1#!/usr/bin/env python 2import os 3import sys 4import commands 5 6 7if not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2: 8 print '********* You must have Python version 2.2 or higher to run configure ***********' 9 print '* Python is easy to install for end users or sys-admin. We urge you to upgrade *' 10 print '* http://www.python.org/download/ *' 11 print '* *' 12 print '* You can configure PETSc manually BUT please, please consider upgrading python *' 13 print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual *' 14 print '*********************************************************************************' 15 sys.exit(4) 16 17def getarch(): 18 if os.path.basename(sys.argv[0]).startswith('configure'): return '' 19 else: return os.path.basename(sys.argv[0])[:-3] 20 21def petsc_configure(configure_options): 22 # use the name of the config/configure_arch.py to determine the arch 23 if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 24 25 # Should be run from the toplevel 26 pythonDir = os.path.abspath(os.path.join('python')) 27 bsDir = os.path.join(pythonDir, 'BuildSystem') 28 if not os.path.isdir(pythonDir): 29 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 30 if not os.path.isdir(bsDir): 31 print '''Could not locate BuildSystem in $PETSC_DIR/python. 32 Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 33 (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 34 if status: 35 if output.find('ommand not found') >= 0: 36 print '''******** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path\nor manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where you do have bk installed and can clone BuildSystem.******** ''' 37 elif output.find('Cannot resolve host') >= 0: 38 print '''******** Unable to download BuildSystem. You must be off the network. Connect to the internet and run config/configure.py again******** ''' 39 else: 40 print '''******** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov******** ''' 41 print output 42 sys.exit(3) 43 44 sys.path.insert(0, bsDir) 45 sys.path.insert(0, pythonDir) 46 import config.framework 47 48 49 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 50 try: 51 framework.configure(out = sys.stdout) 52 framework.storeSubstitutions(framework.argDB) 53 return 0 54 except RuntimeError, e: 55 msg = '******* Unable to configure with given options ******* (see configure.log for full details):\n'+str(e)+'\n******************************************************\n' 56 se = '' 57 except TypeError, e: 58 msg = '******* Error in command line argument to configure.py ***********\n'+str(e)+'\n******************************************************\n' 59 se = '' 60 except SystemExit, e: 61 if e.code is None or e.code == 0: 62 return 63 msg = '******* CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 64 se = str(e) 65 except Exception, e: 66 msg = '******* CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 67 se = str(e) 68 69 print msg 70 if hasattr(framework, 'log'): 71 import traceback 72 framework.log.write(msg+se) 73 traceback.print_tb(sys.exc_info()[2], file = framework.log) 74 sys.exit(1) 75 76if __name__ == '__main__': 77 petsc_configure([]) 78 79