#!/usr/bin/env python import os,re,sys,string,subprocess from optparse import OptionParser, Option # ----------------------------- class extendableOption(Option): # ----------------------------- # used for definition of new option parser action 'extend', which enables to take multiple option arguments # taken from online tutorial http://docs.python.org/library/optparse.html ACTIONS = Option.ACTIONS + ("extend",) STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",) TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",) ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",) def take_action(self, action, dest, opt, value, values, parser): if action == "extend": lvalue = value.split(",") values.ensure_value(dest, []).extend(lvalue) else: Option.take_action(self, action, dest, opt, value, values, parser) ######################################################## # MAIN ######################################################## parser = OptionParser(option_class=extendableOption, usage='%prog options', description = """ Sets up the pre and post processing tools of DAMASK """ + string.replace('$Id$','\n','\\n') ) compilers = ['ifort','gfortran'] blastypes = ['LAPACK','ACML','IMKL'] parser.add_option('--with-fc', dest='compiler', type='string', help='F90 compiler [%default]') parser.add_option('--with-marc-dir', dest='marcdir', type='string', help='root directory of MSC.Marc [%default]') parser.add_option('--with-fftw-dir', dest='fftwdir', type='string', help='root directory of FFTW [%default]') parser.add_option('--with-blas-lapack-dir', dest='blasdir', type='string', help='root directory of LAPACK [%default]') parser.add_option('--with-blas-type', dest='blastype', type='string', help='type of BLAS/LAPACK library [%default]') parser.add_option('--with-spectral-options', dest='spectraloptions', type='string', action='extend', help='options for spectral solver %default') compiler = os.getenv('F90') if compiler == None: compiler ={True:'ifort',False:'gfortran'}[\ subprocess.call(['which', 'ifort'],\ stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0] parser.set_defaults(compiler = compiler) parser.set_defaults(blastype = 'LAPACK') parser.set_defaults(fftwdir = '/usr/local') parser.set_defaults(blasdir = '/usr') parser.set_defaults(marcdir = '/msc') parser.set_defaults(spectraloptions = []) (options,filenames) = parser.parse_args() options.blastype = options.blastype.upper() options.compiler = options.compiler.lower() if options.blastype not in blastypes: print('Unknown BLAS type selected') if options.compiler not in compilers: print('Unknown compiler type selected') output = [] with open('installation/options','r') as f: for line in f: items = re.split('[= ]',line) if items[0] == 'F90': line = '%s=%s\n'%(items[0],options.compiler) if items[0] == 'FFTW_ROOT': line = '%s=%s\n'%(items[0],options.fftwdir.rstrip('/')) if items[0] == 'MSC_ROOT': line = '%s=%s\n'%(items[0],options.marcdir.rstrip('/')) for blastype in blastypes: if options.blastype == blastype and items[0] == '%s_ROOT'%blastype: line = '%s=%s\n'%(items[0],options.blasdir.rstrip('/')) for spectralOption in options.spectraloptions: [key,value] = re.split('[= ]',spectralOption)[0:2] if key == items[0]: line = '%s=%s\n'%(items[0],value) options.spectraloptions.remove(spectralOption) output.append(line) for spectralOption in options.spectraloptions: output.append(spectralOption+'\n') with open('installation/options','w') as f: for line in output: f.write(line)