# Path: kano/logging.py
# class lazy_logger:
# class loader:
#     def __getattr__(self, name):
#     def __init__(self, old_mod):
#     def __getattr__(self, name):
# def log_excepthook(exc_class, exc_value, tb):
# 
# Path: kano/utils/shell.py
# def run_cmd(cmd, localised=False, unsudo=False):
#     '''
#     Executes cmd, returning stdout, stderr, return code
#     if localised is False, LC_ALL will be set to "C"
#     '''
#     env = os.environ.copy()
#     if not localised:
#         env['LC_ALL'] = 'C'
# 
#     if unsudo and \
#             'SUDO_USER' in os.environ and \
#             os.environ['SUDO_USER'] != 'root':
#         cmd = "sudo -u {} bash -c '{}' ".format(os.environ['SUDO_USER'], cmd)
# 
#     process = subprocess.Popen(cmd, shell=True, env=env,
#                                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
#                                preexec_fn=restore_signals)
# 
#     stdout, stderr = process.communicate()
#     returncode = process.returncode
#     return stdout, stderr, returncode
# 
# Path: kano/utils/file_operations.py
# def read_file_contents_as_lines(path):
#     if os.path.exists(path):
#         with open(path) as infile:
#             content = infile.readlines()
#             lines = [line.strip() for line in content]
#             return lines


import traceback
from kano.logging import logger
from kano.utils.shell import run_cmd
from kano.utils.file_operations import read_file_contents_as_lines
    Args:
        use_cached (bool): Read the revision from a cached value or read
            it from the ``/proc/cpuinfo`` file directly.

    Returns:
        str: Hexadecimal value for the Raspberry Pi board revision; emptry
        string if the value could not be read.
    """
    global _g_revision

    if use_cached and _g_revision:
        return _g_revision

    for entry in reversed(read_file_contents_as_lines(CPUINFO_FILE)):
        if entry.startswith('Revision'):
            _g_revision = entry.split(':')[1].strip()
            return _g_revision

    return ''


def is_monitor():
    status_str, _, _ = run_cmd('/usr/bin/tvservice -s')
    return 'RGB full' in status_str


def get_cpu_id():
    '''
    Returns the RaspberryPI Serial number from /proc/cpuinfo
    '''

# Path: kano/logging.py
# class lazy_logger:
# class loader:
#     def __getattr__(self, name):
#     def __init__(self, old_mod):
#     def __getattr__(self, name):
# def log_excepthook(exc_class, exc_value, tb):
# 
# Path: kano/utils/shell.py
# def run_cmd(cmd, localised=False, unsudo=False):
#     '''
#     Executes cmd, returning stdout, stderr, return code
#     if localised is False, LC_ALL will be set to "C"
#     '''
#     env = os.environ.copy()
#     if not localised:
#         env['LC_ALL'] = 'C'
# 
#     if unsudo and \
#             'SUDO_USER' in os.environ and \
#             os.environ['SUDO_USER'] != 'root':
#         cmd = "sudo -u {} bash -c '{}' ".format(os.environ['SUDO_USER'], cmd)
# 
#     process = subprocess.Popen(cmd, shell=True, env=env,
#                                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
#                                preexec_fn=restore_signals)
# 
#     stdout, stderr = process.communicate()
#     returncode = process.returncode
#     return stdout, stderr, returncode
# 
# Path: kano/utils/file_operations.py
# def read_file_contents_as_lines(path):
#     if os.path.exists(path):
#         with open(path) as infile:
#             content = infile.readlines()
#             lines = [line.strip() for line in content]
#             return lines


# Path: kano/utils/hardware.py
import traceback
from kano.logging import logger
from kano.utils.shell import run_cmd
from kano.utils.file_operations import read_file_contents_as_lines

    Args:
        use_cached (bool): Read the revision from a cached value or read
            it from the ``/proc/cpuinfo`` file directly.

    Returns:
        str: Hexadecimal value for the Raspberry Pi board revision; emptry
        string if the value could not be read.
    """
    global _g_revision

    if use_cached and _g_revision:
        return _g_revision

    for entry in reversed(read_file_contents_as_lines(CPUINFO_FILE)):
        if entry.startswith('Revision'):
            _g_revision = entry.split(':')[1].strip()
            return _g_revision

    return ''


def is_monitor():
    status_str, _, _ = run_cmd('/usr/bin/tvservice -s')
    return 'RGB full' in status_str


def get_cpu_id():
    '''
    Returns the RaspberryPI Serial number from /proc/cpuinfo
    '''

    lines = read_file_contents_as_lines(CPUINFO_FILE)