def enable(self): log.debug('Blocklist: Plugin enabled..') self.is_url = True self.is_downloading = False self.is_importing = False self.has_imported = False self.up_to_date = False self.need_to_resume_session = False self.num_blocked = 0 self.file_progress = 0.0 self.core = component.get("Core") self.config = deluge.configmanager.ConfigManager( "blocklist.conf", DEFAULT_PREFS) self.reader = create_reader(self.config["list_type"], self.config["list_compression"]) if type(self.config["last_update"]) is not float: self.config.config["last_update"] = 0.0 update_now = False if self.config["load_on_start"]: self.pause_session() if self.config["check_after_days"] > 0: if self.config["last_update"]: last_update = datetime.fromtimestamp( self.config["last_update"]) check_period = timedelta( days=self.config["check_after_days"]) if not self.config[ "last_update"] or last_update + check_period < datetime.now( ): update_now = True if not update_now: d = self.import_list( deluge.configmanager.get_config_dir("blocklist.cache")) d.addCallbacks(self.on_import_complete, self.on_import_error) if self.need_to_resume_session: d.addBoth(self.resume_session) # This function is called every 'check_after_days' days, to download # and import a new list if needed. if self.config["check_after_days"] > 0: self.update_timer = LoopingCall(self.check_import) self.update_timer.start( self.config["check_after_days"] * 24 * 60 * 60, update_now)
def auto_detect(self, blocklist): """ Tries to auto-detect the blocklist type :param blocklist: path of blocklist to auto-detect :type blocklist: string :raises UnknownFormatError: if the format cannot be detected """ self.config["list_compression"] = detect_compression(blocklist) self.config["list_type"] = detect_format(blocklist, self.config["list_compression"]) log.debug("Auto-detected type: %s compression: %s", self.config["list_type"], self.config["list_compression"]) if not self.config["list_type"]: self.config["list_compression"] = "" raise UnknownFormatError else: self.reader = create_reader(self.config["list_type"], self.config["list_compression"])
def enable(self): log.debug('Blocklist: Plugin enabled...') self.is_url = True self.is_downloading = False self.is_importing = False self.has_imported = False self.up_to_date = False self.need_to_resume_session = False self.num_whited = 0 self.num_blocked = 0 self.file_progress = 0.0 self.core = component.get("Core") self.config = deluge.configmanager.ConfigManager("blocklist.conf", DEFAULT_PREFS) if "whitelisted" not in self.config: self.config["whitelisted"] = [] self.reader = create_reader(self.config["list_type"], self.config["list_compression"]) if type(self.config["last_update"]) is not float: self.config.config["last_update"] = 0.0 update_now = False if self.config["load_on_start"]: self.pause_session() if self.config["last_update"]: last_update = datetime.fromtimestamp(self.config["last_update"]) check_period = timedelta(days=self.config["check_after_days"]) if not self.config["last_update"] or last_update + check_period < datetime.now(): update_now = True else: d = self.import_list(deluge.configmanager.get_config_dir("blocklist.cache")) d.addCallbacks(self.on_import_complete, self.on_import_error) if self.need_to_resume_session: d.addBoth(self.resume_session) # This function is called every 'check_after_days' days, to download # and import a new list if needed. self.update_timer = LoopingCall(self.check_import) if self.config["check_after_days"] > 0: self.update_timer.start( self.config["check_after_days"] * 24 * 60 * 60, update_now )