def func(*args, **kwargs):
     """A mock function which returns itself, enabling chainable
     function calls.
     """
     log.warning('The %s method has not been implemented on '
                 'the CLI. Your code might not work properly '
                 'when calling it.', name)
     return self
Example #2
0
 def notify(self, msg='', title=None, delay=5000, image=''):
     """Displays a temporary notification message to the user. If
     title is not provided, the plugin name will be used. To have a
     blank title, pass '' for the title argument. The delay argument
     is in milliseconds.
     """
     if not msg:
         log.warning('Empty message for notification dialog')
     if title is None:
         title = self.addon.getAddonInfo('name')
     xbmc.executebuiltin('Kodi.Notification("%s", "%s", "%s", "%s")' %
                         (msg, title, delay, image))
Example #3
0
 def notify(self, msg='', title=None, delay=5000, image=''):
     """Displays a temporary notification message to the user. If
     title is not provided, the plugin name will be used. To have a
     blank title, pass '' for the title argument. The delay argument
     is in milliseconds.
     """
     if not msg:
         log.warning('Empty message for notification dialog')
     if title is None:
         title = self.addon.getAddonInfo('name')
     xbmc.executebuiltin('Kodi.Notification("%s", "%s", "%s", "%s")' %
                         (msg, title, delay, image))
 def getSetting(self, key):
     log.warning('xbmcaddon.Plugin.getSetting() has not been implemented '
                 'in CLI mode.')
     try:
         value = self._settings[key]
     except KeyError:
         # see if we have an env var
         value = _get_env_setting(key)
         if _get_env_setting(key) is None:
             value = raw_input('* Please enter a temporary value for %s: ' %
                               key)
         self._settings[key] = value
     return value
Example #5
0
 def getSetting(self, key):
     log.warning('xbmcaddon.Plugin.getSetting() has not been implemented '
                 'in CLI mode.')
     try:
         value = self._settings[key]
     except KeyError:
         # see if we have an env var
         value = _get_env_setting(key)
         if _get_env_setting(key) is None:
             value = raw_input(
                 '* Please enter a temporary value for %s: ' % key)
         self._settings[key] = value
     return value
Example #6
0
    def get_setting(self, key, converter=None, choices=None):
        """Returns the settings value for the provided key.

        If converter is str, unicode, bool or int the settings value will be
        returned converted to the provided type. If choices is an instance of
        list or tuple its item at position of the settings value be returned.

        Args:
            key (str): The ID of the setting defined in settings.xml.
            converter (Optional[str, unicode, bool, int]): How to convert the
                setting value.
                TODO(Sinap): Maybe this should just be a callable object?
            choices (Optional[list,tuple]):

        Notes:
            converter: It is suggested to always use unicode for
                text-settings because else xbmc returns utf-8 encoded strings.

        Examples:
            * ``plugin.get_setting('per_page', int)``
            * ``plugin.get_setting('password', unicode)``
            * ``plugin.get_setting('force_viewmode', bool)``
            * ``plugin.get_setting('content', choices=('videos', 'movies'))``
        """
        # TODO: allow pickling of settings items?
        # TODO: STUB THIS OUT ON CLI
        value = self.addon.getSetting(key)
        if converter is str:
            return value
        elif converter is unicode:
            return value.decode('utf-8')
        elif converter is bool:
            return value == 'true'
        elif converter is int:
            return int(value)
        elif isinstance(choices, (list, tuple)):
            return choices[int(value)]
        elif converter is None:
            log.warning('No converter provided, unicode should be used, '
                        'but returning str value')
            return value
        else:
            raise TypeError('Acceptable converters are str, unicode, bool and '
                            'int. Acceptable choices are instances of list '
                            ' or tuple.')
Example #7
0
    def get_setting(self, key, converter=None, choices=None):
        """Returns the settings value for the provided key.

        If converter is str, unicode, bool or int the settings value will be
        returned converted to the provided type. If choices is an instance of
        list or tuple its item at position of the settings value be returned.

        Args:
            key (str): The ID of the setting defined in settings.xml.
            converter (Optional[str, unicode, bool, int]): How to convert the
                setting value.
                TODO(Sinap): Maybe this should just be a callable object?
            choices (Optional[list,tuple]):

        Notes:
            converter: It is suggested to always use unicode for
                text-settings because else xbmc returns utf-8 encoded strings.

        Examples:
            * ``plugin.get_setting('per_page', int)``
            * ``plugin.get_setting('password', unicode)``
            * ``plugin.get_setting('force_viewmode', bool)``
            * ``plugin.get_setting('content', choices=('videos', 'movies'))``
        """
        # TODO: allow pickling of settings items?
        # TODO: STUB THIS OUT ON CLI
        value = self.addon.getSetting(key)
        if converter is str:
            return value
        elif converter is unicode:
            return value.decode('utf-8')
        elif converter is bool:
            return value == 'true'
        elif converter is int:
            return int(value)
        elif isinstance(choices, (list, tuple)):
            return choices[int(value)]
        elif converter is None:
            log.warning('No converter provided, unicode should be used, '
                        'but returning str value')
            return value
        else:
            raise TypeError('Acceptable converters are str, unicode, bool and '
                            'int. Acceptable choices are instances of list '
                            ' or tuple.')
Example #8
0
    def add_url_rule(self, url_rule, view_func, name, options=None):
        """This method adds a URL rule for routing purposes. The
        provided name can be different from the view function name if
        desired. The provided name is what is used in url_for to build
        a URL.

        The route decorator provides the same functionality.
        """
        rule = UrlRule(url_rule, view_func, name, options)
        if name in self._view_functions.keys():
            # TODO: Raise exception for ambiguous views during registration
            log.warning('Cannot add url rule "%s" with name "%s". There is '
                        'already a view with that name', url_rule, name)
            self._view_functions[name] = None
        else:
            log.debug('Adding url rule "%s" named "%s" pointing to function '
                      '"%s"', url_rule, name, view_func.__name__)
            self._view_functions[name] = rule
        self._routes.append(rule)
Example #9
0
    def add_url_rule(self, url_rule, view_func, name, options=None):
        """This method adds a URL rule for routing purposes. The
        provided name can be different from the view function name if
        desired. The provided name is what is used in url_for to build
        a URL.

        The route decorator provides the same functionality.
        """
        rule = UrlRule(url_rule, view_func, name, options)
        if name in self._view_functions.keys():
            # TODO: Raise exception for ambiguous views during registration
            log.warning(
                'Cannot add url rule "%s" with name "%s". There is '
                'already a view with that name', url_rule, name)
            self._view_functions[name] = None
        else:
            log.debug(
                'Adding url rule "%s" named "%s" pointing to function '
                '"%s"', url_rule, name, view_func.__name__)
            self._view_functions[name] = rule
        self._routes.append(rule)
Example #10
0
    def add_to_playlist(items, playlist='video'):
        """Adds the provided list of items to the specified playlist.
        Available playlists include *video* and *music*.
        """
        playlists = {'music': 0, 'video': 1}
        if playlist not in playlists:
            raise ValueError('Playlist "%s" is invalid.' % playlist)

        selected_playlist = xbmc.PlayList(playlists[playlist])
        _items = []
        for item in items:
            if not hasattr(item, 'as_xbmc_listitem'):
                if 'info_type' in item:
                    log.warning('info_type key has no affect for playlist '
                                'items as the info_type is inferred from the '
                                'playlist type.')
                # info_type has to be same as the playlist type
                item['info_type'] = playlist
                item = kodiswift.ListItem.from_dict(**item)
            _items.append(item)
            selected_playlist.add(item.get_path(), item.as_xbmc_listitem())
        return _items
Example #11
0
    def add_to_playlist(items, playlist='video'):
        """Adds the provided list of items to the specified playlist.
        Available playlists include *video* and *music*.
        """
        playlists = {'music': 0, 'video': 1}
        if playlist not in playlists:
            raise ValueError('Playlist "%s" is invalid.' % playlist)

        selected_playlist = xbmc.PlayList(playlists[playlist])
        _items = []
        for item in items:
            if not hasattr(item, 'as_xbmc_listitem'):
                if 'info_type' in item:
                    log.warning('info_type key has no affect for playlist '
                                'items as the info_type is inferred from the '
                                'playlist type.')
                # info_type has to be same as the playlist type
                item['info_type'] = playlist
                item = kodiswift.ListItem.from_dict(**item)
            _items.append(item)
            selected_playlist.add(item.get_path(), item.as_xbmc_listitem())
        return _items