Exemple #1
0
def servers_blacklist(item):
    server_list = servertools.get_servers_list()
    dict_values = {}

    list_controls = [{
        "id": "filter_servers",
        "type": "bool",
        "label": "@30068",
        "default": False,
        "enabled": True,
        "visible": True
    }]
    dict_values['filter_servers'] = config.get_setting('filter_servers')
    if dict_values['filter_servers'] == None:
        dict_values['filter_servers'] = False
    for i, server in enumerate(sorted(server_list.keys())):
        server_parameters = server_list[server]
        controls, defaults = servertools.get_server_controls_settings(server)
        dict_values[server] = config.get_setting("black_list", server=server)

        control = {
            "id": server,
            "type": "bool",
            "label": '    %s' % server_parameters["name"],
            "default": defaults.get("black_list", False),
            "enabled": "eq(-%s,True)" % (i + 1),
            "visible": True
        }
        list_controls.append(control)

    return platformtools.show_channel_settings(
        list_controls=list_controls,
        dict_values=dict_values,
        caption=config.get_localized_string(60550),
        callback="cb_servers_blacklist")
Exemple #2
0
def servers_blacklist(item):
    server_list = servertools.get_servers_list()
    dict_values = {}

    list_controls = [{'id': 'filter_servers',
                      'type': "bool",
                      'label': "@30068",
                      'default': False,
                      'enabled': True,
                      'visible': True}]
    dict_values['filter_servers'] = config.get_setting('filter_servers')

    for i, server in enumerate(sorted(server_list.keys())):
        server_parameters = server_list[server]
        controls, defaults = servertools.get_server_controls_settings(server)
        dict_values[server] = config.get_setting("black_list",server=server)
        
        control = {'id': server,
                   'type': "bool",
                   'label': '    %s' % server_parameters["name"],
                   'default': defaults.get("black_list", False),
                   'enabled': "eq(-%s,True)" % (i + 1),
                   'visible': True}
        list_controls.append(control)


    return platformtools.show_channel_settings(list_controls=list_controls, dict_values=dict_values,
                                               caption="Servidores bloqueados",
                                               callback="cb_servers_blacklist")
Exemple #3
0
    def start(self,
              list_controls=None,
              dict_values=None,
              caption="",
              callback=None,
              item=None,
              custom_button=None,
              channelpath=None):
        logger.info()

        # Ruta para las imagenes de la ventana
        self.mediapath = os.path.join(config.get_runtime_path(), 'resources',
                                      'skins', 'Default', 'media')

        # Capturamos los parametros
        self.list_controls = list_controls
        self.values = dict_values
        self.caption = caption
        self.callback = callback
        self.item = item

        if type(custom_button) == dict:
            self.custom_button = {}
            self.custom_button["label"] = custom_button.get("label", "")
            self.custom_button["function"] = custom_button.get("function", "")
            self.custom_button["visible"] = bool(
                custom_button.get("visible", True))
            self.custom_button["close"] = bool(
                custom_button.get("close", False))
        else:
            self.custom_button = None

        # Obtenemos el canal desde donde se ha echo la llamada y cargamos los settings disponibles para ese canal
        if not channelpath:
            channelpath = inspect.currentframe(
            ).f_back.f_back.f_code.co_filename
        self.channel = os.path.basename(channelpath).replace(".py", "")
        self.ch_type = os.path.basename(os.path.dirname(channelpath))

        # Si no tenemos list_controls, hay que sacarlos del json del canal
        if not self.list_controls:

            # Si la ruta del canal esta en la carpeta "channels", obtenemos los controles y valores mediante chaneltools
            if os.path.join(config.get_runtime_path(),
                            "channels") in channelpath:

                # La llamada se hace desde un canal
                self.list_controls, default_values = channeltools.get_channel_controls_settings(
                    self.channel)
                self.kwargs = {"channel": self.channel}

            # Si la ruta del canal esta en la carpeta "servers", obtenemos los controles y valores mediante servertools
            elif os.path.join(config.get_runtime_path(),
                              "servers") in channelpath:

                # La llamada se hace desde un canal
                self.list_controls, default_values = servertools.get_server_controls_settings(
                    self.channel)
                self.kwargs = {"server": self.channel}

            # En caso contrario salimos
            else:
                return None

        # Si no se pasan dict_values, creamos un dict en blanco
        if self.values is None:
            self.values = {}

        # Ponemos el titulo
        if self.caption == "":
            self.caption = str(config.get_localized_string(
                30100)) + " -- " + self.channel.capitalize()

        elif self.caption.startswith('@') and unicode(
                self.caption[1:]).isnumeric():
            self.caption = config.get_localized_string(int(self.caption[1:]))

        # Muestra la ventana
        self.return_value = None
        self.doModal()
        return self.return_value
Exemple #4
0
    def show_channel_settings(self,
                              list_controls=None,
                              dict_values=None,
                              caption="",
                              callback=None,
                              item=None,
                              custom_button=None,
                              channelpath=None):
        from platformcode import config
        from core import channeltools
        from core import servertools
        import inspect
        if not os.path.isdir(
                os.path.join(config.get_data_path(), "settings_channels")):
            os.mkdir(os.path.join(config.get_data_path(), "settings_channels"))

        title = caption

        if type(custom_button) == dict:
            custom_button = {
                "label": custom_button.get("label", ""),
                "function": custom_button.get("function", ""),
                "visible": bool(custom_button.get("visible", True)),
                "close": bool(custom_button.get("close", False))
            }

        else:
            custom_button = None

        # Obtenemos el canal desde donde se ha echo la llamada y cargamos los settings disponibles para ese canal
        if not channelpath:
            channelpath = inspect.currentframe(
            ).f_back.f_back.f_code.co_filename
        channelname = os.path.basename(channelpath).split(".")[0]
        ch_type = os.path.basename(os.path.dirname(channelpath))

        # Si no tenemos list_controls, hay que sacarlos del json del canal
        if not list_controls:

            # Si la ruta del canal esta en la carpeta "channels", obtenemos los controles y valores mediante chaneltools
            if os.path.join(config.get_runtime_path(),
                            "channels") in channelpath:

                # La llamada se hace desde un canal
                list_controls, default_values = channeltools.get_channel_controls_settings(
                    channelname)
                kwargs = {"channel": channelname}

            # Si la ruta del canal esta en la carpeta "servers", obtenemos los controles y valores mediante servertools
            elif os.path.join(config.get_runtime_path(),
                              "servers") in channelpath:
                # La llamada se hace desde un server
                list_controls, default_values = servertools.get_server_controls_settings(
                    channelname)
                kwargs = {"server": channelname}

            # En caso contrario salimos
            else:
                return None

        # Si no se pasan dict_values, creamos un dict en blanco
        if dict_values == None:
            dict_values = {}

        # Ponemos el titulo
        if caption == "":
            caption = str(config.get_localized_string(
                30100)) + " -- " + channelname.capitalize()
        elif caption.startswith('@') and unicode(caption[1:]).isnumeric():
            caption = config.get_localized_string(int(caption[1:]))

        JsonData = {}
        JsonData["action"] = "OpenConfig"
        JsonData["data"] = {}
        JsonData["data"]["title"] = self.kodi_labels_to_html(caption)
        JsonData["data"]["custom_button"] = custom_button
        JsonData["data"]["items"] = []

        # Añadir controles
        for c in list_controls:
            if not "default" in c: c["default"] = ""
            if not "color" in c: c["color"] = "auto"
            if not "label" in c: continue

            # Obtenemos el valor
            if "id" in c:
                if not c["id"] in dict_values:
                    if not callback:
                        c["value"] = config.get_setting(c["id"], **kwargs)
                    else:
                        c["value"] = c["default"]

                    dict_values[c["id"]] = c["value"]

                else:
                    c["value"] = dict_values[c["id"]]

            # Translation
            if c['label'].startswith('@') and unicode(
                    c['label'][1:]).isnumeric():
                c['label'] = str(config.get_localized_string(c['label'][1:]))
            if c["label"].endswith(":"): c["label"] = c["label"][:-1]

            if c['type'] == 'list':
                lvalues = []
                for li in c['lvalues']:
                    if li.startswith('@') and unicode(li[1:]).isnumeric():
                        lvalues.append(str(config.get_localized_string(
                            li[1:])))
                    else:
                        lvalues.append(li)
                c['lvalues'] = lvalues

            c["label"] = self.kodi_labels_to_html(c["label"])

            JsonData["data"]["items"].append(c)

        ID = self.send_message(JsonData)
        close = False

        while True:
            data = self.get_data(ID)
            if type(data) == dict:
                JsonData["action"] = "HideLoading"
                JsonData["data"] = {}
                self.send_message(JsonData)

                for v in data:
                    if data[v] == "true": data[v] = True
                    if data[v] == "false": data[v] = False
                    if unicode(data[v]).isnumeric(): data[v] = int(data[v])

                if callback and '.' in callback:
                    package, callback = callback.rsplit('.', 1)
                else:
                    package = '%s.%s' % (ch_type, channelname)

                cb_channel = None
                try:
                    cb_channel = __import__(package, None, None, [package])
                except ImportError:
                    logger.error('Imposible importar %s' % package)

                if callback:
                    # Si existe una funcion callback la invocamos ...
                    return getattr(cb_channel, callback)(item, data)
                else:
                    # si no, probamos si en el canal existe una funcion 'cb_validate_config' ...
                    try:
                        return getattr(cb_channel, 'cb_validate_config')(item,
                                                                         data)
                    except AttributeError:
                        # ... si tampoco existe 'cb_validate_config'...
                        for v in data:
                            config.set_setting(v, data[v], **kwargs)

            elif data == "custom_button":
                if '.' in callback:
                    package, callback = callback.rsplit('.', 1)
                else:
                    package = '%s.%s' % (ch_type, channelname)
                try:
                    cb_channel = __import__(package, None, None, [package])
                except ImportError:
                    logger.error('Imposible importar %s' % package)
                else:
                    return_value = getattr(
                        cb_channel, custom_button['function'])(item,
                                                               dict_values)
                    if custom_button["close"] == True:
                        return return_value
                    else:
                        JsonData["action"] = "custom_button"
                        JsonData["data"] = {}
                        JsonData["data"]["values"] = dict_values
                        JsonData["data"]["return_value"] = return_value
                        ID = self.send_message(JsonData)

            elif data == False:
                return None
Exemple #5
0
    def start(self,
              list_controls=None,
              dict_values=None,
              caption="",
              callback=None,
              item=None,
              custom_button=None,
              channelpath=None):
        log()

        # Media Path
        self.mediapath = os.path.join(config.get_runtime_path(), 'resources',
                                      'skins', 'Default', 'media')

        # Params
        self.list_controls = list_controls
        self.values = dict_values
        self.caption = caption
        self.callback = callback
        self.item = item

        if isinstance(custom_button, dict):
            self.custom_button = {}
            self.custom_button["label"] = custom_button.get("label", "")
            self.custom_button["function"] = custom_button.get("function", "")
            self.custom_button["visible"] = bool(
                custom_button.get("visible", True))
            self.custom_button["close"] = bool(
                custom_button.get("close", False))
        else:
            self.custom_button = None

        # Load Channel Settings
        if not channelpath:
            channelpath = inspect.currentframe(
            ).f_back.f_back.f_code.co_filename
        self.channel = os.path.basename(channelpath).replace(".py", "")
        self.ch_type = os.path.basename(os.path.dirname(channelpath))
        # If list_controls does not exist, it is removed from the channel json
        if not self.list_controls:

            # If the channel path is in the "channels" folder, we get the controls and values using chaneltools
            if os.path.join(
                    config.get_runtime_path(), "channels") or os.path.join(
                        config.get_runtime_path(), "specials") in channelpath:

                # The call is made from a channel
                self.list_controls, default_values = channeltools.get_channel_controls_settings(
                    self.channel)
                self.kwargs = {"channel": self.channel}
                self.channelName = channeltools.get_channel_json(
                    self.channel)['name']

            # If the channel path is in the "servers" folder, we get the controls and values through servertools
            elif os.path.join(config.get_runtime_path(),
                              "servers") in channelpath:

                # The call is made from a channel
                self.list_controls, default_values = servertools.get_server_controls_settings(
                    self.channel)
                self.kwargs = {"server": self.channel}
                self.channelName = servertools.get_server_json(
                    self.channel)['name']

            # Else Exit
            else:
                return None

        # If dict_values are not passed, create a blank dict
        if self.values is None:
            self.values = {}

        # Make title
        if self.caption == "":
            self.caption = str(
                config.get_localized_string(30100)) + ' - ' + self.channelName

        matches = match(self.caption, patron=r'@(\d+)').matches
        if matches:
            for m in matches:
                self.caption = self.caption.replace(
                    '@' + match, config.get_localized_string(int(m)))

        # Show Window
        self.return_value = None
        self.doModal()
        return self.return_value