now environment vars are processed in known order. gracefully put own extensions to end of existing (e.g. PATH=$PATH:ourStuff)

This commit is contained in:
Philip Eisenlohr 2011-11-09 17:20:20 +00:00
parent 314caffc08
commit eebb59d146
1 changed files with 38 additions and 27 deletions

View File

@ -14,25 +14,34 @@ validShells = {\
'csh': ['.cshrc'], 'csh': ['.cshrc'],
} }
environment = {\ environment = [\
'LD_LIBRARY_PATH': {'delete':'"acml"', # what keywords trigger item deletion from existing path { 'name': 'DAMASK_ROOT',
'substitute':'[os.path.join(pathInfo["acml"],"ifort64_mp/lib"),\ 'delete':'DamaskRoot',
os.path.join(pathInfo["acml"],"ifort64/lib")]', # what to substitute for deleted path items 'substitute':'[DamaskRoot]',
'append': True, # whether new entries append to existing ${env} 'append': False,
}, },
'PYTHONPATH': {'delete':'os.path.join(DamaskRoot,"lib")', { 'name': 'DAMASK_BIN',
'substitute':'[os.path.join(DamaskRoot,"lib")]', 'delete':'os.path.join(DamaskRoot,"bin")',
'append': True, 'substitute':'[os.path.join(DamaskRoot,"bin")]',
}, 'append': False,
'DAMASK_ROOT': {'delete':'DamaskRoot', },
'substitute':'[DamaskRoot]', { 'name': 'PATH',
'append': False, 'delete':'"${DAMASK_BIN}"',
}, 'substitute':'["${DAMASK_BIN}"]',
'PATH': {'delete':'os.path.join(DamaskRoot,"bin")', 'append': True,
'substitute':'[os.path.join(DamaskRoot,"bin")]', },
'append': True, { 'name': 'PYTHONPATH',
}, 'delete':'"${DAMASK_ROOT}/lib"',
} 'substitute':'["${DAMASK_ROOT}/lib"]',
'append': True,
},
{ 'name': '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}
},
]
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')
@ -69,21 +78,23 @@ if theShell == 'bash':
rc.close() rc.close()
output = [] output = []
for envVar in environment.keys(): environment[envVar]['matched'] = False for var in environment: var['matched'] = False
for line in content: for line in content:
for envVar,data in environment.items(): for var in environment:
m = re.search(r'^(.*? %s=)([^;]*)(.*)$'%envVar,line) m = re.search(r'^(.*? %s=)([^;]*)(.*)$'%var['name'],line)
if m: if m:
substitute = eval(data['substitute'])+[path for path in m.group(2).split(':') if eval(data['delete']) not in path] substitute = [path for path in m.group(2).split(':') if eval(var['delete']) not in path] + \
eval(var['substitute'])
line = m.group(1)+':'.join(substitute)+m.group(3) line = m.group(1)+':'.join(substitute)+m.group(3)
environment[envVar]['matched'] = True var['matched'] = True
output.append(line) output.append(line)
for envVar,data in environment.items(): for var in environment:
if not data['matched']: if not var['matched']:
output.append('export %s=%s'%(envVar,':'.join(eval(data['substitute'])+{True:['${%s}'%envVar],False:[]}[data['append']]))) output.append('export %s=%s'%(var['name'],':'.join({True:['${%s}'%var['name']],False:[]}[var['append']]+\
eval(var['substitute']))))
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')