19d310bb7SBarry Smith#!/usr/bin/env python 29d310bb7SBarry Smithfrom __future__ import generators 39d310bb7SBarry Smithimport config.base 49d310bb7SBarry Smithimport os 59d310bb7SBarry Smith 69d310bb7SBarry Smithclass Configure(config.base.Configure): 79d310bb7SBarry Smith def __init__(self, framework): 89d310bb7SBarry Smith config.base.Configure.__init__(self, framework) 99d310bb7SBarry Smith self.headerPrefix = '' 109d310bb7SBarry Smith self.substPrefix = '' 11*4d9e5d0eSSatish Balay self.isprefix = False 125188cb68SSatish Balay self.dir = '' 139d310bb7SBarry Smith return 149d310bb7SBarry Smith 15*4d9e5d0eSSatish Balay def __str1__(self): 16*4d9e5d0eSSatish Balay if self.isprefix: 17*4d9e5d0eSSatish Balay return ' Prefix: ' + self.dir + '\n' 18*4d9e5d0eSSatish Balay else: 19*4d9e5d0eSSatish Balay return ' Prefix: <inplace installation>\n' 209d310bb7SBarry Smith 219d310bb7SBarry Smith def setupHelp(self, help): 229d310bb7SBarry Smith import nargs 239d310bb7SBarry Smith help.addArgument('PETSc', '-with-clean=<bool>', nargs.ArgBool(None, 0, 'Delete prior build files including externalpackages')) 249d310bb7SBarry Smith return 259d310bb7SBarry Smith 269d310bb7SBarry Smith def setupDependencies(self, framework): 279d310bb7SBarry Smith config.base.Configure.setupDependencies(self, framework) 285bb5b263SMatthew G. Knepley self.petscdir = framework.require('PETSc.options.petscdir', self) 299d310bb7SBarry Smith self.arch = framework.require('PETSc.options.arch', self) 309d310bb7SBarry Smith return 319d310bb7SBarry Smith 329d310bb7SBarry Smith def printSudoPasswordMessage(self,needsudo = 1): 339d310bb7SBarry Smith '''Prints a message that sudo password will be needed for installs of packages''' 349d310bb7SBarry Smith '''Packages like sowing and make that are never installed in an sudo location would pass 0 for needsudo''' 359d310bb7SBarry Smith if needsudo and self.installSudoMessage: 369d310bb7SBarry Smith self.logPrintBox(self.installSudoMessage) 379d310bb7SBarry Smith self.installSudoMessage = '' 389d310bb7SBarry Smith 399d310bb7SBarry Smith def setInstallDir(self): 409d310bb7SBarry Smith ''' setup installDir to either prefix or if that is not set to PETSC_DIR/PETSC_ARCH''' 419d310bb7SBarry Smith self.installSudo = '' 429d310bb7SBarry Smith self.installSudoMessage = '' 439d310bb7SBarry Smith if self.framework.argDB['prefix']: 44*4d9e5d0eSSatish Balay self.isprefix = True 454a08bad0SBarry Smith self.dir = os.path.abspath(os.path.expanduser(self.framework.argDB['prefix'])) 465188cb68SSatish Balay self.petscDir = self.dir 475188cb68SSatish Balay self.petscArch = '' 489d310bb7SBarry Smith try: 499d310bb7SBarry Smith os.makedirs(os.path.join(self.dir,'PETScTestDirectory')) 509d310bb7SBarry Smith os.rmdir(os.path.join(self.dir,'PETScTestDirectory')) 51be5c6b33SBarry Smith except Exception as e: 52be5c6b33SBarry Smith self.logPrint('Error trying to to test write permissions on directory '+str(e)) 539d310bb7SBarry Smith self.installSudoMessage = 'You do not have write permissions to the --prefix directory '+self.dir+'\nYou will be prompted for the sudo password for any external package installs' 549d310bb7SBarry Smith self.installSudo = 'sudo ' 559d310bb7SBarry Smith else: 565bb5b263SMatthew G. Knepley self.dir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 575188cb68SSatish Balay self.petscDir = self.petscdir.dir 585188cb68SSatish Balay self.petscArch = self.arch.arch 598ca03633SSatish Balay self.addMakeMacro('PREFIXDIR',self.dir) 605bb5b263SMatthew G. Knepley self.confDir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 619d310bb7SBarry Smith 629d310bb7SBarry Smith def configureInstallDir(self): 639d310bb7SBarry Smith '''Makes installDir subdirectories if it does not exist for both prefix install location and PETSc work install location''' 645bb5b263SMatthew G. Knepley dir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 659d310bb7SBarry Smith if not os.path.exists(dir): 669d310bb7SBarry Smith os.makedirs(dir) 67af0996ceSBarry Smith for i in ['include','lib','bin',os.path.join('lib','petsc','conf')]: 689d310bb7SBarry Smith newdir = os.path.join(dir,i) 699d310bb7SBarry Smith if not os.path.exists(newdir): 709d310bb7SBarry Smith os.makedirs(newdir) 719d310bb7SBarry Smith if os.path.isfile(self.framework.argDB.saveFilename): 729d310bb7SBarry Smith os.remove(self.framework.argDB.saveFilename) 73af0996ceSBarry Smith confdir = os.path.join(dir,'lib','petsc','conf') 749d310bb7SBarry Smith self.framework.argDB.saveFilename = os.path.abspath(os.path.join(confdir, 'RDict.db')) 757ad10985SMatthew G. Knepley self.logPrint('Changed persistence directory to '+confdir) 769d310bb7SBarry Smith return 779d310bb7SBarry Smith 785004c6edSSatish Balay def cleanConfDir(self): 799d310bb7SBarry Smith import shutil 805004c6edSSatish Balay if self.framework.argDB['with-clean'] and os.path.isdir(self.confDir): 815004c6edSSatish Balay self.logPrintBox('Warning: "with-clean" is specified. Removing all build files from '+ self.confDir) 825004c6edSSatish Balay shutil.rmtree(self.confDir) 839d310bb7SBarry Smith return 849d310bb7SBarry Smith 859d310bb7SBarry Smith def saveReconfigure(self): 86af0996ceSBarry Smith self.reconfigure_file = os.path.join(self.dir,'lib','petsc','conf','reconfigure-'+self.arch.arch+'.py') 879d310bb7SBarry Smith self.save_reconfigure_file = None 889d310bb7SBarry Smith if self.framework.argDB['with-clean'] and os.path.exists(self.reconfigure_file): 899d310bb7SBarry Smith self.save_reconfigure_file = '.save.reconfigure-'+self.arch.arch+'.py' 909d310bb7SBarry Smith try: 919d310bb7SBarry Smith if os.path.exists(self.save_reconfigure_file): os.unlink(self.save_reconfigure_file) 929d310bb7SBarry Smith os.rename(self.reconfigure_file,self.save_reconfigure_file) 935b6bfdb9SJed Brown except Exception as e: 949d310bb7SBarry Smith self.save_reconfigure_file = None 957ad10985SMatthew G. Knepley self.logPrint('error in saveReconfigure(): '+ str(e)) 969d310bb7SBarry Smith return 979d310bb7SBarry Smith 989d310bb7SBarry Smith def restoreReconfigure(self): 999d310bb7SBarry Smith if self.framework.argDB['with-clean'] and self.save_reconfigure_file: 1009d310bb7SBarry Smith try: 1019d310bb7SBarry Smith os.rename(self.save_reconfigure_file,self.reconfigure_file) 1025b6bfdb9SJed Brown except Exception as e: 1037ad10985SMatthew G. Knepley self.logPrint('error in restoreReconfigure(): '+ str(e)) 1049d310bb7SBarry Smith return 1059d310bb7SBarry Smith 1069d310bb7SBarry Smith def configure(self): 1079d310bb7SBarry Smith self.executeTest(self.setInstallDir) 1089d310bb7SBarry Smith self.executeTest(self.saveReconfigure) 1095004c6edSSatish Balay self.executeTest(self.cleanConfDir) 1109d310bb7SBarry Smith self.executeTest(self.configureInstallDir) 1119d310bb7SBarry Smith self.executeTest(self.restoreReconfigure) 1129d310bb7SBarry Smith return 113