1#!/usr/bin/env python 2import os, sys 3 4configDir = os.path.abspath('config') 5sys.path.insert(0, configDir) 6bsDir = os.path.abspath(os.path.join(configDir, 'BuildSystem')) 7sys.path.insert(0, bsDir) 8 9import script 10 11class Installer(script.Script): 12 def __init__(self, clArgs = None): 13 import RDict 14 script.Script.__init__(self, clArgs, RDict.RDict()) 15 return 16 17 def setupHelp(self, help): 18 import nargs 19 20 script.Script.setupHelp(self, help) 21 help.addArgument('Installer', '-rootDir=<path>', nargs.Arg(None, None, 'Install Root Directory')) 22 help.addArgument('Installer', '-installDir=<path>', nargs.Arg(None, None, 'Install Target Directory')) 23 help.addArgument('Installer', '-arch=<type>', nargs.Arg(None, None, 'Architecture type')) 24 help.addArgument('Installer', '-ranlib=<prog>', nargs.Arg(None, 'ranlib', 'Ranlib program')) 25 help.addArgument('Installer', '-make=<prog>', nargs.Arg(None, 'make', 'Make program')) 26 help.addArgument('Installer', '-libSuffix=<ext>', nargs.Arg(None, 'make', 'The static library suffix')) 27 return 28 29 def setupDirectories(self): 30 self.rootDir = os.path.abspath(self.argDB['rootDir']) 31 self.installDir = os.path.abspath(self.argDB['installDir']) 32 self.arch = os.path.abspath(self.argDB['arch']) 33 self.ranlib = os.path.abspath(self.argDB['ranlib']) 34 self.make = os.path.abspath(self.argDB['make']) 35 self.libSuffix = os.path.abspath(self.argDB['libSuffix']) 36 return 37 38 def run(self): 39 import re, shutil 40 41 self.setup() 42 self.setupDirectories() 43 if self.installDir == self.rootDir: 44 print 'Install directory is current directory; nothing needs to be done' 45 else: 46 print 'Installing PETSc at',self.installDir 47 if not os.path.isdir(self.installDir): 48 os.makedirs(self.installDir) 49 rootIncludeDir = os.path.join(self.rootDir, 'include') 50 archIncludeDir = os.path.join(self.rootDir, self.arch, 'include') 51 rootConfDir = os.path.join(self.rootDir, 'conf') 52 archConfDir = os.path.join(self.rootDir, self.arch, 'conf') 53 rootBinDir = os.path.join(self.rootDir, 'bin') 54 archBinDir = os.path.join(self.rootDir, self.arch, 'bin') 55 archLibDir = os.path.join(self.rootDir, self.arch, 'lib') 56 installIncludeDir = os.path.join(self.installDir, 'include') 57 installConfDir = os.path.join(self.installDir, 'conf') 58 installLibDir = os.path.join(self.installDir, 'lib') 59 installBinDir = os.path.join(self.installDir, 'bin') 60 if os.path.exists(installIncludeDir): 61 shutil.rmtree(installIncludeDir) 62 shutil.copytree(rootIncludeDir, installIncludeDir) 63 for f in os.listdir(archIncludeDir): 64 shutil.copy(os.path.join(archIncludeDir, f), os.path.join(installIncludeDir, f)) 65 if os.path.exists(installConfDir): 66 shutil.rmtree(installConfDir) 67 shutil.copytree(rootConfDir, installConfDir) 68 for f in os.listdir(archConfDir): 69 shutil.copy(os.path.join(archConfDir, f), os.path.join(installConfDir, f)) 70 for f in os.listdir(installConfDir): 71 oldFile = open(os.path.join(installConfDir, f)) 72 lines = [] 73 for line in oldFile.readlines(): 74 lines.append(re.sub(self.rootDir, self.installDir, re.sub(os.path.join(self.rootDir, self.arch), self.installDir, line))) 75 oldFile.close() 76 oldFile = open(os.path.join(installConfDir, f), 'w') 77 oldFile.write(''.join(lines)) 78 oldFile.close() 79 if os.path.exists(installBinDir): 80 shutil.rmtree(installBinDir) 81 shutil.copytree(rootBinDir, installBinDir) 82 for f in os.listdir(archBinDir): 83 shutil.copy(os.path.join(archBinDir, f), os.path.join(installBinDir, f)) 84 if os.path.exists(installLibDir): 85 shutil.rmtree(installLibDir) 86 shutil.copytree(archLibDir, installLibDir) 87 for f in os.listdir(installLibDir): 88 if os.path.splitext(f)[1] == '.'+self.libSuffix: 89 self.executeShellCommand(self.ranlib+' '+os.path.join(installLibDir, f)) 90 self.executeShellCommand(self.make+' PETSC_ARCH=""'+' PETSC_DIR='+self.installDir+' shared') 91 print ''' 92If using sh/bash, do the following: 93 PETSC_DIR=%s; export PETSC_DIR 94 unset PETSC_ARCH 95If using csh/tcsh, do the following: 96 setenv PETSC_DIR %s 97 unsetenv PETSC_ARCH 98Now run the testsuite to verify the install with the following: 99 make test 100''' % (self.installDir, self.installDir) 101 return 102 103if __name__ == '__main__': 104 Installer(sys.argv[1:]).run() 105