1import config.base 2import os 3import re 4 5class Configure(config.base.Configure): 6 def __init__(self, framework): 7 config.base.Configure.__init__(self, framework) 8 self.headerPrefix = 'PETSC' 9 self.substPrefix = 'PETSC' 10 self.isPetsc = 1 11 return 12 13 def __str1__(self): 14 if hasattr(self, 'dir'): 15 return ' PETSC_DIR: '+str(self.dir)+'\n' 16 return '' 17 18 def setupHelp(self, help): 19 import nargs 20 help.addArgument('PETSc', '-PETSC_DIR=<root-dir>', nargs.Arg(None, None, 'The root directory of the PETSc installation')) 21 return 22 23 def configureDirectories(self): 24 '''Checks PETSC_DIR and sets if not set''' 25 if 'PETSC_DIR' in self.framework.argDB: 26 self.dir = self.framework.argDB['PETSC_DIR'] 27 if self.dir == 'pwd': 28 raise RuntimeError('You have set -PETSC_DIR=pwd, you need to use back quotes around the pwd\n like -PETSC_DIR=`pwd`') 29 if not os.path.isdir(self.dir): 30 raise RuntimeError('The value you set with -PETSC_DIR='+self.dir+' is not a directory') 31 elif 'PETSC_DIR' in os.environ: 32 self.dir = os.environ['PETSC_DIR'] 33 if self.dir == 'pwd': 34 raise RuntimeError(''' 35The environmental variable PETSC_DIR is set incorrectly. Please use the following: [notice backquotes] 36 For sh/bash : PETSC_DIR=`pwd`; export PETSC_DIR 37 for csh/tcsh : setenv PETSC_DIR `pwd`''') 38 elif not os.path.isdir(self.dir): 39 raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' is not a directory') 40 else: 41 self.dir = os.getcwd() 42 if self.isPetsc and not os.path.realpath(self.dir) == os.path.realpath(os.getcwd()): 43 raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' MUST be the current directory '+os.getcwd()) 44 self.version = 'Unknown' 45 versionHeader = os.path.join(self.dir, 'include', 'petscversion.h') 46 versionInfo = [] 47 if os.path.exists(versionHeader): 48 f = file(versionHeader) 49 for line in f: 50 if line.find('define PETSC_VERSION') >= 0: 51 versionInfo.append(line[:-1]) 52 f.close() 53 else: 54 raise RuntimeError('Invalid PETSc directory '+str(self.dir)+'. Could not locate '+versionHeader) 55 self.version = '.'.join([line.split(' ')[-1] for line in versionInfo[1:4]]) 56 self.logPrint('Version Information:') 57 for line in versionInfo: 58 self.logPrint(line) 59 self.addMakeMacro('DIR', self.dir) 60 self.framework.argDB['search-dirs'].append(os.path.join(self.dir, 'bin', 'win32fe')) 61 62 return 63 64 def configure(self): 65 self.executeTest(self.configureDirectories) 66 return 67