logparse / parsers / sysinfo.pyon commit bugfixing in config & add quiet mode (1542324)
   1#
   2#   sysinfo.py
   3#
   4#   Get standard system information from basic Unix commands
   5#
   6
   7import platform
   8import subprocess
   9import os
  10import re
  11
  12from ..formatting import *
  13from .. import config
  14
  15import logging
  16logger = logging.getLogger(__name__)
  17
  18def parse_log():
  19
  20    logger.debug("Starting sysinfo section")
  21    section = Section("system")
  22    table = Table()
  23
  24    table.add_row(Row([Column("Hostname"), Column(util.hostname(config.prefs['hostname-path']))]))
  25    table.add_row(Row([Column("OS"), Column(platform.platform())]))
  26    table.add_row(Row([Column("OS version"), Column(platform.version())]))
  27    table.add_row(Row([Column("Platform"), Column(platform.system() + " " + platform.machine())]))
  28
  29    processors = []
  30    raw_proc = util.readlog(config.prefs['logs']['cpuinfo'])
  31    line_regex = re.compile(".*model name.*:\s*")
  32    proc_regex = re.compile("\s*(\(R\)|\(TM\)|CPU)")
  33    for line in raw_proc.splitlines():
  34        if "model name" in line:
  35            processor = line_regex.sub("", line, 1)
  36            processor = " ".join(proc_regex.sub("", processor).split()) # remove extraneous text and whitespace
  37            if not processor in processors:
  38                processors.append(processor)
  39            else:
  40                logger.debug("Found duplicate entry (perhaps multiple cores?) for {0}".format(processor))
  41    table.align_column(0, "right")
  42    if len(processors) == 1:
  43        table.add_row(Row([Column("Processor"), Column("; ".join(processors))]))
  44        section.append_table(table)
  45    elif len(processors) > 1:
  46        section.append_table(table)
  47        proc_data = Data("Processors")
  48        proc_data.items = processors
  49        section.append_data(proc_data)
  50    else:
  51        logger.warning("Failed to find processor data")
  52
  53    logger.info("Finished sysinfo section")
  54    return section