From 5bc5403d6d41ec891774227ff987b96b600e6412 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 1 Jun 2018 15:43:07 +1000 Subject: [PATCH] Revert to pre-3.6 regex group matching --- afsmon/__init__.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/afsmon/__init__.py b/afsmon/__init__.py index 92ad31e..ca1c93d 100644 --- a/afsmon/__init__.py +++ b/afsmon/__init__.py @@ -94,11 +94,11 @@ class FileServerStats(object): # todo: there's a bunch more we could extract... m = vol_regex.search(chunk) q = re.search('MaxQuota\s+(?P\d+) K', chunk) - used = int(m['used']) - quota = int(q['quota']) + used = int(m.group('used')) + quota = int(q.group('quota')) percent_used = round(float(used) / float(quota) * 100, 2) self.volumes.append( - Volume(m['vol'], m['id'], m['perms'], + Volume(m.group('vol'), m.group('id'), m.group('perms'), used, quota, percent_used)) def _get_calls_waiting(self): @@ -110,10 +110,10 @@ class FileServerStats(object): for line in output.split('\n'): m = re.search('(?P\d+) calls waiting for a thread', line) if m: - self.calls_waiting = int(m['waiting']) + self.calls_waiting = int(m.group('waiting')) m = re.search('(?P\d+) threads are idle', line) if m: - self.idle_threads = int(m['idle']) + self.idle_threads = int(m.group('idle')) def _get_partition_stats(self): cmd = ["vos", "partinfo", self.hostname, "-noauth"] @@ -127,12 +127,13 @@ class FileServerStats(object): '/vicep(?P[a-z][a-z]?): ' '(?P\d+) K blocks out of total (?P\d+)', line) if m: - part = 'vicep%s' % m['partition'] + part = 'vicep%s' % m.group('partition') # (used, free, total, %age) - used = int(m['total']) - int(m['free']) + used = int(m.group('total')) - int(m.group('free')) + percent = round(float(used) / float(m.group('total')) * 100, 2) self.partitions.append( - Partition(part, used, int(m['free']), int(m['total']), - round(float(used) / float(m['total']) * 100, 2))) + Partition(part, used, int(m.group('free')), + int(m.group('total')), percent)) def _get_fs_stats(self): cmd = ["bos", "status", self.hostname, "-long", "-noauth"] @@ -150,7 +151,8 @@ class FileServerStats(object): m = re.search( r'last started at (?P\w+ \w+ \w+ \d+:\d+:\d+ \d+)', output) - self.restart = datetime.strptime(m['date'], '%a %b %d %H:%M:%S %Y') + self.restart = datetime.strptime(m.group('date'), + '%a %b %d %H:%M:%S %Y') self.uptime = self.timestamp - self.restart elif re.search('temporarily disabled, currently shutdown', output):