Subversion Repositories slepc-dev

Rev

Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1714 jroman 1
#
2
#  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
#  SLEPc - Scalable Library for Eigenvalue Problem Computations
4
#  Copyright (c) 2002-2009, Universidad Politecnica de Valencia, Spain
5
#
6
#  This file is part of SLEPc.
7
#    
8
#  SLEPc is free software: you can redistribute it and/or modify it under  the
9
#  terms of version 3 of the GNU Lesser General Public License as published by
10
#  the Free Software Foundation.
11
#
12
#  SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
13
#  WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
14
#  FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
15
#  more details.
16
#
17
#  You  should have received a copy of the GNU Lesser General  Public  License
18
#  along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19
#  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20
#
21
 
22
import os
23
import sys
24
import log
25
import petscconf
26
import urllib
27
import urlparse
28
import tarfile
29
 
30
def Install():
31
  '''
32
  Download and uncompress the slepc4py tarball
33
  '''
34
  log.Write('='*80)
35
  log.Println('Installing slepc4py...')
36
 
37
  # Test whether PETSc was installed with petsc4py
38
  petscdir = os.environ['PETSC_DIR']
39
  petscconf.Load(petscdir)
40
  archdir = os.sep.join([petscdir,petscconf.ARCH])
41
  if petscconf.ISINSTALL:
42
    petsc4pydir = os.sep.join([petscdir,'lib/petsc4py'])
43
  else:
44
    petsc4pydir = os.sep.join([archdir,'lib/petsc4py'])
45
  if not os.path.exists(petsc4pydir):
46
    sys.exit('ERROR: current PETSc configuration does not include petsc4py support' + petsc4pydir)
47
 
48
  # Create externalpackages directory
49
  externdir = 'externalpackages'
50
  if not os.path.exists(externdir):
51
    try:
52
      os.mkdir(externdir)
53
    except:
54
      sys.exit('ERROR: cannot create directory ' + externdir)
55
 
56
  # Download tarball
57
  packagename = 'slepc4py-1.0.0'
58
  url = 'http://slepc4py.googlecode.com/files/'+packagename+'.tar.gz'
59
  archiveZip = 'slepc4py.tgz'
60
  localFile = os.sep.join([externdir,archiveZip])
61
  log.Println('Downloading '+url+' to '+localFile)
62
 
63
  if os.path.exists(localFile):
64
    os.remove(localFile)
65
  try:
66
    urllib.urlretrieve(url, localFile)
67
  except Exception, e:
68
    name = 'slepc4py'
69
    filename   = os.path.basename(urlparse.urlparse(url)[2])
70
    failureMessage = '''\
71
Unable to download package %s from: %s
72
* If your network is disconnected - please reconnect and rerun config/configure.py
73
* Alternatively, you can download the above URL manually, to /yourselectedlocation/%s
74
  and use the configure option:
75
  --download-%s=/yourselectedlocation/%s
76
''' % (name, url, filename, name, filename)
77
    raise RuntimeError(failureMessage)
78
 
79
  # Uncompress tarball
80
  destDir = os.sep.join([externdir,packagename])
81
  log.Println('Uncompressing '+localFile+' to directory '+destDir)
82
  if os.path.exists(destDir):
83
    for root, dirs, files in os.walk(destDir, topdown=False):
84
      for name in files:
85
        os.remove(os.path.join(root, name))
86
      for name in dirs:
87
        os.rmdir(os.path.join(root, name))
88
  try:
89
    tar = tarfile.open(localFile, "r:gz")
90
    tar.extractall(path=externdir)
91
    tar.close()
92
  except RuntimeError, e:
93
    raise RuntimeError('Error uncompressing '+archiveZip+': '+str(e))
94
 
95
  os.remove(localFile)
96
 
97
 
1717 jroman 98
def addMakeRule(slepcrules,installdir,prefixinstall,getslepc4py):
1714 jroman 99
  '''
100
  Add a rule to the makefile in order to build slepc4py
101
  '''
102
  if getslepc4py:
1717 jroman 103
    target = 'slepc4py'
104
    slepcrules.write(target+':\n')
1714 jroman 105
    externdir = 'externalpackages'
106
    packagename = 'slepc4py-1.0.0'
107
    destDir = os.sep.join([externdir,packagename])
108
    cmd = '@cd '+destDir
109
    slepcrules.write('\t'+cmd+'; \\\n')
110
    cmd = 'python setup.py clean --all'
111
    slepcrules.write('\t'+cmd+'; \\\n')
112
    cmd = 'python setup.py install --install-lib='+os.path.join(installdir,'lib')
113
    slepcrules.write('\t'+cmd+'\n')
114
    cmd = '@echo "====================================="'
115
    slepcrules.write('\t'+cmd+'\n')
116
    cmd = '@echo "To use slepc4py, add '+os.path.join(installdir,'lib')+' to PYTHONPATH"'
117
    slepcrules.write('\t'+cmd+'\n')
118
    cmd = '@echo "====================================="'
119
    slepcrules.write('\t'+cmd+'\n')
1717 jroman 120
  else:
121
    if prefixinstall:
122
      target = 'slepc4py'
123
      slepcrules.write(target+':\n')
124
      cmd = '@echo " "'
125
      slepcrules.write('\t'+cmd+'\n')
1714 jroman 126
 
1717 jroman 127
  target = 'slepc4py_noinstall'
128
  if getslepc4py and not prefixinstall:
129
    slepcrules.write(target+': slepc4py\n')
130
  else:
131
    slepcrules.write(target+':\n')