add more docstrings
[logparse.git] / logparse / parsers / sysinfo.py
index e0168b8b91c542371c982693cf7bba268fb6c2bd..6b89f82448bf84fe1ce5e92d7617a4263060cad7 100644 (file)
@@ -11,44 +11,49 @@ import re
 
 from logparse.formatting import *
 from logparse.config import prefs
-
-import logging
-logger = logging.getLogger(__name__)
-
-def parse_log():
-
-    logger.debug("Starting sysinfo section")
-    section = Section("system")
-    table = Table()
-
-    table.add_row(Row([Column("Hostname"), Column(util.hostname(prefs.get("logparse", "hostname-path")))]))
-    table.add_row(Row([Column("OS"), Column(platform.platform())]))
-    table.add_row(Row([Column("OS version"), Column(platform.version())]))
-    table.add_row(Row([Column("Platform"), Column(platform.system() + " " + platform.machine())]))
-
-    processors = []
-    raw_proc = util.readlog(prefs.get("logs", "cpuinfo"))
-    line_regex = re.compile(".*model name.*:\s*")
-    proc_regex = re.compile("\s*(\(R\)|\(TM\)|CPU)")
-    for line in raw_proc.splitlines():
-        if "model name" in line:
-            processor = line_regex.sub("", line, 1)
-            processor = " ".join(proc_regex.sub("", processor).split()) # remove extraneous text and whitespace
-            if not processor in processors:
-                processors.append(processor)
-            else:
-                logger.debug("Found duplicate entry (perhaps multiple cores?) for {0}".format(processor))
-    table.align_column(0, "right")
-    if len(processors) == 1:
-        table.add_row(Row([Column("Processor"), Column("; ".join(processors))]))
-        section.append_table(table)
-    elif len(processors) > 1:
-        section.append_table(table)
-        proc_data = Data("Processors")
-        proc_data.items = processors
-        section.append_data(proc_data)
-    else:
-        logger.warning("Failed to find processor data")
-
-    logger.info("Finished sysinfo section")
-    return section
+from logparse.load_parsers import Parser
+
+class Sysinfo(Parser):
+
+    def __init__(self):
+        super().__init__()
+        self.name = "sysinfo"
+        self.info = "Get standard system information from basic Unix commands"
+
+    def parse_log(self):
+
+        logger.debug("Starting sysinfo section")
+        section = Section("system")
+        table = Table()
+
+        table.add_row(Row([Column("Hostname"), Column(util.hostname(prefs.get("logparse", "hostname-path")))]))
+        table.add_row(Row([Column("OS"), Column(platform.platform())]))
+        table.add_row(Row([Column("OS version"), Column(platform.version())]))
+        table.add_row(Row([Column("Platform"), Column(platform.system() + " " + platform.machine())]))
+
+        processors = []
+        raw_proc = util.readlog(prefs.get("logs", "cpuinfo"))
+        line_regex = re.compile(".*model name.*:\s*")
+        proc_regex = re.compile("\s*(\(R\)|\(TM\)|CPU)")
+        for line in raw_proc.splitlines():
+            if "model name" in line:
+                processor = line_regex.sub("", line, 1)
+                processor = " ".join(proc_regex.sub("", processor).split()) # remove extraneous text and whitespace
+                if not processor in processors:
+                    processors.append(processor)
+                else:
+                    logger.debug("Found duplicate entry (perhaps multiple cores?) for {0}".format(processor))
+        table.align_column(0, "right")
+        if len(processors) == 1:
+            table.add_row(Row([Column("Processor"), Column("; ".join(processors))]))
+            section.append_table(table)
+        elif len(processors) > 1:
+            section.append_table(table)
+            proc_data = Data("Processors")
+            proc_data.items = processors
+            section.append_data(proc_data)
+        else:
+            logger.warning("Failed to find processor data")
+
+        logger.info("Finished sysinfo section")
+        return section