1from __future__ import generators 2import config.base 3import os 4 5class Configure(config.base.Configure): 6 def __init__(self, framework): 7 config.base.Configure.__init__(self, framework) 8 self.headerPrefix = '' 9 self.substPrefix = '' 10 self.isprefix = False 11 self.dir = '' 12 return 13 14 def __str1__(self): 15 if self.isprefix: 16 return ' Prefix: ' + self.dir + '\n' 17 else: 18 return ' Prefix: <inplace installation>\n' 19 20 def setupHelp(self, help): 21 import nargs 22 help.addArgument('PETSc', '-with-clean=<bool>', nargs.ArgBool(None, 0, 'Delete prior build files including externalpackages')) 23 return 24 25 def setupDependencies(self, framework): 26 config.base.Configure.setupDependencies(self, framework) 27 self.petscdir = framework.require('PETSc.options.petscdir', self) 28 self.arch = framework.require('PETSc.options.arch', self) 29 return 30 31 def setInstallDir(self): 32 '''Set installDir to either prefix or if that is not set to PETSC_DIR/PETSC_ARCH''' 33 self.installSudo = '' 34 if self.framework.argDB['prefix']: 35 self.isprefix = True 36 self.dir = os.path.abspath(os.path.expanduser(self.framework.argDB['prefix'])) 37 self.petscDir = self.dir 38 self.petscArch = '' 39 try: 40 os.makedirs(os.path.join(self.dir,'PETScTestDirectory')) 41 os.rmdir(os.path.join(self.dir,'PETScTestDirectory')) 42 except Exception as e: 43 self.logPrint('Error trying to test write permissions on directory '+str(e)) 44 self.installSudo = 'sudo ' 45 else: 46 self.dir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 47 self.petscDir = self.petscdir.dir 48 self.petscArch = self.arch.arch 49 self.addMakeMacro('PREFIXDIR',self.dir) 50 self.confDir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 51 52 def configureInstallDir(self): 53 '''Makes installDir subdirectories if it does not exist for both prefix install location and PETSc work install location''' 54 dir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 55 if not os.path.exists(dir): 56 os.makedirs(dir) 57 for i in ['include','lib','bin',os.path.join('lib','petsc','conf')]: 58 newdir = os.path.join(dir,i) 59 if not os.path.exists(newdir): 60 os.makedirs(newdir) 61 if os.path.isfile(self.framework.argDB.saveFilename): 62 os.remove(self.framework.argDB.saveFilename) 63 confdir = os.path.join(dir,'lib','petsc','conf') 64 self.framework.argDB.saveFilename = os.path.abspath(os.path.join(confdir, 'RDict.db')) 65 self.logPrint('Changed persistence directory to '+confdir) 66 return 67 68 def cleanConfDir(self): 69 '''Remove all the files from configuration directory for this PETSC_ARCH, from --with-clean option''' 70 import shutil 71 if self.framework.argDB['with-clean'] and os.path.isdir(self.confDir): 72 self.logPrintWarning('"with-clean" is specified. Removing all build files from '+ self.confDir) 73 shutil.rmtree(self.confDir) 74 return 75 76 def saveReconfigure(self): 77 '''Save the configure options in a script in PETSC_ARCH/lib/petsc/conf so the same configure may be easily re-run''' 78 self.reconfigure_file = os.path.join(self.dir,'lib','petsc','conf','reconfigure-'+self.arch.arch+'.py') 79 self.save_reconfigure_file = None 80 if self.framework.argDB['with-clean'] and os.path.exists(self.reconfigure_file): 81 self.save_reconfigure_file = '.save.reconfigure-'+self.arch.arch+'.py' 82 try: 83 if os.path.exists(self.save_reconfigure_file): os.unlink(self.save_reconfigure_file) 84 os.rename(self.reconfigure_file,self.save_reconfigure_file) 85 except Exception as e: 86 self.save_reconfigure_file = None 87 self.logPrint('error in saveReconfigure(): '+ str(e)) 88 return 89 90 def restoreReconfigure(self): 91 '''If --with-clean was requested but restoring the reconfigure file was requested then restore it''' 92 if self.framework.argDB['with-clean'] and self.save_reconfigure_file: 93 try: 94 os.rename(self.save_reconfigure_file,self.reconfigure_file) 95 except Exception as e: 96 self.logPrint('error in restoreReconfigure(): '+ str(e)) 97 return 98 99 def configure(self): 100 self.executeTest(self.setInstallDir) 101 self.executeTest(self.saveReconfigure) 102 self.executeTest(self.cleanConfDir) 103 self.executeTest(self.configureInstallDir) 104 self.executeTest(self.restoreReconfigure) 105 return 106