# # sysinfo.py # # Get standard system information from basic Unix commands # import platform import subprocess import os import re from ..formatting import * from .. import config 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(config.prefs['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(config.prefs['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