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 rhl9(): 22 try: 23 file = open('/etc/redhat-release','r') 24 except: 25 return 0 26 try: 27 buf = file.read() 28 file.close() 29 except: 30 # can't read file - assume dangerous RHL9 31 return 1 32 if buf.find('Shrike') > -1: 33 return 1 34 else: 35 return 0 36 37def petsc_configure(configure_options): 38 # use the name of the config/configure_arch.py to determine the arch 39 if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 40 41 # Disable threads on RHL9 42 if rhl9(): 43 sys.argv.append('--useThreads=0') 44 print ' *** RHL9 detected. Disabling threads in configure *****' 45 46 # Should be run from the toplevel 47 pythonDir = os.path.abspath(os.path.join('python')) 48 bsDir = os.path.join(pythonDir, 'BuildSystem') 49 if not os.path.isdir(pythonDir): 50 raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 51 if not os.path.isdir(bsDir): 52 print '''++ Could not locate BuildSystem in $PETSC_DIR/python.''' 53 print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 54 (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 55 if status: 56 if output.find('ommand not found') >= 0: 57 print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 58 print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 59 print '''** you do have bk installed and can clone BuildSystem. ''' 60 elif output.find('Cannot resolve host') >= 0: 61 print '''** Unable to download BuildSystem. You must be off the network.''' 62 print '''** Connect to the internet and run config/configure.py again.''' 63 else: 64 print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 65 print output 66 sys.exit(3) 67 68 sys.path.insert(0, bsDir) 69 sys.path.insert(0, pythonDir) 70 import config.framework 71 import cPickle 72 73 framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0) 74 try: 75 framework.configure(out = sys.stdout) 76 framework.storeSubstitutions(framework.argDB) 77 framework.argDB['configureCache'] = cPickle.dumps(framework) 78 return 0 79 except RuntimeError, e: 80 msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \ 81 +str(e)+'\n******************************************************\n' 82 se = '' 83 except TypeError, e: 84 msg = '***** Error in command line argument to configure.py *****\n' \ 85 +str(e)+'\n******************************************************\n' 86 se = '' 87 except ImportError, e: 88 msg = '******* Unable to find module for configure.py *******\n' \ 89 +str(e)+'\n******************************************************\n' 90 se = '' 91 except SystemExit, e: 92 if e.code is None or e.code == 0: 93 return 94 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 95 se = str(e) 96 except Exception, e: 97 msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 98 se = str(e) 99 100 print msg 101 if hasattr(framework, 'log'): 102 import traceback 103 framework.log.write(msg+se) 104 traceback.print_tb(sys.exc_info()[2], file = framework.log) 105 sys.exit(1) 106 107if __name__ == '__main__': 108 petsc_configure([]) 109 110