2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2016-09-08 12:15:46 +05:30
|
|
|
import os,subprocess,shlex,re
|
2011-12-14 01:32:26 +05:30
|
|
|
|
|
|
|
class Environment():
|
2011-12-15 14:21:16 +05:30
|
|
|
__slots__ = [ \
|
2014-01-17 07:07:01 +05:30
|
|
|
'options',
|
2011-12-14 01:32:26 +05:30
|
|
|
]
|
|
|
|
|
2016-07-14 18:39:25 +05:30
|
|
|
def __init__(self):
|
2014-01-15 00:33:41 +05:30
|
|
|
self.options = {}
|
|
|
|
self.get_options()
|
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):
|
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
|
|
|
|
2014-01-12 00:43:02 +05:30
|
|
|
def get_options(self):
|
2016-07-14 02:01:38 +05:30
|
|
|
with open(self.relPath(self.rootDir()+'/CONFIG')) as configFile:
|
|
|
|
for line in configFile:
|
2016-07-14 18:39:25 +05:30
|
|
|
l = re.sub('^set ', '', line).strip() # remove "set" (tcsh) when setting variables
|
2016-07-14 02:01:38 +05:30
|
|
|
if l and not l.startswith('#'):
|
2016-08-01 20:31:13 +05:30
|
|
|
items = re.split(r'\s*=\s*',l)
|
2016-07-14 18:39:25 +05:30
|
|
|
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
|
2013-03-05 01:09:13 +05:30
|
|
|
|
2014-01-17 02:59:39 +05:30
|
|
|
def isAvailable(self,software,Nneeded =-1):
|
2013-03-05 01:09:13 +05:30
|
|
|
licensesNeeded = {'abaqus' :5,
|
|
|
|
'standard':5,
|
|
|
|
'explicit':5}
|
2014-01-17 02:59:39 +05:30
|
|
|
if Nneeded == -1: Nneeded = licensesNeeded[software]
|
2013-03-05 01:09:13 +05:30
|
|
|
try:
|
2014-10-21 11:10:26 +05:30
|
|
|
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] >= Nneeded:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
print('%s missing licenses for %s'%(licenses[1] + Nneeded - licenses[0],software))
|
|
|
|
return licenses[1] + Nneeded - licenses[0]
|
|
|
|
except IndexError:
|
|
|
|
print('Could not retrieve license information for %s'%software)
|
|
|
|
return 127
|
|
|
|
except:
|
|
|
|
return 126
|