From dcc872442f52648c22a6e5055149fee8df627505 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 12 Feb 2020 11:46:24 +1100 Subject: [PATCH] flake8 regex fixes Prefix strings with regex escapes with "r" Change-Id: I1dcbaa9947a693992e560ca258469b8cbcfcfec3 --- afsmon/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/afsmon/__init__.py b/afsmon/__init__.py index b08523f..d70938f 100644 --- a/afsmon/__init__.py +++ b/afsmon/__init__.py @@ -33,6 +33,7 @@ class FileServerStatus(Enum): UNKNOWN = 3 NO_CONNECTION = 4 + Partition = collections.namedtuple( 'Partition', 'partition, used, free, total, percent_used') @@ -68,7 +69,7 @@ class FileServerStats(object): # Sample AFS timestamps: # Tue Nov 2 03:35:15 2016 # Tue Nov 22 03:35:15 2016 - AFS_DATE_REGEX = '(?P\w+ \w+\s+(\d{1,2}) \d+:\d+:\d+ \d+)' + AFS_DATE_REGEX = r'(?P\w+ \w+\s+(\d{1,2}) \d+:\d+:\d+ \d+)' AFS_DATE_STRPTIME = '%a %b %d %H:%M:%S %Y' def _get_volumes(self): @@ -99,7 +100,7 @@ class FileServerStats(object): # convert it to a Volume() # todo: there's a bunch more we could extract... m = vol_regex.search(chunk) - q = re.search('MaxQuota\s+(?P\d+) K', chunk) + q = re.search(r'MaxQuota\s+(?P\d+) K', chunk) used = int(m.group('used')) quota = int(q.group('quota')) percent_used = round(float(used) / float(quota) * 100, 2) @@ -118,10 +119,10 @@ class FileServerStats(object): cmd, stderr=subprocess.STDOUT).decode('ascii') for line in output.split('\n'): - m = re.search('(?P\d+) calls waiting for a thread', line) + m = re.search(r'(?P\d+) calls waiting for a thread', line) if m: self.calls_waiting = int(m.group('waiting')) - m = re.search('(?P\d+) threads are idle', line) + m = re.search(r'(?P\d+) threads are idle', line) if m: self.idle_threads = int(m.group('idle')) @@ -133,9 +134,9 @@ class FileServerStats(object): for line in output.split('\n'): m = re.search( - 'Free space on partition ' - '/vicep(?P[a-z][a-z]?): ' - '(?P\d+) K blocks out of total (?P\d+)', line) + r'Free space on partition ' + r'/vicep(?P[a-z][a-z]?): ' + r'(?P\d+) K blocks out of total (?P\d+)', line) if m: part = 'vicep%s' % m.group('partition') # (used, free, total, %age)