def set(self, cache_id, data, checksum=None, expiration=datetime.timedelta(hours=24)): """ Stores new value in cache location :param cache_id: ID of cache to create :type cache_id: str :param data: value to store in cache :type data: Any :param checksum: Optional checksum to apply to item :type checksum: str,int :param expiration: Expiration of cache value in seconds since epoch :type expiration: int :return: None :rtype: """ expires = self._get_timestamp(expiration) cached = (expires, data, checksum) self._win.setProperty( g.encode_py2(cache_id), g.encode_py2( codecs.encode(pickle.dumps(cached), "base64").decode()), ) self._get_index() self._index.add((cache_id, expires)) self._save_index()
def _post_process(self, item, prepend_date=False, mixed_list=False): if not item: return name = g.decode_py2(item.get("info", {}).get("title")) if not name: g.log("Item has no title: {}".format(item), "error") if (not item["info"]["mediatype"] == "list" and not self.hide_unaired and not self.is_aired(item["info"])): name = g.color_string(tools.italic_string(name), "red") if item["info"]["mediatype"] == "episode": if self.title_appends_mixed and mixed_list: name = self._handle_episode_title_appending( name, item, self.title_appends_mixed) elif self.title_appends_general and not mixed_list: name = self._handle_episode_title_appending( name, item, self.title_appends_general) if item["info"][ "mediatype"] == "list" and self.list_title_appends == "1": name += " - {}".format( g.color_string(g.encode_py2(item["info"]["username"]))) if not item["info"]["mediatype"] == "list" and prepend_date: release_day = tools.parse_datetime(item["info"]["aired"][:10]) if release_day: release_day = release_day.strftime("%d %b") name = "[{}] {}".format(release_day, g.encode_py2(name)) item.update({"name": name}) item["info"]["title"] = name return item
def clear_all(self): """ Drop all values in cache locations :return: :rtype: """ self._get_index() for cache_id, expires in self._index: self._win.clearProperty(g.encode_py2(cache_id))
def install_skin(self, zip_location=None, silent=False): """ Method to install a new theme into Seren :param zip_location: Optional url to fetch zip file from :type zip_location: str :param silent: Optional argument to disable user feedback :type silent: bool :return: None :rtype: None """ self._get_zip_file(url=zip_location) if self._zip_file is None: return skin_meta = self._get_skin_meta() if skin_meta is None: return if skin_meta["skin_name"] in self.seren_skins: xbmcgui.Dialog().ok( g.ADDON_NAME, g.get_language_string(30228).format(skin_meta["skin_name"]), ) return self._extract_zip(skin_meta) self._add_skin_to_database(skin_meta) if not silent: switch_skin = xbmcgui.Dialog().yesno( g.ADDON_NAME, g.get_language_string(30218).format( g.encode_py2(skin_meta["skin_name"]), g.encode_py2(skin_meta["version"]), ), ) if not switch_skin: return self.switch_skin(skin_meta["skin_name"])
def _loads(value): """ Depickling method. :param value:Bytes with the pickled object :type value:str|bytes :return:Depickled value :rtype:any """ if value is None: return None retries = 0 while retries < 2: try: return pickle.loads(g.encode_py2(value)) except pickle.UnpicklingError: return None except RuntimeError: retries += 1 continue
def do_cleanup(self): """ Process cleaning up expired values from cache locations :return: :rtype: """ if self._exit: return self._get_index() cur_time = datetime.datetime.utcnow() cur_timestamp = self._get_timestamp() if self._win.getProperty(self._create_key("cache.mem.clean.busy")): return self._win.setProperty(self._create_key("cache.mem.clean.busy"), "busy") self._get_index() for cache_id, expires in self._index: if expires < cur_timestamp: self._win.clearProperty(g.encode_py2(cache_id)) self._win.setProperty(self._create_key("cache.mem.clean.busy"), repr(cur_time)) self._win.clearProperty(self._create_key("cache.mem.clean.busy"))
def _win_get_property(self, key): return g.encode_py2(self._win.getProperty(key))