2011-12-22 16:00:25 +05:30
|
|
|
# $Id$
|
|
|
|
|
2013-03-05 01:09:13 +05:30
|
|
|
import os,sys,string,re,subprocess,shlex
|
2011-12-14 01:32:26 +05:30
|
|
|
|
|
|
|
class Environment():
|
2011-12-15 14:21:16 +05:30
|
|
|
__slots__ = [ \
|
|
|
|
'rootRelation',
|
|
|
|
'pathInfo',
|
2011-12-14 01:32:26 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self,rootRelation = '.'):
|
2011-12-15 14:21:16 +05:30
|
|
|
self.rootRelation = rootRelation
|
2011-12-20 16:25:47 +05:30
|
|
|
self.pathInfo = {}
|
2011-12-15 14:21:16 +05:30
|
|
|
self.get_pathInfo()
|
2011-12-14 01:32:26 +05:30
|
|
|
|
|
|
|
def relPath(self,relative = '.'):
|
|
|
|
return os.path.join(self.rootDir(),relative)
|
|
|
|
|
2011-12-15 14:21:16 +05:30
|
|
|
def rootDir(self):
|
2011-12-14 01:32:26 +05:30
|
|
|
damask_root = os.getenv('DAMASK_ROOT')
|
2011-12-15 14:21:16 +05:30
|
|
|
if damask_root == '' or damask_root == None: # env not set
|
|
|
|
if sys.argv[0] == '': # no caller path
|
|
|
|
cwd = os.getcwd()
|
|
|
|
else:
|
|
|
|
cwd = {False: os.path.dirname(sys.argv[0]),
|
|
|
|
True: sys.argv[0]}[os.path.isdir(sys.argv[0])]
|
|
|
|
damask_root = os.path.normpath(os.path.join(os.path.realpath(cwd),self.rootRelation))
|
|
|
|
|
2011-12-14 01:32:26 +05:30
|
|
|
return damask_root
|
|
|
|
|
2011-12-15 14:21:16 +05:30
|
|
|
def binDir(self):
|
2011-12-14 01:32:26 +05:30
|
|
|
damask_bin = os.getenv('DAMASK_BIN')
|
|
|
|
if damask_bin == '' or damask_bin == None: damask_bin = self.relPath('bin/')
|
|
|
|
return damask_bin
|
|
|
|
|
2011-12-15 14:21:16 +05:30
|
|
|
def get_pathInfo(self):
|
|
|
|
try: # check for user-defined pathinfo
|
2011-12-14 01:32:26 +05:30
|
|
|
file = open(self.relPath('lib/pathinfo'))
|
2011-12-20 16:25:47 +05:30
|
|
|
content = map(lambda string: string.strip(),file.readlines())
|
2011-12-14 01:32:26 +05:30
|
|
|
file.close()
|
|
|
|
for line in content:
|
2011-12-20 16:25:47 +05:30
|
|
|
if not (line.startswith('#') or line == ''):
|
|
|
|
items = line.split() + ['','']
|
2013-02-01 17:00:57 +05:30
|
|
|
if items[1] == '': # nothing specified
|
|
|
|
self.pathInfo[items[0].lower()] = ''
|
|
|
|
elif items[1].startswith(('/','$')): # absolute path specified ($shellVar is considered absolute)
|
|
|
|
self.pathInfo[items[0].lower()] = items[1]
|
|
|
|
else: # path relative to DAMASK_ROOT/lib
|
|
|
|
self.pathInfo[items[0].lower()] = os.path.normpath(os.path.join(self.relPath('lib/'),items[1]))
|
2011-12-14 01:32:26 +05:30
|
|
|
except:
|
|
|
|
pass
|
2013-03-05 01:09:13 +05:30
|
|
|
|
|
|
|
def isAvailable(self,software,noNeeded=-1):
|
|
|
|
licensesNeeded = {'abaqus' :5,
|
|
|
|
'standard':5,
|
|
|
|
'explicit':5}
|
|
|
|
if noNeeded == -1: noNeeded = licensesNeeded[software]
|
|
|
|
cmd = """ ssh mulicense2 "/Stat_Flexlm | grep 'Users of %s: ' | cut -d' ' -f7,13" """%software
|
|
|
|
process = subprocess.Popen(shlex.split(cmd),stdout = subprocess.PIPE,stderr = subprocess.PIPE)
|
|
|
|
licenses = map(int, process.stdout.readline().split())
|
|
|
|
try:
|
|
|
|
if licenses[0]-licenses[1] >= noNeeded:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
print licenses[1] + noNeeded - licenses[0], 'missing licenses for %s'%software
|
|
|
|
return licenses[1] + noNeeded - licenses[0]
|
|
|
|
except IndexError:
|
|
|
|
print 'Could not retrieve license information for %s'%software
|
|
|
|
return 127
|