19d310bb7SBarry Smithimport config.base 29d310bb7SBarry Smithimport os 39d310bb7SBarry Smithimport re 49d310bb7SBarry Smith 59d310bb7SBarry Smithclass Configure(config.base.Configure): 69d310bb7SBarry Smith def __init__(self, framework): 79d310bb7SBarry Smith config.base.Configure.__init__(self, framework) 89d310bb7SBarry Smith self.headerPrefix = 'PETSC' 99d310bb7SBarry Smith self.substPrefix = 'PETSC' 109d310bb7SBarry Smith self.isPetsc = 1 119d310bb7SBarry Smith return 129d310bb7SBarry Smith 139d310bb7SBarry Smith def __str1__(self): 149d310bb7SBarry Smith if hasattr(self, 'dir'): 159d310bb7SBarry Smith return ' PETSC_DIR: '+str(self.dir)+'\n' 169d310bb7SBarry Smith return '' 179d310bb7SBarry Smith 189d310bb7SBarry Smith def setupHelp(self, help): 199d310bb7SBarry Smith import nargs 209d310bb7SBarry Smith help.addArgument('PETSc', '-PETSC_DIR=<root-dir>', nargs.Arg(None, None, 'The root directory of the PETSc installation')) 219d310bb7SBarry Smith return 229d310bb7SBarry Smith 239d310bb7SBarry Smith def configureDirectories(self): 249d310bb7SBarry Smith '''Checks PETSC_DIR and sets if not set''' 259d310bb7SBarry Smith if 'PETSC_DIR' in self.framework.argDB: 269d310bb7SBarry Smith self.dir = self.framework.argDB['PETSC_DIR'] 279d310bb7SBarry Smith if self.dir == 'pwd': 289d310bb7SBarry Smith raise RuntimeError('You have set -PETSC_DIR=pwd, you need to use back quotes around the pwd\n like -PETSC_DIR=`pwd`') 299d310bb7SBarry Smith if not os.path.isdir(self.dir): 309d310bb7SBarry Smith raise RuntimeError('The value you set with -PETSC_DIR='+self.dir+' is not a directory') 319d310bb7SBarry Smith elif 'PETSC_DIR' in os.environ: 329d310bb7SBarry Smith self.dir = os.environ['PETSC_DIR'] 339d310bb7SBarry Smith if self.dir == 'pwd': 349d310bb7SBarry Smith raise RuntimeError(''' 359d310bb7SBarry SmithThe environmental variable PETSC_DIR is set incorrectly. Please use the following: [notice backquotes] 369d310bb7SBarry Smith For sh/bash : PETSC_DIR=`pwd`; export PETSC_DIR 379d310bb7SBarry Smith for csh/tcsh : setenv PETSC_DIR `pwd`''') 389d310bb7SBarry Smith elif not os.path.isdir(self.dir): 399d310bb7SBarry Smith raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' is not a directory') 409d310bb7SBarry Smith else: 419d310bb7SBarry Smith self.dir = os.getcwd() 429d310bb7SBarry Smith if self.isPetsc and not os.path.realpath(self.dir) == os.path.realpath(os.getcwd()): 439d310bb7SBarry Smith raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' MUST be the current directory '+os.getcwd()) 449d310bb7SBarry Smith self.version = 'Unknown' 459d310bb7SBarry Smith versionHeader = os.path.join(self.dir, 'include', 'petscversion.h') 469d310bb7SBarry Smith versionInfo = [] 479d310bb7SBarry Smith if os.path.exists(versionHeader): 489d310bb7SBarry Smith f = file(versionHeader) 499d310bb7SBarry Smith for line in f: 509d310bb7SBarry Smith if line.find('define PETSC_VERSION') >= 0: 519d310bb7SBarry Smith versionInfo.append(line[:-1]) 529d310bb7SBarry Smith f.close() 539d310bb7SBarry Smith else: 549d310bb7SBarry Smith raise RuntimeError('Invalid PETSc directory '+str(self.dir)+'. Could not locate '+versionHeader) 559d310bb7SBarry Smith self.version = '.'.join([line.split(' ')[-1] for line in versionInfo[1:4]]) 569d310bb7SBarry Smith self.logPrint('Version Information:') 579d310bb7SBarry Smith for line in versionInfo: 589d310bb7SBarry Smith self.logPrint(line) 59*0aa1f76dSSatish Balay self.framework.argDB['with-executables-search-path'].append(os.path.join(self.dir, 'lib','petsc','bin', 'win32fe')) 609d310bb7SBarry Smith 619d310bb7SBarry Smith return 629d310bb7SBarry Smith 639d310bb7SBarry Smith def configure(self): 649d310bb7SBarry Smith self.executeTest(self.configureDirectories) 659d310bb7SBarry Smith return 66