15d5a5a7bSMatthew Knepley#!/usr/bin/env python 25d5a5a7bSMatthew Knepleyimport os 35d5a5a7bSMatthew Knepleyimport sys 44f8a5b45SBarry Smithimport commands 55d5a5a7bSMatthew Knepley 64b8aa89bSBarry Smith 7b26a8723SBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2: 832077d6dSBarry Smith print '********* You must have Python version 2.2 or higher to run configure ***********' 932077d6dSBarry Smith print '* Python is easy to install for end users or sys-admin. We urge you to upgrade *' 1032077d6dSBarry Smith print '* http://www.python.org/download/ *' 1132077d6dSBarry Smith print '* *' 1232077d6dSBarry Smith print '* You can configure PETSc manually BUT please, please consider upgrading python *' 1332077d6dSBarry Smith print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual *' 1432077d6dSBarry Smith print '*********************************************************************************' 15b26a8723SBarry Smith sys.exit(4) 162fb34ac0SMatthew Knepley 17f6614063SBarry Smithclass RestartException: 18f6614063SBarry Smith def __init__(self,args): 19f6614063SBarry Smith self.args = args 20f6614063SBarry Smith return 21f6614063SBarry Smith 224b8aa89bSBarry Smithdef getarch(): 2364382af2SBarry Smith if os.path.basename(sys.argv[0]).startswith('configure'): return '' 24b88bae4cSBarry Smith else: return os.path.basename(sys.argv[0])[:-3] 254b8aa89bSBarry Smith 265d5a5a7bSMatthew Knepleydef petsc_configure(configure_options): 275fb2c094SBarry Smith # use the name of the config/configure_arch.py to determine the arch 285fb2c094SBarry Smith if getarch(): configure_options.append('-PETSC_ARCH='+getarch()) 295fb2c094SBarry Smith 3087282423SMatthew Knepley # Should be run from the toplevel 315d5a5a7bSMatthew Knepley pythonDir = os.path.abspath(os.path.join('python')) 3287282423SMatthew Knepley bsDir = os.path.join(pythonDir, 'BuildSystem') 3387282423SMatthew Knepley if not os.path.isdir(pythonDir): 345d5a5a7bSMatthew Knepley raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.')) 3587282423SMatthew Knepley if not os.path.isdir(bsDir): 36d688700cSSatish Balay print '''++ Could not locate BuildSystem in $PETSC_DIR/python.''' 37d688700cSSatish Balay print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"''' 384f8a5b45SBarry Smith (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem') 397d7624c9SBarry Smith if status: 407d7624c9SBarry Smith if output.find('ommand not found') >= 0: 41d688700cSSatish Balay print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path''' 42d688700cSSatish Balay print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where''' 43d688700cSSatish Balay print '''** you do have bk installed and can clone BuildSystem. ''' 447d7624c9SBarry Smith elif output.find('Cannot resolve host') >= 0: 45d688700cSSatish Balay print '''** Unable to download BuildSystem. You must be off the network.''' 46d688700cSSatish Balay print '''** Connect to the internet and run config/configure.py again.''' 477d7624c9SBarry Smith else: 48d688700cSSatish Balay print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov''' 497d7624c9SBarry Smith print output 5087282423SMatthew Knepley sys.exit(3) 514f8a5b45SBarry Smith 5287282423SMatthew Knepley sys.path.insert(0, bsDir) 535d5a5a7bSMatthew Knepley sys.path.insert(0, pythonDir) 545d5a5a7bSMatthew Knepley import config.framework 55f56be888SMatthew Knepley import cPickle 564f8a5b45SBarry Smith 57f6614063SBarry Smith framework = [] 5870ae1cd5SMatthew Knepley try: 59f6614063SBarry Smith framework = while_petsc_configure(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options) 60358ebc22SMatthew Knepley framework.storeSubstitutions(framework.argDB) 61f56be888SMatthew Knepley framework.argDB['configureCache'] = cPickle.dumps(framework) 62dd50d019SBarry Smith return 0 63e9f3bb17SBarry Smith except RuntimeError, e: 6466b9a547SSatish Balay msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \ 65d688700cSSatish Balay +str(e)+'\n******************************************************\n' 66e9f3bb17SBarry Smith se = '' 671a02243aSBarry Smith except TypeError, e: 6866b9a547SSatish Balay msg = '***** Error in command line argument to configure.py *****\n' \ 69d688700cSSatish Balay +str(e)+'\n******************************************************\n' 701a02243aSBarry Smith se = '' 71*96dc2fe8SMatthew Knepley except ImportError, e: 72*96dc2fe8SMatthew Knepley msg = '******* Unable to find module for configure.py *******\n' \ 73*96dc2fe8SMatthew Knepley +str(e)+'\n******************************************************\n' 74*96dc2fe8SMatthew Knepley se = '' 75d7d3c4beSMatthew Knepley except SystemExit, e: 76d7d3c4beSMatthew Knepley if e.code is None or e.code == 0: 77d7d3c4beSMatthew Knepley return 78d688700cSSatish Balay msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 79d7d3c4beSMatthew Knepley se = str(e) 80e9f3bb17SBarry Smith except Exception, e: 81d688700cSSatish Balay msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n' 82e9f3bb17SBarry Smith se = str(e) 83e9f3bb17SBarry Smith 84e9f3bb17SBarry Smith print msg 85e9f3bb17SBarry Smith if hasattr(framework, 'log'): 86e9f3bb17SBarry Smith framework.log.write(msg+se) 87f6614063SBarry Smith file = framework.log 88f6614063SBarry Smith else: 89f6614063SBarry Smith print se 90f6614063SBarry Smith file = sys.stdout 91f6614063SBarry Smith import traceback 92f6614063SBarry Smith traceback.print_tb(sys.exc_info()[2], file = file) 93e9f3bb17SBarry Smith sys.exit(1) 945d5a5a7bSMatthew Knepley 95f6614063SBarry Smith 96f6614063SBarry Smithdef while_petsc_configure(args): 97f6614063SBarry Smith import config.framework 98f6614063SBarry Smith while 1: 99f6614063SBarry Smith framework = config.framework.Framework(args, loadArgDB = 0) 100f6614063SBarry Smith try: 101f6614063SBarry Smith framework.configure(out = sys.stdout) 102f6614063SBarry Smith break 103f6614063SBarry Smith except RestartException, e: 104f6614063SBarry Smith # ugly crap; merge additional args 105f6614063SBarry Smith for j in e.args: 106f6614063SBarry Smith found = 0 107f6614063SBarry Smith for i in len(args): 108f6614063SBarry Smith if args[i].startswith(j): 109f6614063SBarry Smith args[i] += ' '+e.args[j] 110f6614063SBarry Smith found = 1 111f6614063SBarry Smith break 112f6614063SBarry Smith if not found: 113f6614063SBarry Smith args.append(j+'='+e.args[j]) 114f6614063SBarry Smith args.append('-logAppend=1') 115f6614063SBarry Smith return framework 116f6614063SBarry Smith 1175d5a5a7bSMatthew Knepleyif __name__ == '__main__': 118a030c540SBarry Smith petsc_configure([]) 119759acf64SBarry Smith 120