made it more flexible to future envVar additions and csh implementation...
This commit is contained in:
parent
860594d9a4
commit
a66c502617
|
@ -3,11 +3,32 @@
|
||||||
import os,sys,string,re
|
import os,sys,string,re
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
validShells = {\
|
pathInfo = {\
|
||||||
'bash':['.bashrc','.bash_profile'],
|
'acml': 'lib/acml4.4.0',
|
||||||
'csh': ['.cshrc']
|
'fftw': 'lib/fftw',
|
||||||
|
'msc': '/msc',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validShells = {\
|
||||||
|
'bash':['.bashrc','.bash_profile'],
|
||||||
|
'csh': ['.cshrc'],
|
||||||
|
}
|
||||||
|
|
||||||
|
environment = {\
|
||||||
|
'LD_LIBRARY_PATH': {'delete':'"acml"', # what keywords trigger item deletion from existing path
|
||||||
|
'substitute':'[os.path.join(pathInfo["acml"],"ifort64_mp/lib"),\
|
||||||
|
os.path.join(pathInfo["acml"],"ifort64/lib")]', # what to substitute for deleted path items
|
||||||
|
'append': True, # whether new entries append to existing ${env}
|
||||||
|
},
|
||||||
|
'PYTHONPATH': {'delete':'os.path.join(DamaskRoot,"lib")',
|
||||||
|
'substitute':'[os.path.join(DamaskRoot,"lib")]',
|
||||||
|
'append': True,
|
||||||
|
},
|
||||||
|
'DAMASK_ROOT': {'delete':'DamaskRoot',
|
||||||
|
'substitute':'[DamaskRoot]',
|
||||||
|
'append': False,
|
||||||
|
},
|
||||||
|
}
|
||||||
parser = OptionParser(usage="%prog [options]", description = """
|
parser = OptionParser(usage="%prog [options]", description = """
|
||||||
Sets up your shell resource to be compatible with DAMASK.
|
Sets up your shell resource to be compatible with DAMASK.
|
||||||
""" + string.replace('$Id$','\n','\\n')
|
""" + string.replace('$Id$','\n','\\n')
|
||||||
|
@ -19,17 +40,18 @@ parser.add_option("-s","--shell", type="string",
|
||||||
|
|
||||||
parser.set_defaults(shell = 'bash')
|
parser.set_defaults(shell = 'bash')
|
||||||
|
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
DamaskRoot = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),'../'))
|
DamaskRoot = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),'../'))
|
||||||
try: # check for MSC.Mentat installation location
|
|
||||||
|
try: # check for user-defined pathinfo
|
||||||
file = open(os.path.join(DamaskRoot,'lib/pathinfo'))
|
file = open(os.path.join(DamaskRoot,'lib/pathinfo'))
|
||||||
for line in file.readlines():
|
content = file.readlines()
|
||||||
if line.split()[0].lower() == 'acml': ACMLpath = os.path.normpath(line.split()[1])
|
|
||||||
file.close()
|
file.close()
|
||||||
|
for line in content:
|
||||||
|
pathinfo[line.split()[0].lower()] = os.path.normpath(line.split()[1])
|
||||||
except:
|
except:
|
||||||
ACMLpath = os.path.join(DamaskRoot,'lib/acml4.4.0/')
|
pass
|
||||||
|
|
||||||
theShell = options.shell.lower()
|
theShell = options.shell.lower()
|
||||||
theHome = os.getenv('USERPROFILE') or os.getenv('HOME')
|
theHome = os.getenv('USERPROFILE') or os.getenv('HOME')
|
||||||
|
@ -42,33 +64,22 @@ if theShell == 'bash':
|
||||||
content = map(string.strip,rc.readlines())
|
content = map(string.strip,rc.readlines())
|
||||||
rc.close()
|
rc.close()
|
||||||
|
|
||||||
matched = {'LD_LIB': False, 'PYTHONPATH': False}
|
|
||||||
output = []
|
output = []
|
||||||
|
for envVar in environment.keys(): environment[envVar]['matched'] = False
|
||||||
|
|
||||||
for line in content:
|
for line in content:
|
||||||
|
for envVar,data in environment.items():
|
||||||
m = re.search('^(.*?LD_LIBRARY_PATH=)([^;]*)(.*)$',line)
|
m = re.search(r'^(.*?%s=)([^;]*)(.*)$'%envVar,line)
|
||||||
if m:
|
if m:
|
||||||
newPath = [os.path.join(ACMLpath,'ifort64_mp/lib'),os.path.join(ACMLpath,'ifort64/lib')]
|
substitute = eval(data['substitute'])+[path for path in m.group(2).split(':') if eval(data['delete']) not in path]
|
||||||
for item in m.group(2).split(':'):
|
line = m.group(1)+':'.join(substitute)+m.group(3)
|
||||||
if 'acml' not in item.lower(): newPath.append(item)
|
environment[envVar]['matched'] = True
|
||||||
line = m.group(1)+':'.join(newPath)+m.group(3)
|
|
||||||
matched['LD_LIB'] = True
|
|
||||||
|
|
||||||
m = re.search('^(.*?PYTHONPATH=)([^;]*)(.*)$',line)
|
|
||||||
if m:
|
|
||||||
newPath = [os.path.join(DamaskRoot,'lib')]
|
|
||||||
for item in m.group(2).split(':'):
|
|
||||||
if os.path.join(DamaskRoot,'lib') != item: newPath.append(item)
|
|
||||||
line = m.group(1)+':'.join(newPath)+m.group(3)
|
|
||||||
matched['PYTHONPATH'] = True
|
|
||||||
|
|
||||||
output.append(line)
|
output.append(line)
|
||||||
|
|
||||||
if not matched['LD_LIB']:
|
for envVar,data in environment.items():
|
||||||
output.append('export LD_LIBRARY_PATH=%s:%s:${LD_LIBRARY_PATH}'%(os.path.join(ACMLpath,'ifort64_mp/lib'),os.path.join(ACMLpath,'ifort64/lib')))
|
if not data['matched']:
|
||||||
if not matched['PYTHONPATH']:
|
output.append('export %s=%s'%(envVar,':'.join(eval(data['substitute'])+{True:['${%s}'%envVar],False:[]}[data['append']])))
|
||||||
output.append('export PYTHONPATH=%s:$PYTHONPATH'%(os.path.join(DamaskRoot,'lib')))
|
|
||||||
|
|
||||||
rc = open(os.path.join(theHome,theRC),'w')
|
rc = open(os.path.join(theHome,theRC),'w')
|
||||||
rc.write('\n'.join(output)+'\n')
|
rc.write('\n'.join(output)+'\n')
|
||||||
|
|
Loading…
Reference in New Issue