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 = '.'):
|
2014-01-17 02:59:39 +05:30
|
|
|
self.rootRelation = rootRelation
|
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):
|
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:
|
2014-01-17 02:59:39 +05:30
|
|
|
cwd = sys.argv[0] if os.path.isdir(sys.argv[0]) else os.path.dirname(sys.argv[0])
|
|
|
|
|
2011-12-15 14:21:16 +05:30
|
|
|
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')
|
2014-01-17 02:59:39 +05:30
|
|
|
if damask_bin == '' or damask_bin == None: damask_bin = self.relPath('bin/')
|
2011-12-14 01:32:26 +05:30
|
|
|
return damask_bin
|
2014-01-12 00:43:02 +05:30
|
|
|
|
|
|
|
def get_options(self):
|
2014-01-17 02:59:39 +05:30
|
|
|
with open(self.relPath('installation/options')) as file:
|
|
|
|
for line in file:
|
|
|
|
l = line.strip()
|
|
|
|
if not (l.startswith('#') or l == ''):
|
|
|
|
items = l.split('=') + ['','']
|
2014-01-15 00:33:41 +05:30
|
|
|
if items[1] != '': # nothing specified
|
|
|
|
self.options[items[0].upper()] = items[1]
|
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
|
|
|
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:
|
2014-01-17 02:59:39 +05:30
|
|
|
if licenses[0]-licenses[1] >= Nneeded:
|
2013-03-05 01:09:13 +05:30
|
|
|
return 0
|
|
|
|
else:
|
2014-01-17 02:59:39 +05:30
|
|
|
print(licenses[1] + Nneeded - licenses[0], 'missing licenses for %s'%software)
|
|
|
|
return licenses[1] + Nneeded - licenses[0]
|
2013-03-05 01:09:13 +05:30
|
|
|
except IndexError:
|
2013-09-14 16:22:02 +05:30
|
|
|
print('Could not retrieve license information for %s'%software)
|
2014-01-12 00:43:02 +05:30
|
|
|
return 127
|