Esempio n. 1
0
def cache_files(path, widget_id):
    info_keys = utils.get_info_keys()
    params = {
        "jsonrpc": "2.0",
        "method": "Files.GetDirectory",
        "params": {
            "properties": info_keys,
            "directory": path,
        },
        "id": 1,
    }
    files = utils.call_jsonrpc(params)
    _, _, changed = cache_expiry(path, widget_id, add=files)
    return (files, changed)
Esempio n. 2
0
def clean(widget_id=None, notify=False, all=False):
    if all:
        for widget in find_defined_widgets():
            clean(widget_id=widget["id"])
        return find_defined_widgets()

    files = []
    dialog = xbmcgui.Dialog()
    skin_shortcuts = os.path.join(utils._addon_data, "script.skinshortcuts")

    params = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "Addons.GetAddons",
        "params": {"type": "xbmc.gui.skin"},
    }
    addons = json.loads(utils.call_jsonrpc(json.dumps(params)))
    if "error" not in addons:
        for addon in addons["result"]["addons"]:
            path = os.path.join(utils._addon_data, addon["addonid"], "settings.xml")
            if os.path.exists(path):
                files.append(path)
    if os.path.exists(skin_shortcuts):
        for xml in os.listdir(skin_shortcuts):
            ext = xml.split(".")
            if ext[-1] in ["xml", "properties"]:
                path = os.path.join(skin_shortcuts, xml)
                files.append(path)

    remove = []
    removed = 0

    if widget_id:
        found = False
        for file in files:
            if widget_id in utils.read_file(file):
                found = True
                utils.log("{} found in {}; not cleaning".format(widget_id, file))
                break
        if not found:
            utils.log("{} not found; cleaning".format(widget_id))
            utils.remove_file(
                os.path.join(utils._addon_path, "{}.widget".format(widget_id))
            )
            return True
        return False

    for widget in find_defined_widgets():
        found = False
        if get_group_by_id(widget["group"]):
            found = True
        else:
            for file in files:
                if widget["id"] in utils.read_file(file):
                    found = True
                    utils.log("{} found in {}; not cleaning".format(widget["id"], file))
                    break
        if not found:
            utils.log("{} not found; cleaning".format(widget["id"]))
            utils.remove_file(
                os.path.join(utils._addon_path, "{}.widget".format(widget["id"]))
            )
            removed += 1
    if notify:
        dialog.notification(
            "AutoWidget",
            utils.get_string(30106).format("No" if removed == 0 else removed),
        )
Esempio n. 3
0
def clean(widget_id=None, notify=False):
    files = []
    dialog = xbmcgui.Dialog()
    skin_shortcuts = os.path.join(utils._addon_data, 'script.skinshortcuts')

    params = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "Addons.GetAddons",
        "params": {
            "type": "xbmc.gui.skin"
        }
    }
    addons = json.loads(utils.call_jsonrpc(json.dumps(params)))
    if 'error' not in addons:
        for addon in addons['result']['addons']:
            path = os.path.join(utils._addon_data, addon['addonid'],
                                'settings.xml')
            if os.path.exists(path):
                files.append(path)
    if os.path.exists(skin_shortcuts):
        for xml in os.listdir(skin_shortcuts):
            ext = xml.split('.')
            if ext[-1] in ['xml', 'properties']:
                path = os.path.join(skin_shortcuts, xml)
                files.append(path)

    remove = []
    removed = 0

    if widget_id:
        found = False
        for file in files:
            if widget_id in utils.read_file(file):
                found = True
                utils.log('{} found in {}; not cleaning'.format(
                    widget_id, file))
                break
        if not found:
            utils.log('{} not found; cleaning'.format(widget_id))
            utils.remove_file(
                os.path.join(utils._addon_path, '{}.widget'.format(widget_id)))
            return True
        return False

    for widget in find_defined_widgets():
        found = False
        if get_group_by_id(widget['group']):
            found = True
        else:
            for file in files:
                if widget['id'] in utils.read_file(file):
                    found = True
                    utils.log('{} found in {}; not cleaning'.format(
                        widget['id'], file))
                    break
        if not found:
            utils.log('{} not found; cleaning'.format(widget['id']))
            utils.remove_file(
                os.path.join(utils._addon_path,
                             '{}.widget'.format(widget['id'])))
            removed += 1
    if notify:
        dialog.notification(
            'AutoWidget',
            utils.get_string(32132).format('No' if removed == 0 else removed))