Exemple #1
0
def get_screen_log():
    """Get display information using kano-settings display functions.

    Returns:
        dict: An aggregate of display characteristics
    """

    try:
        from kano_settings.system.display import get_edid, get_edid_name, get_status, \
            list_supported_modes, get_optimal_resolution_mode, override_models

        edid = get_edid()
        model = get_edid_name(use_cached=False)

        override_models(edid, model)

        status = get_status()
        supported = list_supported_modes(use_cached=False)
        optimal = get_optimal_resolution_mode(edid, supported)

        log_data = {
            'model': model,
            'status': status,
            'edid': edid,
            'supported': supported,
            'optimal': optimal,
        }
        log = json.dumps(log_data, sort_keys=True, indent=4)
    except:
        return traceback.format_exc()

    return log
def get_screen_log():
    """Get display information using kano-settings display functions.

    Returns:
        dict: An aggregate of display characteristics
    """

    try:
        from kano_settings.system.display import get_edid, get_edid_name, get_status, \
            list_supported_modes, get_optimal_resolution_mode, override_models

        edid = get_edid()
        model = get_edid_name(use_cached=False)

        override_models(edid, model)

        status = get_status()
        supported = list_supported_modes(use_cached=False)
        optimal = get_optimal_resolution_mode(edid, supported)

        log_data = {
            'model': model,
            'status': status,
            'edid': edid,
            'supported': supported,
            'optimal': optimal,
        }
        log = json.dumps(log_data, sort_keys=True, indent=4)
    except:
        return traceback.format_exc()

    return log
Exemple #3
0
def get_metadata_archive():
    '''
    It creates a file (ARCHIVE_NAME) with all the information
    Returns the file
    '''
    ensure_dir(TMP_DIR)
    file_list = [
        {'name': 'kanux_version.txt', 'contents': get_version()},
        {'name': 'kanux_stamp.txt', 'contents': get_stamp()},
        {'name': 'process.txt', 'contents': get_processes()},
        {'name': 'packages.txt', 'contents': get_packages()},
        {'name': 'dmesg.txt', 'contents': get_dmesg()},
        {'name': 'syslog.txt', 'contents': get_syslog()},
        {'name': 'cmdline.txt', 'contents': read_file_contents('/boot/cmdline.txt')},
        {'name': 'config.txt', 'contents': read_file_contents('/boot/config.txt')},
        {'name': 'wifi-info.txt', 'contents': get_wifi_info()},
        {'name': 'usbdevices.txt', 'contents': get_usb_devices()},

        # TODO: Remove raw logs when json ones become stable
        {'name': 'app-logs.txt', 'contents': get_app_logs_raw()},

        {'name': 'app-logs-json.txt', 'contents': get_app_logs_json()},
        {'name': 'hdmi-info.txt', 'contents': get_hdmi_info()},
        {'name': 'edid.dat', 'contents': get_edid()},
        {'name': 'screen-log.txt', 'contents': get_screen_log()},
        {'name': 'xorg-log.txt', 'contents': get_xorg_log()},
        {'name': 'cpu-info.txt', 'contents': get_cpu_info()},
        {'name': 'lsof.txt', 'contents': get_lsof()},
        {'name': 'content-objects.txt', 'contents': get_co_list()}
    ]
    # Include the screenshot if it exists
    if os.path.isfile(SCREENSHOT_PATH):
        file_list.append({
                         'name': SCREENSHOT_NAME,
                         'contents': read_file_contents(SCREENSHOT_PATH)
                         })
    # Collect all coredumps, for applications that terminated unexpectedly
    for f in os.listdir('/var/tmp/'):
        if f.startswith('core-'):
            file_list.append({
                'name': f,
                'contents': read_file_contents(os.path.join('/var/tmp', f))
            })
    # create files for each non empty metadata info
    for file in file_list:
        if file['contents']:
            write_file_contents(TMP_DIR + file['name'], file['contents'])
    # archive all the metadata files
    # need to change dir to avoid tar subdirectories
    current_directory = os.getcwd()
    os.chdir(TMP_DIR)
    run_cmd("tar -zcvf {} *".format(ARCHIVE_NAME))
    # open the file and return it
    archive = open(ARCHIVE_NAME, 'rb')
    # restore the current working directory
    os.chdir(current_directory)

    return archive
Exemple #4
0
def is_hdmi_audio_supported():
    '''
    Returns True if the display is HDMI and has audio support
    '''
    if is_hdmi_audio_supported.hdmi_supported is not None:
        return is_hdmi_audio_supported.hdmi_supported
    try:
        from kano_settings.system.display import get_edid
        is_hdmi_audio_supported.hdmi_supported = get_edid()['hdmi_audio']
    except Exception:
        is_hdmi_audio_supported.hdmi_supported = False

    return is_hdmi_audio_supported.hdmi_supported
def get_metadata_archive(title='', desc=''):
    '''
    It creates a file (ARCHIVE_NAME) with all the information
    Returns the file
    '''
    ensure_dir(TMP_DIR)
    file_list = [
        {
            'name': 'metadata.json',
            'contents': json.dumps({'title': title, 'description': desc})
        },
        {'name': 'kanux_version.txt', 'contents': get_version()},
        {'name': 'kanux_stamp.txt', 'contents': get_stamp()},
        {'name': 'process.txt', 'contents': get_processes()},
        {'name': 'process-tree.txt', 'contents': get_process_tree()},
        {'name': 'packages.txt', 'contents': get_packages()},
        {'name': 'dmesg.txt', 'contents': get_dmesg()},
        {'name': 'syslog.txt', 'contents': get_syslog()},
        {
            'name': 'cmdline.txt',
            'contents': read_file_contents('/boot/cmdline.txt')
        },
        {
            'name': 'config.txt',
            'contents': read_file_contents('/boot/config.txt')
        },
        {'name': 'wifi-info.txt', 'contents': get_wifi_info()},
        {'name': 'usbdevices.txt', 'contents': get_usb_devices()},

        # TODO: Remove raw logs when json ones become stable
        {'name': 'app-logs.txt', 'contents': get_app_logs_raw()},

        {'name': 'app-logs-json.txt', 'contents': get_app_logs_json()},
        {'name': 'hdmi-info.txt', 'contents': get_hdmi_info()},
        {'name': 'edid.dat', 'contents': get_edid()},
        {'name': 'screen-log.txt', 'contents': get_screen_log()},
        {'name': 'xorg-log.txt', 'contents': get_xorg_log()},
        {'name': 'cpu-info.txt', 'contents': get_cpu_info()},
        {'name': 'mem-stats.txt', 'contents': get_mem_stats()},
        {'name': 'lsof.txt', 'contents': get_lsof()},
        {'name': 'content-objects.txt', 'contents': get_co_list()},
        {'name': 'disk-space.txt', 'contents': get_disk_space()},
        {'name': 'lsblk.txt', 'contents': get_lsblk()},
        {'name': 'sources-list.txt', 'contents': get_sources_list()},
    ]
    file_list += get_install_logs()

    # Include the screenshot if it exists
    if os.path.isfile(SCREENSHOT_PATH):
        file_list.append({
            'name': SCREENSHOT_NAME,
            'contents': read_file_contents(SCREENSHOT_PATH)
        })
    # Collect all coredumps, for applications that terminated unexpectedly
    for f in os.listdir('/var/tmp/'):
        if f.startswith('core-'):
            file_list.append({
                'name': f,
                'contents': read_file_contents(os.path.join('/var/tmp', f))
            })
    # create files for each non empty metadata info
    for file in file_list:
        if file['contents']:
            write_file_contents(
                os.path.join(TMP_DIR, file['name']), file['contents']
            )
    # archive all the metadata files
    import tarfile
    with tarfile.open(ARCHIVE_PATH, mode='w') as archive:
        for f in os.listdir(TMP_DIR):
            archive.add(os.path.join(TMP_DIR, f), arcname=f)

    # open the file and return it
    archive = open(ARCHIVE_PATH, 'rb')

    return archive

amixer_control = "name='PCM Playback Route'"

analogue_value = 1
hdmi_value = 2
hdmi_string = ": values={}".format(hdmi_value)

store_cmd = "service alsa-utils restart"
amixer_set_cmd = "amixer -c 0 cset {control} {{value}}".format(
    control=amixer_control)
amixer_get_cmd = "amixer -c 0 cget {control}".format(control=amixer_control)

try:
    from kano_settings.system.display import get_edid
    hdmi_supported = get_edid()['hdmi_audio']
except Exception:
    hdmi_supported = False


# set_to_HDMI = True or False
def set_to_HDMI(HDMI):
    if not hdmi_supported:
        HDMI = False

    # 1 analog
    # 2 hdmi

    # These are the changes we'll apply if they have changed from what they were
    if HDMI:
        amixer_cmd = amixer_set_cmd.format(value=hdmi_value)
def get_metadata_archive(title='', desc=''):
    '''
    It creates a file (ARCHIVE_NAME) with all the information
    Returns the file
    '''
    ensure_dir(TMP_DIR)
    file_list = [
        {
            'name': 'metadata.json',
            'contents': json.dumps({
                'title': title,
                'description': desc
            })
        },
        {
            'name': 'kanux_version.txt',
            'contents': get_version()
        },
        {
            'name': 'kanux_stamp.txt',
            'contents': get_stamp()
        },
        {
            'name': 'process.txt',
            'contents': get_processes()
        },
        {
            'name': 'process-tree.txt',
            'contents': get_process_tree()
        },
        {
            'name': 'packages.txt',
            'contents': get_packages()
        },
        {
            'name': 'dmesg.txt',
            'contents': get_dmesg()
        },
        {
            'name': 'syslog.txt',
            'contents': get_syslog()
        },
        {
            'name': 'cmdline.txt',
            'contents': read_file_contents('/boot/cmdline.txt')
        },
        {
            'name': 'config.txt',
            'contents': read_file_contents('/boot/config.txt')
        },
        {
            'name': 'wifi-info.txt',
            'contents': get_wifi_info()
        },
        {
            'name': 'usbdevices.txt',
            'contents': get_usb_devices()
        },

        # TODO: Remove raw logs when json ones become stable
        {
            'name': 'app-logs.txt',
            'contents': get_app_logs_raw()
        },
        {
            'name': 'app-logs-json.txt',
            'contents': get_app_logs_json()
        },
        {
            'name': 'hdmi-info.txt',
            'contents': get_hdmi_info()
        },
        {
            'name': 'edid.dat',
            'contents': get_edid()
        },
        {
            'name': 'screen-log.txt',
            'contents': get_screen_log()
        },
        {
            'name': 'xorg-log.txt',
            'contents': get_xorg_log()
        },
        {
            'name': 'cpu-info.txt',
            'contents': get_cpu_info()
        },
        {
            'name': 'mem-stats.txt',
            'contents': get_mem_stats()
        },
        {
            'name': 'lsof.txt',
            'contents': get_lsof()
        },
        {
            'name': 'content-objects.txt',
            'contents': get_co_list()
        },
        {
            'name': 'disk-space.txt',
            'contents': get_disk_space()
        },
        {
            'name': 'lsblk.txt',
            'contents': get_lsblk()
        },
        {
            'name': 'sources-list.txt',
            'contents': get_sources_list()
        },
    ]
    file_list += get_install_logs()

    # Include the screenshot if it exists
    if os.path.isfile(SCREENSHOT_PATH):
        file_list.append({
            'name': SCREENSHOT_NAME,
            'contents': read_file_contents(SCREENSHOT_PATH)
        })
    # Collect all coredumps, for applications that terminated unexpectedly
    for f in os.listdir('/var/tmp/'):
        if f.startswith('core-'):
            file_list.append({
                'name':
                f,
                'contents':
                read_file_contents(os.path.join('/var/tmp', f))
            })
    # create files for each non empty metadata info
    for file in file_list:
        if file['contents']:
            write_file_contents(os.path.join(TMP_DIR, file['name']),
                                file['contents'])
    # archive all the metadata files
    import tarfile
    with tarfile.open(ARCHIVE_PATH, mode='w') as archive:
        for f in os.listdir(TMP_DIR):
            archive.add(os.path.join(TMP_DIR, f), arcname=f)

    # open the file and return it
    archive = open(ARCHIVE_PATH, 'rb')

    return archive