DAMASK_EICMD/python/damask/environment.py

28 lines
935 B
Python
Raw Normal View History

2019-05-30 23:32:55 +05:30
import os
import re
2011-12-14 01:32:26 +05:30
class Environment():
__slots__ = [ \
2014-01-17 07:07:01 +05:30
'options',
2011-12-14 01:32:26 +05:30
]
def __init__(self):
self.options = {}
self.get_options()
2011-12-14 01:32:26 +05:30
def relPath(self,relative = '.'):
return os.path.join(self.rootDir(),relative)
def rootDir(self):
2014-01-24 18:00:27 +05:30
return os.path.normpath(os.path.join(os.path.realpath(__file__),'../../../'))
2014-01-17 02:59:39 +05:30
def get_options(self):
with open(self.relPath(self.rootDir()+'/CONFIG')) as configFile:
for line in configFile:
l = re.sub('^set ', '', line).strip() # remove "set" (tcsh) when setting variables
if l and not l.startswith('#'):
2016-08-01 20:31:13 +05:30
items = re.split(r'\s*=\s*',l)
if len(items) == 2:
self.options[items[0].upper()] = \
re.sub('\$\{*DAMASK_ROOT\}*',self.rootDir(),os.path.expandvars(items[1])) # expand all shell variables and DAMASK_ROOT