Пример #1
0
def _convert_shortcuts(converted):
    shortcut_files = os.listdir(_shortcuts_path)
    shortcut_files = [
        x for x in shortcut_files
        if x.endswith('.DATA.xml') and 'powermenu' not in x
    ]
    for xml in shortcut_files:
        xml_path = os.path.join(_shortcuts_path, xml)
        shortcuts = utils.read_xml(xml_path)

        if shortcuts is None:
            continue

        for shortcut in shortcuts.findall('shortcut'):
            label_node = shortcut.find('label')
            action_node = shortcut.find('action')

            match = re.search(activate_window_pattern,
                              action_node.text if action_node.text else '')
            if not match:
                continue

            groups = list(match.groups())

            if not groups or len(groups) < 2:
                continue

            id_match = re.search(uuid_pattern, groups[2])
            if 'plugin.program.autowidget' in groups[2] and id_match:
                params = dict(
                    parse_qsl(groups[2].split('?')[1].replace('\"', '')))
                if not params:
                    continue

                _id = params.get('id')
                if params.get('target') == 'shortcut':
                    pass
                else:
                    label_node.text = skin_string_info_pattern.format(
                        _id, 'label')

                    groups[1], groups[2] = (skin_string_info_pattern.format(
                        _id, i) for i in ['target', 'action'])

                    action_node.text = path_replace_pattern.format(
                        groups[0], ','.join(groups[1:]))
                if _id and _id not in converted:
                    save_path_details(params)
                    if params.get('target') != 'shortcut':
                        converted.append(_id)

        utils.write_xml(xml_path, shortcuts)

    return converted
Пример #2
0
def _convert_skin_strings(converted):
    xml_path = os.path.join(_skin_path, 'settings.xml')
    settings = utils.read_xml(xml_path)

    if settings is None:
        return converted

    settings = [i for i in settings.findall('setting') if i.text]
    path_settings = [
        i for i in settings if 'plugin.program.autowidget' in i.text
        and re.search(uuid_pattern, i.text)
        and not re.match(activate_window_pattern, i.text)
    ]
    label_settings = [
        i for i in settings if 'plugin.program.autowidget' not in i.text
        and re.match(label_pattern, i.text)
    ]
    for path in path_settings:
        path_id = path.get('id')
        if not path_id:
            continue

        params = dict(parse_qsl(path.text.split('?')[1].replace('\"', '')))

        _id = params.get('id')
        if params.get('target') == 'shortcut':
            pass
        else:
            params['path_setting'] = path_id
            for label in label_settings:
                if _id in label.text:
                    params['label_setting'] = label.get('id')
                    break

        if _id and _id not in converted:
            save_path_details(params)
            if params.get('target') != 'shortcut':
                converted.append(_id)

    return converted