コード例 #1
0
def log(msg, level=xbmc.LOGNOTICE):
    if not os.path.exists(CONFIG.PLUGIN_DATA):
        os.makedirs(CONFIG.PLUGIN_DATA)
    if not os.path.exists(CONFIG.WIZLOG):
        f = open(CONFIG.WIZLOG, 'w+')
        f.close()
    if CONFIG.WIZDEBUGGING == 'false':
        return False
    if CONFIG.DEBUGLEVEL == '0':  # No Logging
        return False
    if CONFIG.DEBUGLEVEL == '1':  # Normal Logging
        if level not in [xbmc.LOGNOTICE, xbmc.LOGERROR, xbmc.LOGSEVERE, xbmc.LOGFATAL]:
            return False
    if CONFIG.DEBUGLEVEL == '2':  # Full Logging
        level = xbmc.LOGNOTICE
    try:
        xbmc.log('{0}: {1}'.format(CONFIG.ADDONTITLE, msg), level)
    except Exception as e:
        try:
            xbmc.log('Logging Failure: {0}'.format(e), level)
        except:
            pass
    if CONFIG.ENABLEWIZLOG == 'true':
        import time

        lastcheck = CONFIG.NEXTCLEANDATE if not CONFIG.NEXTCLEANDATE == 0 else tools.get_date()
        if CONFIG.CLEANWIZLOG == 'true' and time.mktime(time.strptime(lastcheck, "%Y-%m-%d %H:%M:%S")) <= tools.get_date():
            check_log()

        line = "[{0}] {1}".format(tools.get_date(formatted=True), msg)
        line = line.rstrip('\r\n') + '\n'
        tools.write_to_file(CONFIG.WIZLOG, line, mode='a')
コード例 #2
0
def log(msg, level=xbmc.LOGNOTICE):
    from resources.libs.common import tools

    if not os.path.exists(CONFIG.PLUGIN_DATA):
        os.makedirs(CONFIG.PLUGIN_DATA)
    if not os.path.exists(CONFIG.WIZLOG):
        f = open(CONFIG.WIZLOG, 'w+')
        f.close()
    if CONFIG.WIZDEBUGGING == 'false':
        return False
    if CONFIG.DEBUGLEVEL == '0':  # No Logging
        return False
    if CONFIG.DEBUGLEVEL == '1':  # Normal Logging
        if level not in [xbmc.LOGNOTICE, xbmc.LOGERROR, xbmc.LOGSEVERE, xbmc.LOGFATAL]:
            return False
    if CONFIG.DEBUGLEVEL == '2':  # Full Logging
        level = xbmc.LOGNOTICE
    try:
        xbmc.log('{0}: {1}'.format(CONFIG.ADDONTITLE, msg), level)
    except Exception as e:
        try:
            xbmc.log('Logging Failure: {0}'.format(e), level)
        except:
            pass
    if CONFIG.ENABLEWIZLOG == 'true':
        lastcheck = CONFIG.NEXTCLEANDATE if not CONFIG.NEXTCLEANDATE == '' else str(tools.get_date())
        if CONFIG.CLEANWIZLOG == 'true' and lastcheck <= str(tools.get_date()):
            check_log()

        line = "[{0} {1}] {2}".format(tools.get_date(now=True).date(),
                                      str(tools.get_date(now=True).time())[:8],
                                      msg)
        line = line.rstrip('\r\n') + '\n'
        tools.write_to_file(CONFIG.WIZLOG, line, mode='a')
コード例 #3
0
def unhide_password():
    from resources.libs.common import tools
    from resources.libs.common import logging
    
    dialog = xbmcgui.Dialog()

    if dialog.yesno(CONFIG.ADDONTITLE,
                        "[COLOR {0}]Would you like to [COLOR {1}]unhide[/COLOR] all passwords when typing in the add-on settings menus?[/COLOR]".format(CONFIG.COLOR2, CONFIG.COLOR1),
                        yeslabel="[B][COLOR springgreen]Unhide Passwords[/COLOR][/B]",
                        nolabel="[B][COLOR red]No Cancel[/COLOR][/B]"):
        count = 0
        for folder in glob.glob(os.path.join(CONFIG.ADDONS, '*/')):
            sett = os.path.join(folder, 'resources', 'settings.xml')
            if os.path.exists(sett):
                f = tools.read_from_file(sett)
                match = tools.parse_dom(f, 'addon', ret='id')
                for line in match:
                    if 'pass' in line:
                        if 'option="hidden"' in line:
                            try:
                                change = line.replace('option="hidden"', '')
                                f.replace(line, change)
                                count += 1
                                logging.log("[Unhide Passwords] found in {0} on {1}".format(sett.replace(CONFIG.HOME, ''), line))
                            except:
                                pass
                tools.write_to_file(sett, f)
        logging.log_notify("[COLOR {0}]Unhide Passwords[/COLOR]".format(CONFIG.COLOR1),
                           "[COLOR {0}]{1} items changed[/COLOR]".format(CONFIG.COLOR2, count))
        logging.log("[Unhide Passwords] {0} items changed".format(count))
    else:
        logging.log("[Unhide Passwords] Cancelled")
コード例 #4
0
    def write_advanced(self, name, url):
        response = tools.open_url(url)

        if response:
            if os.path.exists(CONFIG.ADVANCED):
                choice = self.dialog.yesno(CONFIG.ADDONTITLE,
                                           "[COLOR {0}]Você gostaria de substituir suas configurações avançadas atuais com [COLOR {1}]{2}[/COLOR]?[/COLOR]".format(
                                               CONFIG.COLOR2, CONFIG.COLOR1, name),
                                           yeslabel="[B][COLOR springgreen]Sobrescrever[/COLOR][/B]",
                                           nolabel="[B][COLOR red]Cancelar[/COLOR][/B]")
            else:
                choice = self.dialog.yesno(CONFIG.ADDONTITLE,
                                           "[COLOR {0}]Você gostaria de baixar e instalar[COLOR {1}]{2}[/COLOR]?[/COLOR]".format(
                                               CONFIG.COLOR2, CONFIG.COLOR1, name),
                                           yeslabel="[B][COLOR springgreen]Instalar[/COLOR][/B]",
                                           nolabel="[B][COLOR red]Cancelar[/COLOR][/B]")

            if choice == 1:
                tools.write_to_file(CONFIG.ADVANCED, response.text)
                tools.kill_kodi(msg='[COLOR {0}]Instalar A nova predefinição advancedsettings.xml foi escrita com sucesso, mas as alterações não terão efeito até que você feche o Kodi.[/COLOR]'.format(
                                   CONFIG.COLOR2))
            else:
                logging.log("[Configurações avançadas] instalação cancelada")
                logging.log_notify('[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE),
                                   "[COLOR {0}]Escrita cancelada![/COLOR]".format(CONFIG.COLOR2))
                return
        else:
            logging.log("[Configurações avançadas] URL não funciona: {0}".format(url))
            logging.log_notify('[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE),
                               "[COLOR {0}]URL não funcionaF[/COLOR]".format(CONFIG.COLOR2))
コード例 #5
0
def create_temp(plugin):
    from resources.libs.common import tools

    temp = os.path.join(CONFIG.PLUGIN, 'resources', 'tempaddon.xml')
    r = tools.read_from_file(temp)
    plugdir = os.path.join(CONFIG.ADDONS, plugin)
    if not os.path.exists(plugdir):
        os.makedirs(plugdir)

    tools.write_to_file(os.path.join(plugdir, 'addon.xml'), r.replace('testid', plugin).replace('testversion', '0.0.1'))
    logging.log("{0}: wrote addon.xml".format(plugin))
コード例 #6
0
    def write_advanced(self, name, url):
        response = tools.open_url(url)

        if response:
            if os.path.exists(CONFIG.ADVANCED):
                choice = self.dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Bạn có muốn ghi đè file [COLOR {1}]AdvancedSettings.xml[/COLOR] hiện có?[/COLOR]"
                    .format(CONFIG.COLOR2, CONFIG.COLOR1),
                    yeslabel="[B][COLOR springgreen]Overwrite[/COLOR][/B]",
                    nolabel="[B][COLOR red]Cancel[/COLOR][/B]")
            else:
                choice = self.dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Bạn đã đồng ý ghi đè file [COLOR {1}]AdvancedSettings.xml[/COLOR] \nNhấn [COLOR springgreen]Install[/COLOR] để xác nhận."
                    .format(CONFIG.COLOR2, CONFIG.COLOR1),
                    yeslabel="[B][COLOR springgreen]Install[/COLOR][/B]",
                    nolabel="[B][COLOR red]Cancel[/COLOR][/B]")

            if choice == 1:
                tools.write_to_file(CONFIG.ADVANCED, response.text)
                self.dialog.ok(
                    CONFIG.ADDONTITLE,
                    'Memcache sẽ được lấy tự động dựa vào dung lượng ram trống hiện có.'
                )
                category = 'cache'
                tag = 'memorysize'
                value = None
                self.set_setting(category, tag, value)
                tools.kill_kodi(
                    msg=
                    '[COLOR {0}]File AdvancedSettings.xml đã được thiết lập, bạn cần Restart Kodi để có hiệu lực.[/COLOR]'
                    .format(CONFIG.COLOR2))
            else:
                logging.log("[Advanced Settings] install canceled")
                logging.log_notify(
                    '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1,
                                                    CONFIG.ADDONTITLE),
                    "[COLOR {0}]Write Cancelled![/COLOR]".format(
                        CONFIG.COLOR2))
                return
        else:
            logging.log("[Advanced Settings] URL not working: {0}".format(url))
            logging.log_notify(
                '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1,
                                                CONFIG.ADDONTITLE),
                "[COLOR {0}]URL Not Working[/COLOR]".format(CONFIG.COLOR2))
コード例 #7
0
def write_advanced(name, url):
    from resources.libs.common import tools
    from resources.libs.common import logging

    dialog = xbmcgui.Dialog()

    response = tools.open_url(url)

    if response:
        if os.path.exists(CONFIG.ADVANCED):
            choice = dialog.yesno(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Would you like to overwrite your current Advanced Settings with [COLOR {1}]{}[/COLOR]?[/COLOR]"
                .format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                yeslabel="[B][COLOR springgreen]Overwrite[/COLOR][/B]",
                nolabel="[B][COLOR red]Cancel[/COLOR][/B]")
        else:
            choice = dialog.yesno(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Would you like to download and install [COLOR {1}]{2}[/COLOR]?[/COLOR]"
                .format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                yeslabel="[B][COLOR springgreen]Install[/COLOR][/B]",
                nolabel="[B][COLOR red]Cancel[/COLOR][/B]")

        if choice == 1:
            tools.write_to_file(CONFIG.ADVANCED, response.text)
            dialog.ok(
                CONFIG.ADDONTITLE,
                '[COLOR {0}]AdvancedSettings.xml file has been successfully written. Once you click okay it will force close kodi.[/COLOR]'
                .format(CONFIG.COLOR2))
            tools.kill_kodi(over=True)
        else:
            logging.log("[Advanced Settings] install canceled")
            logging.log_notify(
                '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1,
                                                CONFIG.ADDONTITLE),
                "[COLOR {0}]Write Cancelled![/COLOR]".format(CONFIG.COLOR2))
            return
    else:
        logging.log("[Advanced Settings] URL not working: {0}".format(url))
        logging.log_notify(
            '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1, CONFIG.ADDONTITLE),
            "[COLOR {0}]URL Not Working[/COLOR]".format(CONFIG.COLOR2))
コード例 #8
0
def log(msg, level=xbmc.LOGDEBUG):
    if CONFIG.DEBUGLEVEL == '0':  # No Logging
        return False
    if CONFIG.DEBUGLEVEL == '1':  # Normal Logging
        pass
    if CONFIG.DEBUGLEVEL == '2':  # Full Logging
        level = xbmc.LOGNOTICE
    
    xbmc.log('{0}: {1}'.format(CONFIG.ADDONTITLE, msg), level)
    if CONFIG.ENABLEWIZLOG == 'true':
        if not os.path.exists(CONFIG.WIZLOG):
            with open(CONFIG.WIZLOG, 'w+') as f:
                f.close()

        lastcheck = CONFIG.NEXTCLEANDATE if not CONFIG.NEXTCLEANDATE == 0 else tools.get_date()
        if CONFIG.CLEANWIZLOG == 'true' and time.mktime(time.strptime(lastcheck, "%Y-%m-%d %H:%M:%S")) <= tools.get_date():
            check_log()

        line = "[{0}] {1}".format(tools.get_date(formatted=True), msg)
        line = line.rstrip('\r\n') + '\n'
        tools.write_to_file(CONFIG.WIZLOG, line, mode='a')
コード例 #9
0
def check_log():
    from resources.libs.common import tools

    next = tools.get_date(days=1)
    lines = tools.read_from_file(CONFIG.WIZLOG).split('\n')

    if CONFIG.CLEANWIZLOGBY == '0':  # By Days
        keep = tools.get_date(days=-CONFIG.MAXWIZDATES[int(float(CONFIG.CLEANDAYS))])
        x = 0
        for line in lines:
            if str(line[1:11]) >= str(keep):
                break
            x += 1
        newfile = lines[x:]
        tools.write_to_file(CONFIG.WIZLOG, '\n'.join(newfile))
    elif CONFIG.CLEANWIZLOGBY == '1':  # By Size
        maxsize = CONFIG.MAXWIZSIZE[int(float(CONFIG.CLEANSIZE))]*1024
        if os.path.getsize(CONFIG.WIZLOG) >= maxsize:
            start = len(lines)/2
            newfile = lines[start:]
            tools.write_to_file(CONFIG.WIZLOG, '\n'.join(newfile))
    elif CONFIG.CLEANWIZLOGBY == '2':  # By Lines
        maxlines = CONFIG.MAXWIZLINES[int(float(CONFIG.CLEANLINES))]
        if len(lines) > maxlines:
            start = len(lines) - int(maxlines/2)
            newfile = lines[start:]
            tools.write_to_file(CONFIG.WIZLOG, '\n'.join(newfile))
    CONFIG.set_setting('nextcleandate', str(next))
コード例 #10
0
    def write_advanced(self, name, url):
        response = tools.open_url(url)

        if response:
            if os.path.exists(CONFIG.ADVANCED):
                choice = self.dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Le gustaría sobrescribir su Advanced Settings actual [COLOR {1}]{2}[/COLOR]?[/COLOR]"
                    .format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                    yeslabel="[B][COLOR springgreen]Sobrescribir[/COLOR][/B]",
                    nolabel="[B][COLOR red]Cancelar[/COLOR][/B]")
            else:
                choice = self.dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Le gustaría descargar e instalar [COLOR {1}]{2}[/COLOR]?[/COLOR]"
                    .format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                    yeslabel="[B][COLOR springgreen]Instalar[/COLOR][/B]",
                    nolabel="[B][COLOR red]Cancelar[/COLOR][/B]")

            if choice == 1:
                tools.write_to_file(CONFIG.ADVANCED, response.text)
                tools.kill_kodi(
                    msg=
                    '[COLOR {0}]El nuevo ajuste preestablecido advancedsettings.xml se ha escrito correctamente, pero los cambios no surtirán efecto hasta que cierre Kodi.[/COLOR]'
                    .format(CONFIG.COLOR2))
            else:
                logging.log("[Advanced Settings] instalación canceleda")
                logging.log_notify(
                    '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1,
                                                    CONFIG.ADDONTITLE),
                    "[COLOR {0}]Escritura Canceleda![/COLOR]".format(
                        CONFIG.COLOR2))
                return
        else:
            logging.log("[Advanced Settings] URL no funciona: {0}".format(url))
            logging.log_notify(
                '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1,
                                                CONFIG.ADDONTITLE),
                "[COLOR {0}]URL No Funciona[/COLOR]".format(CONFIG.COLOR2))
コード例 #11
0
ファイル: advanced.py プロジェクト: newf276/repository.newf
    def write_advanced(self, name, url):
        response = tools.open_url(url)

        if response:
            if os.path.exists(CONFIG.ADVANCED):
                choice = self.dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Would you like to overwrite your current Advanced Settings with [COLOR {1}]{2}[/COLOR]?[/COLOR]"
                    .format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                    yeslabel="[B][COLOR deepskyblue]Overwrite[/COLOR][/B]",
                    nolabel="[B][COLOR red]Cancel[/COLOR][/B]")
            else:
                choice = self.dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Would you like to download and install [COLOR {1}]{2}[/COLOR]?[/COLOR]"
                    .format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                    yeslabel="[B][COLOR deepskyblue]Install[/COLOR][/B]",
                    nolabel="[B][COLOR red]Cancel[/COLOR][/B]")

            if choice == 1:
                tools.write_to_file(CONFIG.ADVANCED, response.text)
                tools.kill_kodi(
                    msg=
                    '[COLOR {0}]The new advancedsettings.xml preset has been successfully written, but changes won\'t take effect until you close Kodi.[/COLOR]'
                    .format(CONFIG.COLOR2))
            else:
                logging.log("[Advanced Settings] install canceled")
                logging.log_notify(
                    '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1,
                                                    CONFIG.ADDONTITLE),
                    "[COLOR {0}]Write Cancelled![/COLOR]".format(
                        CONFIG.COLOR2))
                return
        else:
            logging.log("[Advanced Settings] URL not working: {0}".format(url))
            logging.log_notify(
                '[COLOR {0}]{1}[/COLOR]'.format(CONFIG.COLOR1,
                                                CONFIG.ADDONTITLE),
                "[COLOR {0}]URL Not Working[/COLOR]".format(CONFIG.COLOR2))
コード例 #12
0
def check_sources():
    from resources.libs.common import logging
    from resources.libs.common import tools

    dialog = xbmcgui.Dialog()
    progress_dialog = xbmcgui.DialogProgress()

    if not os.path.exists(CONFIG.SOURCES):
        logging.log_notify(
            CONFIG.ADDONTITLE,
            "[COLOR {0}]No sources.xml File Found![/COLOR]".format(
                CONFIG.COLOR2))
        return False
    x = 0
    bad = []
    remove = []
    a = tools.read_from_file(CONFIG.SOURCES)
    temp = a.replace('\r', '').replace('\n', '').replace('\t', '')
    match = re.compile('<files>.+?</files>').findall(temp)

    if len(match) > 0:
        match2 = re.compile(
            '<source>.+?<name>(.+?)</name>.+?<path pathversion="1">(.+?)</path>.+?<allowsharing>(.+?)</allowsharing>.+?</source>'
        ).findall(match[0])
        progress_dialog.create(
            CONFIG.ADDONTITLE,
            "[COLOR {0}]Scanning Sources for Broken links[/COLOR]".format(
                CONFIG.COLOR2))
        for name, path, sharing in match2:
            x += 1
            perc = int(tools.percentage(x, len(match2)))
            progress_dialog.update(
                perc, '',
                "[COLOR {0}]Checking [COLOR {1}]{2}[/COLOR]:[/COLOR]".format(
                    CONFIG.COLOR2, CONFIG.COLOR1, name),
                "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, path))

            working = tools.open_url(path, check=True)
            if not working:
                bad.append([name, path, sharing, working])

        logging.log("Bad Sources: {0}".format(len(bad)))
        if len(bad) > 0:
            choice = dialog.yesno(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]{1}[/COLOR][COLOR {2}] Source(s) have been found Broken"
                .format(CONFIG.COLOR1, len(bad), CONFIG.COLOR2),
                "Would you like to Remove all or choose one by one?[/COLOR]",
                yeslabel="[B][COLOR springgreen]Remove All[/COLOR][/B]",
                nolabel="[B][COLOR red]Choose to Delete[/COLOR][/B]")
            if choice == 1:
                remove = bad
            else:
                for name, path, sharing, working in bad:
                    logging.log("{0} sources: {1}, {2}".format(
                        name, path, working))
                    if dialog.yesno(
                            CONFIG.ADDONTITLE,
                            "[COLOR {0}]{1}[/COLOR][COLOR {2}] was reported as non working"
                            .format(CONFIG.COLOR1, name, CONFIG.COLOR2),
                            "[COLOR {0}]{1}[/COLOR]".format(
                                CONFIG.COLOR1, path),
                            "[COLOR {0}]{1}[/COLOR]".format(
                                CONFIG.COLOR1, working),
                            yeslabel=
                            "[B][COLOR springgreen]Remove Source[/COLOR][/B]",
                            nolabel="[B][COLOR red]Keep Source[/COLOR][/B]"):
                        remove.append([name, path, sharing, working])
                        logging.log("Removing Source {0}".format(name))
                    else:
                        logging.log("Source {0} was not removed".format(name))
            if len(remove) > 0:
                for name, path, sharing, working in remove:
                    a = a.replace(
                        '\n<source>\n<name>{0}</name>\n<path pathversion="1">{1}</path>\n<allowsharing>{2}</allowsharing>\n</source>'
                        .format(name, path, sharing), '')
                    logging.log("Removing Source {0}".format(name))

                tools.write_to_file(CONFIG.SOURCES, str(a))
                alive = len(match) - len(bad)
                kept = len(bad) - len(remove)
                removed = len(remove)
                dialog.ok(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Checking sources for broken paths has been completed"
                    .format(CONFIG.COLOR2),
                    "Working: [COLOR {0}]{1}[/COLOR] | Kept: [COLOR {2}]{3}[/COLOR] | Removed: [COLOR {4}]{5}[/COLOR][/COLOR]"
                    .format(CONFIG.COLOR2, CONFIG.COLOR1, alive, CONFIG.COLOR1,
                            kept, CONFIG.COLOR1, removed))
            else:
                logging.log("No Bad Sources to be removed.")
        else:
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]All Sources Are Working[/COLOR]".format(
                    CONFIG.COLOR2))
    else:
        logging.log("No Sources Found")
コード例 #13
0
def whitelist(do):
    addonnames = []
    addonids = []
    addonfolds = []

    dialog = xbmcgui.Dialog()
    
    if do == 'edit':
        fold = glob.glob(os.path.join(CONFIG.ADDONS, '*/'))
        for folder in sorted(fold, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername in CONFIG.EXCLUDES:
                continue
            elif foldername in CONFIG.DEFAULTPLUGINS:
                continue
            elif foldername == 'packages':
                continue
            xml = os.path.join(folder, 'addon.xml')
            if os.path.exists(xml):
                a = tools.read_from_file(xml)
                temp, addid = parse(a, foldername)
                addonnames.append(temp)
                addonids.append(addid)
                addonfolds.append(foldername)
        fold2 = glob.glob(os.path.join(CONFIG.ADDON_DATA, '*/'))
        for folder in sorted(fold2, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername in addonfolds:
                continue
            if foldername in CONFIG.EXCLUDES:
                continue
            xml = os.path.join(CONFIG.ADDONS, foldername, 'addon.xml')
            xml2 = os.path.join(CONFIG.XBMC, 'addons', foldername, 'addon.xml')
            if os.path.exists(xml):
                a = tools.read_from_file(xml)
            elif os.path.exists(xml2):
                a = tools.read_from_file(xml2)
            else:
                continue
            temp, addid = parse(a, foldername)
            addonnames.append(temp)
            addonids.append(addid)
            addonfolds.append(foldername)
        selected = []
        tempaddonnames = ["-- Click here to Continue --"] + addonnames
        currentWhite = whitelist(do='read')
        for item in currentWhite:
            logging.log(str(item))
            try:
                name, id, fold = item
            except Exception as e:
                logging.log(str(e))
            if id in addonids:
                pos = addonids.index(id)+1
                selected.append(pos-1)
                tempaddonnames[pos] = "[B][COLOR {0}]{1}[/COLOR][/B]".format(CONFIG.COLOR1, name)
            else:
                addonids.append(id)
                addonnames.append(name)
                tempaddonnames.append("[B][COLOR {0}]{1}[/COLOR][/B]".format(CONFIG.COLOR1, name))
        choice = 1
        while choice not in [-1, 0]:
            choice = dialog.select("{0}: Select the add-ons you wish to the whitelist.".format(CONFIG.ADDONTITLE), tempaddonnames)
            if choice == -1:
                break
            elif choice == 0:
                break
            else:
                choice2 = (choice-1)
                if choice2 in selected:
                    selected.remove(choice2)
                    tempaddonnames[choice] = addonnames[choice2]
                else:
                    selected.append(choice2)
                    tempaddonnames[choice] = "[B][COLOR {0}]{1}[/COLOR][/B]".format(CONFIG.COLOR1, addonnames[choice2])
        white_list = []
        if len(selected) > 0:
            for addon in selected:
                white_list.append("['%s', '%s', '%s']" % (addonnames[addon], addonids[addon], addonfolds[addon]))
            writing = '\n'.join(white_list)
            tools.write_to_file(CONFIG.WHITELIST, writing)
        else:
            try:
                os.remove(CONFIG.WHITELIST)
            except:
                pass
        logging.log_notify(CONFIG.ADDONTITLE,
                           "[COLOR {0}]{1} Add-ons in whitelist[/COLOR]".format(CONFIG.COLOR2, len(selected)))
    elif do == 'read':
        white_list = []
        if os.path.exists(CONFIG.WHITELIST):
            lines = tools.read_from_file(CONFIG.WHITELIST).split('\n')
            for item in lines:
                try:
                    name, id, fold = eval(item)
                    white_list.append(eval(item))
                except:
                    pass
        return white_list
    elif do == 'view':
        list = whitelist(do='read')
        if len(list) > 0:
            msg = "Here is a list of your whitelist items, these items(along with dependencies) will not be removed when preforming a fresh start or the userdata overwritten in a build install.[CR][CR]"
            for item in list:
                try:
                    name, id, fold = item
                except Exception as e:
                    logging.log(str(e))
                msg += "[COLOR {0}]{1}[/COLOR] [COLOR {2}]\"{3}\"[/COLOR][CR]".format(CONFIG.COLOR1, name, CONFIG.COLOR2, id)
            window.show_text_box("Viewing Whitelisted Items", msg)
        else:
            logging.log_notify(CONFIG.ADDONTITLE,
                               "[COLOR {0}]No items in whitelist[/COLOR]".format(CONFIG.COLOR2))
    elif do == 'import':
        source = dialog.browse(1, '[COLOR {0}]Select the whitelist file to import[/COLOR]'.format(CONFIG.COLOR2),
                                   'files', '.txt', False, False, CONFIG.HOME)
        logging.log(str(source))
        if not source.endswith('.txt'):
            logging.log_notify(CONFIG.ADDONTITLE,
                               "[COLOR {0}]Import Cancelled![/COLOR]".format(CONFIG.COLOR2))
            return
        current = whitelist(do='read')
        idList = []
        count = 0
        for item in current:
            name, id, fold = item
            idList.append(id)
        lines = tools.read_from_file(xbmcvfs.File(source)).split('\n')
        with open(CONFIG.WHITELIST, 'a') as f:
            for item in lines:
                try:
                    name, id, folder = eval(item)
                except Exception as e:
                    logging.log("Error Adding: '{0}' / {1}".format(item, str(e)), level=xbmc.LOGERROR)
                    continue
                logging.log("{0} / {1} / {2}".format(name, id, folder))
                if id not in idList:
                    count += 1
                    writing = "['{0}', '{1}', '{2}']".format(name, id, folder)
                    if len(idList) + count > 1:
                        writing = "\n%s" % writing
                    f.write(writing)
            logging.log_notify(CONFIG.ADDONTITLE,
                               "[COLOR {0}]{1} Item(s) Added[/COLOR]".format(CONFIG.COLOR2, count))
    elif do == 'export':
        source = dialog.browse(3,
                                   '[COLOR {0}]Select where you wish to export the whitelist file[/COLOR]'.format(CONFIG.COLOR2),
                                   'files', '.txt', False, False, CONFIG.HOME)
        logging.log(str(source))
        try:
            xbmcvfs.copy(CONFIG.WHITELIST, os.path.join(source, 'whitelist.txt'))
            dialog.ok(CONFIG.ADDONTITLE,
                          "[COLOR {0}]Whitelist has been exported to:[/COLOR]".format(CONFIG.COLOR2)
                          +'\n'+"[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, os.path.join(source, 'whitelist.txt')))
            logging.log_notify(CONFIG.ADDONTITLE,
                               "[COLOR {0}]Whitelist Exported[/COLOR]".format(CONFIG.COLOR2))
        except Exception as e:
            logging.log("Export Error: {0}".format(str(e)), level=xbmc.LOGERROR)
            if not dialog.yesno(CONFIG.ADDONTITLE,
                                    "[COLOR {0}]The location you selected isn\'t writable would you like to select another one?[/COLOR]".format(CONFIG.COLOR2),
                                    yeslabel="[B][COLOR springgreen]Change Location[/COLOR][/B]",
                                    nolabel="[B][COLOR red]No Cancel[/COLOR][/B]"):
                logging.log_notify(CONFIG.ADDONTITLE,
                                   "[COLOR {0}]Whitelist Export Cancelled[/COLOR]".format(CONFIG.COLOR2, e))
            else:
                whitelist(do='export')
    elif do == 'clear':
        if not dialog.yesno(CONFIG.ADDONTITLE,
                                "[COLOR {0}]Are you sure you want to clear your whitelist?".format(CONFIG.COLOR2)
                                +'\n'+"This process can't be undone.[/COLOR]",
                                yeslabel="[B][COLOR springgreen]Yes Remove[/COLOR][/B]",
                                nolabel="[B][COLOR red]No Cancel[/COLOR][/B]"):
            logging.log_notify(CONFIG.ADDONTITLE,
                               "[COLOR {0}]Clear Whitelist Cancelled[/COLOR]".format(CONFIG.COLOR2))
            return
        try:
            os.remove(CONFIG.WHITELIST)
            logging.log_notify(CONFIG.ADDONTITLE,
                               "[COLOR {0}]Whitelist Cleared[/COLOR]".format(CONFIG.COLOR2))
        except:
            logging.log_notify(CONFIG.ADDONTITLE,
                               "[COLOR {0}]Error Clearing Whitelist![/COLOR]".format(CONFIG.COLOR2))
コード例 #14
0
def whitelist(do):
    addonnames = []
    addonids = []
    addonfolds = []

    dialog = xbmcgui.Dialog()

    if do == 'edit':
        fold = glob.glob(os.path.join(CONFIG.ADDONS, '*/'))
        for folder in sorted(fold, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername in CONFIG.EXCLUDES:
                continue
            elif foldername in CONFIG.DEFAULTPLUGINS:
                continue
            elif foldername == 'packages':
                continue
            xml = os.path.join(folder, 'addon.xml')
            if os.path.exists(xml):
                a = tools.read_from_file(xml)
                temp, addid = parse(a, foldername)
                addonnames.append(temp)
                addonids.append(addid)
                addonfolds.append(foldername)
        fold2 = glob.glob(os.path.join(CONFIG.ADDON_DATA, '*/'))
        for folder in sorted(fold2, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername in addonfolds:
                continue
            if foldername in CONFIG.EXCLUDES:
                continue
            xml = os.path.join(CONFIG.ADDONS, foldername, 'addon.xml')
            xml2 = os.path.join(CONFIG.XBMC, 'addons', foldername, 'addon.xml')
            if os.path.exists(xml):
                a = tools.read_from_file(xml)
            elif os.path.exists(xml2):
                a = tools.read_from_file(xml2)
            else:
                continue
            temp, addid = parse(a, foldername)
            addonnames.append(temp)
            addonids.append(addid)
            addonfolds.append(foldername)
        selected = []
        tempaddonnames = ["-- Clic aquí para Continuar --"] + addonnames
        currentWhite = whitelist(do='read')
        for item in currentWhite:
            logging.log(str(item))
            try:
                name, id, fold = item
            except Exception as e:
                logging.log(str(e))
            if id in addonids:
                pos = addonids.index(id) + 1
                selected.append(pos - 1)
                tempaddonnames[pos] = "[B][COLOR {0}]{1}[/COLOR][/B]".format(
                    CONFIG.COLOR1, name)
            else:
                addonids.append(id)
                addonnames.append(name)
                tempaddonnames.append("[B][COLOR {0}]{1}[/COLOR][/B]".format(
                    CONFIG.COLOR1, name))
        choice = 1
        while choice not in [-1, 0]:
            choice = dialog.select(
                "{0}: Seleccione los add-ons que desea incluir en la Lista Blanca."
                .format(CONFIG.ADDONTITLE), tempaddonnames)
            if choice == -1:
                break
            elif choice == 0:
                break
            else:
                choice2 = (choice - 1)
                if choice2 in selected:
                    selected.remove(choice2)
                    tempaddonnames[choice] = addonnames[choice2]
                else:
                    selected.append(choice2)
                    tempaddonnames[
                        choice] = "[B][COLOR {0}]{1}[/COLOR][/B]".format(
                            CONFIG.COLOR1, addonnames[choice2])
        white_list = []
        if len(selected) > 0:
            for addon in selected:
                white_list.append(
                    "['%s', '%s', '%s']" %
                    (addonnames[addon], addonids[addon], addonfolds[addon]))
            writing = '\n'.join(white_list)
            tools.write_to_file(CONFIG.WHITELIST, writing)
        else:
            try:
                os.remove(CONFIG.WHITELIST)
            except:
                pass
        logging.log_notify(
            CONFIG.ADDONTITLE,
            "[COLOR {0}]{1} Add-ons en la Lista Blanca[/COLOR]".format(
                CONFIG.COLOR2, len(selected)))
    elif do == 'read':
        white_list = []
        if os.path.exists(CONFIG.WHITELIST):
            lines = tools.read_from_file(CONFIG.WHITELIST).split('\n')
            for item in lines:
                try:
                    name, id, fold = eval(item)
                    white_list.append(eval(item))
                except:
                    pass
        return white_list
    elif do == 'view':
        list = whitelist(do='read')
        if len(list) > 0:
            msg = "Aquí hay una lista de los add-ons de su Lista Blanca, estos add-ons (junto con las dependencias) no se eliminarán cuando se realice un nuevo comienzo o los datos de usuario se sobrescriban en la instalación de una nueva Build.[CR][CR]"
            for item in list:
                try:
                    name, id, fold = item
                except Exception as e:
                    logging.log(str(e))
                msg += "[COLOR {0}]{1}[/COLOR] [COLOR {2}]\"{3}\"[/COLOR][CR]".format(
                    CONFIG.COLOR1, name, CONFIG.COLOR2, id)
            window.show_text_box("Visualización de add-ons de la Lista Blanca",
                                 msg)
        else:
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]No hay add-ons en la Lista Blanca[/COLOR]".format(
                    CONFIG.COLOR2))
    elif do == 'import':
        source = dialog.browse(
            1,
            '[COLOR {0}]Seleccione el archivo de la Lista Blanca para importar[/COLOR]'
            .format(CONFIG.COLOR2), 'files', '.txt', False, False, CONFIG.HOME)
        logging.log(str(source))
        if not source.endswith('.txt'):
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Importación Cancelada![/COLOR]".format(
                    CONFIG.COLOR2))
            return
        current = whitelist(do='read')
        idList = []
        count = 0
        for item in current:
            name, id, fold = item
            idList.append(id)
        lines = tools.read_from_file(xbmcvfs.File(source)).split('\n')
        with open(CONFIG.WHITELIST, 'a') as f:
            for item in lines:
                try:
                    name, id, folder = eval(item)
                except Exception as e:
                    logging.log("Error al Agregar: '{0}' / {1}".format(
                        item, str(e)),
                                level=xbmc.LOGERROR)
                    continue
                logging.log("{0} / {1} / {2}".format(name, id, folder))
                if id not in idList:
                    count += 1
                    writing = "['{0}', '{1}', '{2}']".format(name, id, folder)
                    if len(idList) + count > 1:
                        writing = "\n%s" % writing
                    f.write(writing)
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]{1} Elemento(s) Agregado[/COLOR]".format(
                    CONFIG.COLOR2, count))
    elif do == 'export':
        source = dialog.browse(
            3,
            '[COLOR {0}]Seleccione donde desea exportar el archivo de la Lista Blanca[/COLOR]'
            .format(CONFIG.COLOR2), 'files', '.txt', False, False, CONFIG.HOME)
        logging.log(str(source))
        try:
            xbmcvfs.copy(CONFIG.WHITELIST,
                         os.path.join(source, 'whitelist.txt'))
            dialog.ok(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]La Lista Blanca ha sido exportada a:[/COLOR]".
                format(CONFIG.COLOR2) + '\n' + "[COLOR {0}]{1}[/COLOR]".format(
                    CONFIG.COLOR1, os.path.join(source, 'whitelist.txt')))
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Lista Blanca Exportada[/COLOR]".format(
                    CONFIG.COLOR2))
        except Exception as e:
            logging.log("Error de Exportación: {0}".format(str(e)),
                        level=xbmc.LOGERROR)
            if not dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]La ubicación que seleccionó no se puede escribir. Le gustaría seleccionar otra?[/COLOR]"
                    .format(CONFIG.COLOR2),
                    yeslabel="[B][COLOR cyan]Cambiar Ubicación[/COLOR][/B]",
                    nolabel="[B][COLOR red]No, Cancelar[/COLOR][/B]"):
                logging.log_notify(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Cancelada la Exportación de la Lista Blanca  [/COLOR]"
                    .format(CONFIG.COLOR2, e))
            else:
                whitelist(do='export')
    elif do == 'clear':
        if not dialog.yesno(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Estás seguro de que quieres vaciar tu whitelist?".
                format(CONFIG.COLOR2) + '\n' +
                "Este proceso no se puede deshacer.[/COLOR]",
                yeslabel="[B][COLOR springgreen]Si, Eliminar[/COLOR][/B]",
                nolabel="[B][COLOR red]No, Cancelar[/COLOR][/B]"):
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Cancelado el borrado de la Lista Blanca[/COLOR]".
                format(CONFIG.COLOR2))
            return
        try:
            os.remove(CONFIG.WHITELIST)
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Lista Blanca Vaciada[/COLOR]".format(
                    CONFIG.COLOR2))
        except:
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Error Vaciando Lista Blanca![/COLOR]".format(
                    CONFIG.COLOR2))
コード例 #15
0
def whitelist(do):
    addonnames = []
    addonids = []
    addonfolds = []

    dialog = xbmcgui.Dialog()

    if do == 'edit':
        fold = glob.glob(os.path.join(CONFIG.ADDONS, '*/'))
        for folder in sorted(fold, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername in CONFIG.EXCLUDES:
                continue
            elif foldername in CONFIG.DEFAULTPLUGINS:
                continue
            elif foldername == 'packages':
                continue
            xml = os.path.join(folder, 'addon.xml')
            if os.path.exists(xml):
                a = tools.read_from_file(xml)
                temp, addid = parse(a, foldername)
                addonnames.append(temp)
                addonids.append(addid)
                addonfolds.append(foldername)
        fold2 = glob.glob(os.path.join(CONFIG.ADDON_DATA, '*/'))
        for folder in sorted(fold2, key=lambda x: x):
            foldername = os.path.split(folder[:-1])[1]
            if foldername in addonfolds:
                continue
            if foldername in CONFIG.EXCLUDES:
                continue
            xml = os.path.join(CONFIG.ADDONS, foldername, 'addon.xml')
            xml2 = os.path.join(CONFIG.XBMC, 'addons', foldername, 'addon.xml')
            if os.path.exists(xml):
                a = tools.read_from_file(xml)
            elif os.path.exists(xml2):
                a = tools.read_from_file(xml2)
            else:
                continue
            temp, addid = parse(a, foldername)
            addonnames.append(temp)
            addonids.append(addid)
            addonfolds.append(foldername)
        selected = []
        tempaddonnames = ["-- Clique aqui para continuar --"] + addonnames
        currentWhite = whitelist(do='read')
        for item in currentWhite:
            logging.log(str(item))
            try:
                name, id, fold = item
            except Exception as e:
                logging.log(str(e))
            if id in addonids:
                pos = addonids.index(id) + 1
                selected.append(pos - 1)
                tempaddonnames[pos] = "[B][COLOR {0}]{1}[/COLOR][/B]".format(
                    CONFIG.COLOR1, name)
            else:
                addonids.append(id)
                addonnames.append(name)
                tempaddonnames.append("[B][COLOR {0}]{1}[/COLOR][/B]".format(
                    CONFIG.COLOR1, name))
        choice = 1
        while choice not in [-1, 0]:
            choice = dialog.select(
                "{0}: Selecione os complementos que deseja para a lista de permissões."
                .format(CONFIG.ADDONTITLE), tempaddonnames)
            if choice == -1:
                break
            elif choice == 0:
                break
            else:
                choice2 = (choice - 1)
                if choice2 in selected:
                    selected.remove(choice2)
                    tempaddonnames[choice] = addonnames[choice2]
                else:
                    selected.append(choice2)
                    tempaddonnames[
                        choice] = "[B][COLOR {0}]{1}[/COLOR][/B]".format(
                            CONFIG.COLOR1, addonnames[choice2])
        white_list = []
        if len(selected) > 0:
            for addon in selected:
                white_list.append(
                    "['%s', '%s', '%s']" %
                    (addonnames[addon], addonids[addon], addonfolds[addon]))
            writing = '\n'.join(white_list)
            tools.write_to_file(CONFIG.WHITELIST, writing)
        else:
            try:
                os.remove(CONFIG.WHITELIST)
            except:
                pass
        logging.log_notify(
            CONFIG.ADDONTITLE,
            "[COLOR {0}]{1} Complementos na lista de permissões[/COLOR]".
            format(CONFIG.COLOR2, len(selected)))
    elif do == 'read':
        white_list = []
        if os.path.exists(CONFIG.WHITELIST):
            lines = tools.read_from_file(CONFIG.WHITELIST).split('\n')
            for item in lines:
                try:
                    name, id, fold = eval(item)
                    white_list.append(eval(item))
                except:
                    pass
        return white_list
    elif do == 'view':
        list = whitelist(do='read')
        if len(list) > 0:
            msg = "Aqui está uma lista de seus itens de whitelist, esses itens (junto com as dependências) não serão removidos ao realizar um novo início ou os dados do usuário sobrescritos em uma instalação de compilação.[CR][CR]"
            for item in list:
                try:
                    name, id, fold = item
                except Exception as e:
                    logging.log(str(e))
                msg += "[COLOR {0}]{1}[/COLOR] [COLOR {2}]\"{3}\"[/COLOR][CR]".format(
                    CONFIG.COLOR1, name, CONFIG.COLOR2, id)
            window.show_text_box("Exibindo itens da lista de permissões", msg)
        else:
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Nenhum item na lista de permissões[/COLOR]".format(
                    CONFIG.COLOR2))
    elif do == 'import':
        source = dialog.browse(
            1,
            '[COLOR {0}]Selecione o arquivo da lista de permissões para importar[/COLOR]'
            .format(CONFIG.COLOR2), 'files', '.txt', False, False, CONFIG.HOME)
        logging.log(str(source))
        if not source.endswith('.txt'):
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Importação cancelada![/COLOR]".format(
                    CONFIG.COLOR2))
            return
        current = whitelist(do='read')
        idList = []
        count = 0
        for item in current:
            name, id, fold = item
            idList.append(id)
        lines = tools.read_from_file(xbmcvfs.File(source)).split('\n')
        with open(CONFIG.WHITELIST, 'a') as f:
            for item in lines:
                try:
                    name, id, folder = eval(item)
                except Exception as e:
                    logging.log("Erro ao adicionar: '{0}' / {1}".format(
                        item, str(e)),
                                level=xbmc.LOGERROR)
                    continue
                logging.log("{0} / {1} / {2}".format(name, id, folder))
                if id not in idList:
                    count += 1
                    writing = "['{0}', '{1}', '{2}']".format(name, id, folder)
                    if len(idList) + count > 1:
                        writing = "\n%s" % writing
                    f.write(writing)
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]{1} Item(s) Adicionado[/COLOR]".format(
                    CONFIG.COLOR2, count))
    elif do == 'export':
        source = dialog.browse(
            3,
            '[COLOR {0}]AdicionadoSelecione para onde deseja exportar o arquivo da lista de permissões[/COLOR]'
            .format(CONFIG.COLOR2), 'files', '.txt', False, False, CONFIG.HOME)
        logging.log(str(source))
        try:
            xbmcvfs.copy(CONFIG.WHITELIST,
                         os.path.join(source, 'whitelist.txt'))
            dialog.ok(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]A lista de permissões foi exportada para:[/COLOR]".
                format(CONFIG.COLOR2) + '\n' + "[COLOR {0}]{1}[/COLOR]".format(
                    CONFIG.COLOR1, os.path.join(source, 'whitelist.txt')))
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Whitelist Exported[/COLOR]".format(CONFIG.COLOR2))
        except Exception as e:
            logging.log("Export Error: {0}".format(str(e)),
                        level=xbmc.LOGERROR)
            if not dialog.yesno(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]O local selecionado não é gravável. Gostaria de selecionar outro?[/COLOR]"
                    .format(CONFIG.COLOR2),
                    yeslabel=
                    "[B][COLOR springgreen]Mudar localização[/COLOR][/B]",
                    nolabel="[B][COLOR red]Não Cancelar[/COLOR][/B]"):
                logging.log_notify(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]Exportação da lista branca cancelada[/COLOR]".
                    format(CONFIG.COLOR2, e))
            else:
                whitelist(do='export')
    elif do == 'clear':
        if not dialog.yesno(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Tem certeza de que deseja limpar sua lista de permissões?"
                .format(CONFIG.COLOR2) + '\n' +
                "Este processo não pode ser desfeito.[/COLOR]",
                yeslabel="[B][COLOR springgreen]Sim remover[/COLOR][/B]",
                nolabel="[B][COLOR red]No Cancel[/COLOR][/B]"):
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Clear Whitelist Cancelado[/COLOR]".format(
                    CONFIG.COLOR2))
            return
        try:
            os.remove(CONFIG.WHITELIST)
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Permissões Liberado[/COLOR]".format(CONFIG.COLOR2))
        except:
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Erro ao limpar a lista de permissões![/COLOR]".
                format(CONFIG.COLOR2))
コード例 #16
0
ファイル: check.py プロジェクト: gtkingbuild/Repo-Prueba
def check_sources():
    from resources.libs.common import logging
    from resources.libs.common import tools

    dialog = xbmcgui.Dialog()
    progress_dialog = xbmcgui.DialogProgress()

    if not os.path.exists(CONFIG.SOURCES):
        logging.log_notify(
            CONFIG.ADDONTITLE,
            "[COLOR {0}]No se ha Encontrado Ningún Archivo Fuentes.xml!![/COLOR]"
            .format(CONFIG.COLOR2))
        return False
    x = 0
    bad = []
    remove = []
    a = tools.read_from_file(CONFIG.SOURCES)
    temp = a.replace('\r', '').replace('\n', '').replace('\t', '')
    match = re.compile('<files>.+?</files>').findall(temp)

    if len(match) > 0:
        match2 = re.compile(
            '<source>.+?<name>(.+?)</name>.+?<path pathversion="1">(.+?)</path>.+?<allowsharing>(.+?)</allowsharing>.+?</source>'
        ).findall(match[0])
        progress_dialog.create(
            CONFIG.ADDONTITLE,
            "[COLOR {0}]Escaneo de Fuentes en Busca de enlaces Rotos[/COLOR]".
            format(CONFIG.COLOR2))
        for name, path, sharing in match2:
            x += 1
            perc = int(tools.percentage(x, len(match2)))
            progress_dialog.update(
                perc, '' + '\n' +
                "[COLOR {0}]Comprobando [COLOR {1}]{2}[/COLOR]:[/COLOR]".
                format(CONFIG.COLOR2, CONFIG.COLOR1, name) + '\n' +
                "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, path))

            working = tools.open_url(path, check=True)
            if not working:
                bad.append([name, path, sharing, working])

        logging.log("Fuentes Malas: {0}".format(len(bad)))
        if len(bad) > 0:
            choice = dialog.yesno(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]{1}[/COLOR][COLOR {2}] Fuente(s) se han encontrado Rotas"
                .format(CONFIG.COLOR1, len(bad), CONFIG.COLOR2) + '\n' +
                "Le gustaría Eliminar todos o elegir uno por uno?[/COLOR]",
                yeslabel="[B][COLOR dodgerblue]Eliminar Todo[/COLOR][/B]",
                nolabel="[B][COLOR red]Elija Eliminar[/COLOR][/B]")
            if choice == 1:
                remove = bad
            else:
                for name, path, sharing, working in bad:
                    logging.log("{0} fuentes: {1}, {2}".format(
                        name, path, working))
                    if dialog.yesno(
                            CONFIG.ADDONTITLE,
                            "[COLOR {0}]{1}[/COLOR][COLOR {2}] se informó que no funciona"
                            .format(CONFIG.COLOR1, name, CONFIG.COLOR2) +
                            '\n' + "[COLOR {0}]{1}[/COLOR]".format(
                                CONFIG.COLOR1, path) + '\n' +
                            "[COLOR {0}]{1}[/COLOR]".format(
                                CONFIG.COLOR1, working),
                            yeslabel=
                            "[B][COLOR dodgerblue]Eliminar Fuente[/COLOR][/B]",
                            nolabel="[B][COLOR red]Mantener Fuente[/COLOR][/B]"
                    ):
                        remove.append([name, path, sharing, working])
                        logging.log("Eliminando Fuente {0}".format(name))
                    else:
                        logging.log("La Fuente {0} no se eliminó".format(name))
            if len(remove) > 0:
                for name, path, sharing, working in remove:
                    a = a.replace(
                        '\n<source>\n<name>{0}</name>\n<path pathversion="1">{1}</path>\n<allowsharing>{2}</allowsharing>\n</source>'
                        .format(name, path, sharing), '')
                    logging.log("Eliminando Fuente {0}".format(name))

                tools.write_to_file(CONFIG.SOURCES, str(a))
                alive = len(match) - len(bad)
                kept = len(bad) - len(remove)
                removed = len(remove)
                dialog.ok(
                    CONFIG.ADDONTITLE,
                    "[COLOR {0}]La Comprobación de las fuentes en busca de rutas rotas ha finalizado."
                    .format(CONFIG.COLOR2) + '\n' +
                    "Funciona: [COLOR {0}]{1}[/COLOR] | Conservo: [COLOR {2}]{3}[/COLOR] | Eliminado: [COLOR {4}]{5}[/COLOR][/COLOR]"
                    .format(CONFIG.COLOR2, CONFIG.COLOR1, alive, CONFIG.COLOR1,
                            kept, CONFIG.COLOR1, removed))
            else:
                logging.log("No hay Fuentes Malas que eliminar.")
        else:
            logging.log_notify(
                CONFIG.ADDONTITLE,
                "[COLOR {0}]Todas las Fuentes están Funcionando[/COLOR]".
                format(CONFIG.COLOR2))
    else:
        logging.log("No se Encontraron Fuentes")