[Git][NTPsec/ntpsec][master] 2 commits: temp-log.py: remove redundant else's

Gary E. Miller gitlab at mg.gitlab.com
Fri Jan 27 00:53:10 UTC 2017


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


Commits:
fd21e6be by Gary E. Miller at 2017-01-26T16:47:00-08:00
temp-log.py: remove redundant else's

- - - - -
ea61bd42 by Gary E. Miller at 2017-01-26T16:51:43-08:00
temp-log: Add -q, error display should not need -v.  Better smartctl.

Sorted output of all smart drives.  Clearly Pyhton has no
reasonable way to list directory contents...

- - - - -


1 changed file:

- contrib/temp-log.py


Changes:

=====================================
contrib/temp-log.py
=====================================
--- a/contrib/temp-log.py
+++ b/contrib/temp-log.py
@@ -55,21 +55,23 @@ class CpuTemp:
 
 class SmartCtl:
     "Sensor on the Hard Drive"
+    _drives = []
+
     def __init__(self):
         if os.getuid() != 0:
             raise IOError("You must be root!")
         # Which drive to watch
-        self._drives = []
         for child in os.listdir('/dev/'):
             if re.compile('sd[a-z]$').match(child):
                 self._drives.append("/dev/"+str(child))
+        self._drives = sorted(self._drives)
 
     def get_data(self):
         "Collects the data and return the output as an array"
         out = ""
         for _device in self._drives[:]:
             try:
-                _output = subprocess.check_output(["smartctl", "-a",
+                _output = subprocess.check_output(["smartctl", "-A",
                                                   _device],
                                                   universal_newlines=True
                                                   ).split('\n')
@@ -119,6 +121,10 @@ parser.add_argument('-o', '--once',
                     dest='once',
                     help="Run the output once and exit",
                     action='store_true')
+parser.add_argument('-q', '--quiet',
+                    action="store_true",
+                    dest='quiet',
+                    help="be quite")
 parser.add_argument('-v', '--verbose',
                     action="store_true",
                     dest='verbose',
@@ -179,17 +185,13 @@ def log_data():
         zone = ZoneTemp()
         hdd = SmartCtl()
     except IOError as ioe:
-        if args.verbose:
+        if not args.quiet:
             sys.stderr.write("Unable to run: " + str(ioe) + "\n")
-            sys.exit(1)
-        else:
-            sys.exit(1)
+        sys.exit(1)
     except Exception as e:
-        if args.verbose:
+        if not quiet:
             sys.stderr.write("Unable to run: " + str(e) + "\n")
-            sys.exit(1)
-        else:
-            sys.exit(1)
+        sys.exit(1)
 
     # Create the logger instance
     Logger = logging_setup(log, logging.INFO)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/a2b879173d4a7f6320a877f1b5a6d4dc68060606...ea61bd425d4d6c3ebe14b5bc865f948641d56229
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170127/5e351834/attachment.html>


More information about the vc mailing list