def get_view_mode_id(self, view_mode): '''@deprecated Attempts to return a view_mode_id for a given view_mode taking into account the current skin. If not view_mode_id can be found, None is returned. 'thumbnail' is currently the only suppported view_mode. ''' log.warning('Editing skin viewmodes is not allowed.') return None
def getSetting(self, id): try: value = self._settings[id] except KeyError: log.warning('xbmcaddon.Addon.getSetting() has not been implemented' ' in CLI mode.') value = raw_input('* Please enter a temporary value for %s: ' % id) self._settings[id] = value return value
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('XBMC.Notification("%s", "%s", "%s", "%s")' % (to_utf8(msg), to_utf8(title), delay, to_utf8(image)))
def terminate(self): """Delete the underlying database file. Use with care.""" self.close() if self.filename == ':memory:': return log.info("Deleting %s" % self.filename) try: os.remove(self.filename) except IOError: _, e, _ = sys.exc_info() # python 2.5: "Exception as e" log.warning("Failed to delete %s: %s" % (self.filename, str(e)))
def delete(file): """Deletes a file. file: string - file to delete Example: xbmcvfs.delete(file)""" try: os.remove(encode_fs(file)) return True except: log.warning("Can't remove %s", file, exc_info=True) return False
def getSetting(self, id): log.warning('xbmcaddon.Addon.getSetting() has not been implemented in ' 'CLI mode.') try: value = self._settings[id] except KeyError: # see if we have an env var value = _get_env_setting(id) if _get_env_setting(id) is None: value = raw_input('* Please enter a temporary value for %s: ' % id) self._settings[id] = value return value
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') xbmcgui.Dialog().notification(heading=title, message=msg, time=delay, icon=image)
def rmdir(path): """Remove a folder. path: folder Example: success = xbmcfvs.rmdir(path) """ try: os.rmdir(encode_fs(path)) return True except: log.warning("Can't rmdir %s", path, exc_info=True) return False
def copy(source, destination): """Copy file to destination, returns true/false. source: string - file to copy. destination: string - destination file Example: success = xbmcvfs.copy(source, destination)""" try: shutil.copy(encode_fs(source), encode_fs(destination)) return True except: log.warning("Can't copy %s to %s", file, destination, exc_info=True) return False
def add_context_menu_items(self, items, replace_items=False): '''Adds context menu items. replace_items is only kept for legacy reasons, its functionality was removed. ''' for label, action in items: assert isinstance(label, basestring) assert isinstance(action, basestring) if replace_items: log.warning( "Replacing context menu items functionality was removed.") self._context_menu_items.extend(items) self._listitem.addContextMenuItems(items)
def mkdirs(path): """ mkdirs(path)--Create folder(s) - it will create all folders in the path. path : folder example: - success = xbmcvfs.mkdirs(path) """ try: os.makedirs(encode_fs(path)) return True except: log.warning("Can't makedirs %s", path, exc_info=True) return False
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. .. note:: It is suggested to always use unicode for text-settings because else xbmc returns utf-8 encoded strings. :param key: The id of the setting defined in settings.xml. :param converter: (Optional) Choices are str, unicode, bool and int. :param choices: (Optional) Choices are instances of list or tuple. 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(id=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: try: return json.loads(value) except: 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.')
def getSetting(self, id): """Returns the value of a setting as a unicode string. id: string - id of the setting that the module needs to access. Example: apikey = self.Addon.getSetting('apikey') """ log.warning('xbmcaddon.Addon.getSetting() has not been implemented in ' 'CLI mode.') try: value = self._settings[id] except KeyError: # see if we have an env var value = _get_env_setting(id) if _get_env_setting(id) is None: value = raw_input('* Please enter a temporary value for %s: ' % id) self._settings[id] = value return value
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)
def add_to_playlist(self, items, playlist='video'): '''Adds the provided list of items to the specified playlist. Available playlists include *video* and *music*. ''' playlists = {'music': 0, 'video': 1} assert playlist in playlists.keys(), ('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.keys(): 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 = xbmcswift2.ListItem.from_dict(**item) _items.append(item) selected_playlist.add(item.get_path(), item.as_xbmc_listitem()) return _items
def set_view_mode(self, view_mode_id): '''@deprecated Calls KODI's Container.SetViewMode. Requires an integer view_mode_id''' log.warning('Changing skin viewmodes is not allowed.')