Get the blocklist plugin kind of working.. Still needs some lovin'.

This commit is contained in:
Andrew Resch 2009-06-10 03:42:33 +00:00
commit 267c7408d7
2 changed files with 12 additions and 19 deletions

View file

@ -591,11 +591,11 @@ class Core(component.Component):
self.ip_filter.add_rule(range[0], range[1], 1) self.ip_filter.add_rule(range[0], range[1], 1)
# Start a 2 second timer (and remove the previous one if it exists) # Start a 2 second timer (and remove the previous one if it exists)
#if self.__set_ip_filter_timer: if self.__set_ip_filter_timer:
# self.__set_ip_filter_timer.stop() self.__set_ip_filter_timer.stop()
#self.__set_ip_filter_timer = LoopingCall(self.session.set_ip_filter, self.ip_filter) self.__set_ip_filter_timer = LoopingCall(self.session.set_ip_filter, self.ip_filter)
#self.__set_ip_filter_timer.start(2, False) self.__set_ip_filter_timer.start(2, False)
@export @export
def reset_ip_filter(self): def reset_ip_filter(self):

View file

@ -33,15 +33,15 @@
# #
# #
import threading
import urllib import urllib
import os import os
import datetime import datetime
import gobject
import time import time
import shutil import shutil
from twisted.internet.task import LoopingCall
from twisted.internet import reactor
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.plugins.pluginbase import CorePluginBase from deluge.plugins.pluginbase import CorePluginBase
import deluge.component as component import deluge.component as component
@ -91,9 +91,8 @@ class Core(CorePluginBase):
# This function is called every 'check_after_days' days, to download # This function is called every 'check_after_days' days, to download
# and import a new list if needed. # and import a new list if needed.
self.update_timer = gobject.timeout_add( self.update_timer = LoopingCall(self.download_blocklist)
self.config["check_after_days"] * 24 * 60 * 60 * 1000, self.update_timer.start(self.config["check_after_days"] * 24 * 60 * 60)
self.download_blocklist, True)
def disable(self): def disable(self):
log.debug("Reset IP Filter..") log.debug("Reset IP Filter..")
@ -114,7 +113,7 @@ class Core(CorePluginBase):
def import_list(self, force=False): def import_list(self, force=False):
"""Import the blocklist from the blocklist.cache, if load is True, then """Import the blocklist from the blocklist.cache, if load is True, then
it will download the blocklist file if needed.""" it will download the blocklist file if needed."""
threading.Thread(target=self.import_blocklist, kwargs={"force": force}).start() reactor.callInThread(self.import_blocklist, force=force)
@export() @export()
def get_config(self): def get_config(self):
@ -222,16 +221,10 @@ class Core(CorePluginBase):
return return
self.is_downloading = True self.is_downloading = True
threading.Thread( reactor.callInThread(self.download_blocklist_thread, self.on_download_blocklist, load)
target=self.download_blocklist_thread,
args=(self.on_download_blocklist, load)).start()
def download_blocklist_thread(self, callback, load): def download_blocklist_thread(self, callback, load):
"""Downloads the blocklist specified by 'url' in the config""" """Downloads the blocklist specified by 'url' in the config"""
def _call_callback(callback, load):
callback(load)
return False
def on_retrieve_data(count, block_size, total_blocks): def on_retrieve_data(count, block_size, total_blocks):
fp = float(count * block_size) / total_blocks fp = float(count * block_size) / total_blocks
if fp > 1.0: if fp > 1.0:
@ -256,7 +249,7 @@ class Core(CorePluginBase):
log.debug("Blocklist successfully downloaded..") log.debug("Blocklist successfully downloaded..")
self.config["file_date"] = datetime.datetime.strptime(headers["last-modified"],"%a, %d %b %Y %H:%M:%S GMT").ctime() self.config["file_date"] = datetime.datetime.strptime(headers["last-modified"],"%a, %d %b %Y %H:%M:%S GMT").ctime()
self.config["file_size"] = long(headers["content-length"]) self.config["file_size"] = long(headers["content-length"])
gobject.idle_add(_call_callback, callback, load) reactor.callLater(0, callback, load)
return return
def need_new_blocklist(self): def need_new_blocklist(self):