[Git][NTPsec/ntpsec][master] contrib/temp: remove regex. Replace with a simple split().

Gary E. Miller gitlab at mg.gitlab.com
Tue Jan 24 00:33:06 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
910aa813 by James Browning at 2017-01-23T16:32:33-08:00
contrib/temp: remove regex.  Replace with a simple split().

Signed-off-by: Gary E. Miller <gem at rellim.com>

- - - - -


2 changed files:

- contrib/smartctl-temp-log
- contrib/temp-log.py


Changes:

=====================================
contrib/smartctl-temp-log
=====================================
--- a/contrib/smartctl-temp-log
+++ b/contrib/smartctl-temp-log
@@ -38,7 +38,6 @@ temperatures will be hardware specific.
 """
 
 
-import re
 import subprocess
 import sys
 import time
@@ -66,17 +65,11 @@ except OSError as e:
     sys.stderr.write("ERROR: Could not start smartctl: %s\n" % e.strerror)
     raise SystemExit(2)
 
-
 lines = output.split('\n')
 
-# this regex matches temperature output lines from 'sensors -u'
-pat = re.compile('194 Temperature_Celsius\s+\S+\s+\d+\s+\d+\s+\d+\s+\S+\s+\S+\s+\S+\s+(\d+)')
-
-now = int(time.time())
-
 line = ''
 for line in lines:
-    match = pat.match(line)
-    if match and match.group(1):
-        temp = match.group(1)
+    if line.startswith('194 '):
+        now = int(time.time())
+        temp = line.split()[9]
         sys.stdout.write('%d %s %s\n' % (now, device, temp))


=====================================
contrib/temp-log.py
=====================================
--- a/contrib/temp-log.py
+++ b/contrib/temp-log.py
@@ -63,8 +63,6 @@ class SmartCtl:
         for child in os.listdir('/dev/'):
             if re.compile('sd[a-z]$').match(child):
                 self._drives.append("/dev/"+str(child))
-        # this regex matches temperature output lines from smartctl -l
-        self._pat = re.compile('194 Temperature_Celsius\s+\S+\s+\d+\s+\d+\s+\d+\s+\S+\s+\S+\s+\S+\s+(\d+)')
 
     def get_data(self):
         "Collects the data and return the output as an array"
@@ -74,10 +72,9 @@ class SmartCtl:
                                               universal_newlines=True
                                               ).split('\n')
             for line in _output:
-                match = self._pat.match(line)
-                now = int(time.time())
-                if match and match.group(1):
-                    temp = match.group(1)
+                if line.startswith('194 '):
+                    now = int(time.time())
+                    temp = line.split()[9]
                     return ('%d %s %s' % (now, _device, temp))
 
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/910aa8131cc3b45584160f12bc2bd7e9ba123f80
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170124/fab944dc/attachment.html>


More information about the vc mailing list