[Git][NTPsec/ntpsec][master] cleaned up my bad push from earlier today and fixed issues raised by pyflakes and pep8.

deamoneye gitlab at mg.gitlab.com
Sat Jan 21 04:36:06 UTC 2017


deamoneye pushed to branch master at NTPsec / ntpsec


Commits:
cf17aea3 by Keane Wolter at 2017-01-20T23:35:43-05:00
cleaned up my bad push from earlier today and fixed issues raised by pyflakes and pep8.

- - - - -


1 changed file:

- contrib/temp-log.py


Changes:

=====================================
contrib/temp-log.py
=====================================
--- a/contrib/temp-log.py
+++ b/contrib/temp-log.py
@@ -6,7 +6,6 @@
 # Writes logs to /var/log/ntpstats
 # Requires root to run
 
-<<<<<<< Updated upstream
 import logging
 import logging.handlers
 import os
@@ -14,13 +13,11 @@ import re
 import subprocess
 import sys
 import time
-
-=======
-import sys, re, time, subprocess, os, logging, logging.handlers, argparse
+import argparse
 
 # Global vars
 version = 1.0
->>>>>>> Stashed changes
+
 
 class CpuTemp:
     "Sensors on the CPU Core"
@@ -38,7 +35,8 @@ class CpuTemp:
         _index = 0
         _data = []
         # grab the needed output
-        _output = subprocess.check_output([self._sensors_path, "-u"], universal_newlines=True).split('\n')
+        _output = subprocess.check_output([self._sensors_path, "-u"],
+                                          universal_newlines=True).split('\n')
         for record in _output:
             match = self._pattern.match(record)
             if match and match.group(1):
@@ -49,17 +47,7 @@ class CpuTemp:
 
         return _data
 
-<<<<<<< Updated upstream
-    def _record_temp(self):
-        "Call the external command 'sensors -u' and get the data"
-        # grab the data from the "sensors -u" command
-        output = subprocess.check_output([self._sensors_path, "-u"],
-                                         universal_newlines=True)
-        self.sensors_output = output.split('\n')
-
 
-=======
->>>>>>> Stashed changes
 class SmartCtl:
     "Sensor on the Hard Drive"
     def __init__(self):
@@ -75,26 +63,17 @@ class SmartCtl:
 
     def get_data(self):
         "Collects the data and return the output as an array"
-<<<<<<< Updated upstream
-        _output = subprocess.check_output(["smartctl", "-a", self._device],
-                                          universal_newlines=True)
-        _lines = _output.split('\n')
-        for line in _lines:
-            match = self._pat.match(line)
-            now = int(time.time())
-            if match and match.group(1):
-                temp = match.group(1)
-                return ('%d SMART %s' % (now, temp))
-=======
         for _device in self._drives:
-            _output = subprocess.check_output(["smartctl", "-a", _device], universal_newlines=True).split('\n')
+            _output = subprocess.check_output(["smartctl", "-a",
+                                              _device],
+                                              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)
                     return ('%d,%s,%s' % (now, _device, temp))
->>>>>>> Stashed changes
 
 
 class ZoneTemp:
@@ -121,24 +100,11 @@ class ZoneTemp:
             _zone_data.close()
         return _data
 
-<<<<<<< Updated upstream
-# Global vars
-version = 1.0
-# Create objects
-cpu = CpuTemp()
-zone = ZoneTemp()
-hdd = SmartCtl('/dev/sda')
 
-
-def logging_setup(fileName, levelName, logLevel):
-    "Create logging object with midnight rotation"
-    logFormat = logging.Formatter(
-        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
-=======
 def logging_setup(fileName, levelName, logLevel):
     "Create logging object"
-    logFormat = logging.Formatter('%(asctime)s,%(name)s,%(levelname)s,%(message)s')
->>>>>>> Stashed changes
+    logFormat = logging.Formatter(
+        '%(asctime)s,%(name)s,%(levelname)s,%(message)s')
     # Create logger for cpuTemp
     tempLogger = logging.getLogger(levelName)
     tempLogger.setLevel(logLevel)
@@ -157,14 +123,11 @@ def logging_setup(fileName, levelName, logLevel):
     tempLogger.addHandler(_file)
     return tempLogger
 
-<<<<<<< Updated upstream
 
-def log_data(logger, data):
-    "Write data to the log"
-=======
 def console_log_setup(levelName, logLevel):
     "Create logging object that writes to STDOUT"
-    logFormat = logging.Formatter('%(asctime)s,%(name)s,%(levelname)s,%(message)s')
+    logFormat = logging.Formatter(
+        '%(asctime)s,%(name)s,%(levelname)s,%(message)s')
     # Create the logging object
     tempLog = logging.getLogger(levelName)
     tempLog.setLevel(logLevel)
@@ -177,42 +140,30 @@ def console_log_setup(levelName, logLevel):
     tempLog.addHandler(ch)
     return tempLog
 
+
 def logData(log, data):
     "log the data"
->>>>>>> Stashed changes
     if type(data) in (tuple, list):
         for _item in data:
             log.info(_item)
     else:
         log.info(data)
 
-<<<<<<< Updated upstream
 
-def log_with_multiple_files():
-    "Write the logs to individual files depending on sensor"
-    # Create logger instances
-    zoneLogger = logging_setup('/var/log/ntpstats/zoneTemp.log',
-                               'zone_levelname', logging.INFO)
-    cpuLogger = logging_setup('/var/log/ntpstats/cpuTemp.log',
-                              'cpu_levelname', logging.INFO)
-    hddLogger = logging_setup('/var/log/ntpstats/hddTemp.log',
-                              'hdd_levelname', logging.INFO)
-=======
 def log_data():
     "Write all temperature readings to one file"
     try:
         # Create objects
-        cpu  = CpuTemp()
+        cpu = CpuTemp()
         zone = ZoneTemp()
-        hdd  = SmartCtl()
+        hdd = SmartCtl()
     except IOError as ioe:
         sys.stderr.write("Unable to run: " + str(ioe) + "\n")
         sys.exit(1)
     # Create the logger instance
     zoneLogger = logging_setup(log, 'zone', logging.INFO)
-    cpuLogger  = logging_setup(log, 'cpu', logging.INFO)
-    hddLogger  = logging_setup(log, 'hdd', logging.INFO)
->>>>>>> Stashed changes
+    cpuLogger = logging_setup(log, 'cpu', logging.INFO)
+    hddLogger = logging_setup(log, 'hdd', logging.INFO)
 
     # Write data to their respective logs forever
     while True:
@@ -222,34 +173,20 @@ def log_data():
         # Sleep 15 seconds
         time.sleep(15)
 
-<<<<<<< Updated upstream
 
-def log_with_one_file():
-    "Write all temperature readings to one file"
-    # Create the logger instance
-    zoneLogger = logging_setup('/var/log/ntpstats/temp.log',
-                               'zone_levelname', logging.INFO)
-    cpuLogger = logging_setup('/var/log/ntpstats/temp.log',
-                              'cpu_levelname', logging.INFO)
-    hddLogger = logging_setup('/var/log/ntpstats/temp.log',
-                              'hdd_levelname', logging.INFO)
-
-    # Write data to their respective logs forever
-=======
 def display():
     try:
         # Create objects
-        cpu  = CpuTemp()
+        cpu = CpuTemp()
         zone = ZoneTemp()
-        hdd  = SmartCtl()
+        hdd = SmartCtl()
     except IOError as ioe:
         sys.stderr.write("Unable to run: " + str(ioe) + "\n")
         sys.exit(1)
 
     zoneLogger = console_log_setup('zone', logging.INFO)
-    cpuLogger  = console_log_setup('cpu', logging.INFO)
-    hddLogger  = console_log_setup('hdd', logging.INFO)
->>>>>>> Stashed changes
+    cpuLogger = console_log_setup('cpu', logging.INFO)
+    hddLogger = console_log_setup('hdd', logging.INFO)
     while True:
         logData(zoneLogger, zone.get_data())
         logData(cpuLogger, cpu.get_data())
@@ -257,44 +194,7 @@ def display():
         # Sleep 15 seconds
         time.sleep(15)
 
-<<<<<<< Updated upstream
-
-def help_text():
-    "Help message"
-    print("temp-log.py [-f filepath] [-h] "
-          "[-s [-r {hour|day|week|month|year}] [-m] [-V]")
-    print("-h\tPrints this help message")
-    print("-s\tWrites all data to a single log file")
-    print("-m\tWrites data for each sensor type to their own log file")
-    print("-V\tPrints the version")
-
-try:
-    if sys.argv[1] == "-h" or sys.argv[1] == "--help":
-        help_text()
-
-    if sys.argv[1] == "-V" or sys.argv[1] == "--version":
-        print("Version: " + str(version))
-
-    if sys.argv[1] == "-s":
-        log_with_one_file()
-
-    if sys.argv[1] == "-m":
-        log_with_multiple_files()
 
-except IndexError:
-    help_text()
-except Exception as e:
-    sys.stderr.write("Unable to run: " + str(e))
-    sys.exit(1)
-except IOError as ioe:
-    sys.stderr.write("Unable to run: " + str(ioe))
-    sys.exit(1)
-except KeyboardInterrupt:
-    sys.exit(0)
-except:
-    help_text()
-    sys.exit(1)
-=======
 # Work with argvars
 parser = argparse.ArgumentParser(description="Temperature sensor daemon",
                                  epilog="""See the manual page for details.""")
@@ -322,4 +222,3 @@ else:
         display()
     except (KeyboardInterrupt, SystemExit):
         sys.exit(0)
->>>>>>> Stashed changes



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/cf17aea3aa9488dbb8b64d564ff7c5e069cc61bd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170121/9256bc21/attachment.html>


More information about the vc mailing list