"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "plugins/dstat_condor_queue.py" between
dstat-0.7.3.tar.gz and dstat-0.7.4.tar.gz

About: dstat is a versatile resource statistic tool and a replacement for vmstat, iostat and ifstat (using Python).

dstat_condor_queue.py  (dstat-0.7.3):dstat_condor_queue.py  (dstat-0.7.4)
skipping to change at line 30 skipping to change at line 30
ATTR_VAR_PATTERN = re.compile(r'\$\((\w+)\)') ATTR_VAR_PATTERN = re.compile(r'\$\((\w+)\)')
def __init__(self, file=None, config=None): def __init__(self, file=None, config=None):
if file != None: if file != None:
self.attributes = condor_classad._read_from_file(file) self.attributes = condor_classad._read_from_file(file)
elif config != None: elif config != None:
self.attributes = condor_classad._parse(config) self.attributes = condor_classad._parse(config)
if self.attributes == None: if self.attributes == None:
raise Exception, 'condor_config must be initialized either using a f ile or config text' raise Exception('condor_config must be initialized either using a fi le or config text')
local_config_file = self['LOCAL_CONFIG_FILE'] local_config_file = self['LOCAL_CONFIG_FILE']
if local_config_file != None: if local_config_file != None:
for k,v in condor_classad._read_from_file(local_config_file).items() : for k,v in condor_classad._read_from_file(local_config_file).items() :
self.attributes[k] = v self.attributes[k] = v
def __getitem__(self, name): def __getitem__(self, name):
if name in self.attributes: if name in self.attributes:
self._expand(name) self._expand(name)
skipping to change at line 68 skipping to change at line 68
for l in [l for l in text.split('\n') if not l.strip().startswith('#')]: for l in [l for l in text.split('\n') if not l.strip().startswith('#')]:
l = l.split('=') l = l.split('=')
if len(l) <= 1 or len(l[0]) == 0: if len(l) <= 1 or len(l[0]) == 0:
continue continue
attributes[l[0].strip()] = ''.join(l[1:]).strip() attributes[l[0].strip()] = ''.join(l[1:]).strip()
return attributes return attributes
@staticmethod @staticmethod
def _read_from_file(filename): def _read_from_file(filename):
if not os.access(filename, os.R_OK): if not os.access(filename, os.R_OK):
raise Exception, 'Unable to read file %s' % filename raise Exception('Unable to read file %s' % filename)
try: try:
f = open(filename) f = open(filename)
return condor_classad._parse((f.read())) return condor_classad._parse((f.read()))
finally: finally:
f.close() f.close()
class dstat_plugin(dstat): class dstat_plugin(dstat):
""" """
Plugin for Condor queue stats Plugin for Condor queue stats
""" """
skipping to change at line 94 skipping to change at line 94
self.name = 'condor queue' self.name = 'condor queue'
self.vars = ('jobs', 'idle', 'running', 'held') self.vars = ('jobs', 'idle', 'running', 'held')
self.type = 'd' self.type = 'd'
self.width = 5 self.width = 5
self.scale = 1 self.scale = 1
self.condor_config = None self.condor_config = None
def check(self): def check(self):
config_file = os.environ['CONDOR_CONFIG'] config_file = os.environ['CONDOR_CONFIG']
if config_file == None: if config_file == None:
raise Exception, 'Environment varibale CONDOR_CONFIG is missing' raise Exception('Environment varibale CONDOR_CONFIG is missing')
self.condor_config = condor_classad(config_file) self.condor_config = condor_classad(config_file)
bin_dir = self.condor_config['BIN'] bin_dir = self.condor_config['BIN']
if bin_dir == None: if bin_dir == None:
raise Exception, 'Unable to find BIN directory in condor config file %s' % config_file raise Exception('Unable to find BIN directory in condor config file %s' % config_file)
self.condor_status_cmd = os.path.join(bin_dir, 'condor_q') self.condor_status_cmd = os.path.join(bin_dir, 'condor_q')
if not os.access(self.condor_status_cmd, os.X_OK): if not os.access(self.condor_status_cmd, os.X_OK):
raise Exception, 'Needs %s in the path' % self.condor_status_cmd raise Exception('Needs %s in the path' % self.condor_status_cmd)
else: else:
try: try:
p = os.popen(self.condor_status_cmd+' 2>&1 /dev/null') p = os.popen(self.condor_status_cmd+' 2>&1 /dev/null')
ret = p.close() ret = p.close()
if ret: if ret:
raise Exception, 'Cannot interface with Condor - condor_q re turned != 0?' raise Exception('Cannot interface with Condor - condor_q ret urned != 0?')
except IOError: except IOError:
raise Exception, 'Unable to execute %s' % self.condor_status_cmd raise Exception('Unable to execute %s' % self.condor_status_cmd)
return True return True
def extract(self): def extract(self):
last_line = None last_line = None
try: try:
for repeats in range(3): for repeats in range(3):
for last_line in cmd_readlines(self.condor_status_cmd): for last_line in cmd_readlines(self.condor_status_cmd):
pass pass
m = CONDOR_Q_STAT_PATTER.match(last_line) m = CONDOR_Q_STAT_PATTER.match(last_line)
if m == None: if m == None:
raise Exception, 'Invalid output from %s. Got: %s' % (cmd, l ast_line) raise Exception('Invalid output from %s. Got: %s' % (cmd, la st_line))
stats = [int(s.strip()) for s in m.groups()] stats = [int(s.strip()) for s in m.groups()]
for i,j in enumerate(self.vars): for i,j in enumerate(self.vars):
self.val[j] = stats[i] self.val[j] = stats[i]
except Exception: except Exception:
for name in self.vars: for name in self.vars:
self.val[name] = -1 self.val[name] = -1
# vim:ts=4:sw=4:et # vim:ts=4:sw=4:et
 End of changes. 9 change blocks. 
9 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)