mirror of
https://github.com/codex-storage/deluge.git
synced 2025-03-01 19:40:39 +00:00
BlocklistImport: Option to download new blocklist after certain numbers
of days has past. Patch from Mark Stahler.
This commit is contained in:
parent
20d13f8ddc
commit
b22a40de9b
@ -4,8 +4,8 @@
|
||||
##
|
||||
|
||||
plugin_name = "Blocklist Importer"
|
||||
plugin_author = "Steve 'Tarka' Smith"
|
||||
plugin_version = "0.4"
|
||||
plugin_author = "Steve 'Tarka' Smith, updated by Mark Stahler"
|
||||
plugin_version = "0.45"
|
||||
plugin_description = _("""
|
||||
Download and import various IP blocklists.
|
||||
|
||||
@ -34,7 +34,7 @@ import urllib, deluge.common, deluge.pref
|
||||
from peerguardian import PGReader, PGException
|
||||
from text import TextReader, GZMuleReader, PGZip
|
||||
from ui import GTKConfig, GTKProgress
|
||||
import os.path
|
||||
import os.path, os, time
|
||||
|
||||
# List of formats supported. This is used to generate the UI list and
|
||||
# specify the reader class. The last entry is for storage by the UI.
|
||||
@ -64,14 +64,14 @@ class BlocklistImport:
|
||||
self.config.load()
|
||||
|
||||
if self.config.has_key('url'):
|
||||
self.loadlist(fetch=self.config.get('load_on_start'))
|
||||
self.loadlist(fetch=self.config.get('load_after_days'))
|
||||
|
||||
|
||||
def _download_update(self, curr, chunksize, size):
|
||||
incs = float(size) / float(chunksize)
|
||||
self.gtkprog.download_prog(curr/incs)
|
||||
|
||||
def loadlist(self, fetch=False):
|
||||
def loadlist(self, fetch=-1):
|
||||
# Stop all torrents
|
||||
self.paused_or_not = {}
|
||||
for unique_ID in self.core.unique_IDs:
|
||||
@ -81,8 +81,26 @@ class BlocklistImport:
|
||||
|
||||
self.gtkprog.start()
|
||||
|
||||
# Compare modified time with load_after_days
|
||||
try:
|
||||
liststats = os.stat(self.blockfile)
|
||||
list_timestamp = liststats.st_mtime
|
||||
now_timestamp = time.time()
|
||||
days_update = self.config.get('load_after_days')
|
||||
|
||||
# Seconds in a day = 86400
|
||||
# Check to see if todays timestamp is older than the list plus days in config
|
||||
|
||||
if now_timestamp >= (list_timestamp + (86400 * days_update)):
|
||||
fetch = -1
|
||||
print 'New Blocklist required...'
|
||||
|
||||
# If blocklist doesnt exist
|
||||
except OSError, e:
|
||||
pass
|
||||
|
||||
# Attempt initial import
|
||||
if fetch:
|
||||
if fetch == -1:
|
||||
print "Fetching",self.config.get('url')
|
||||
self.gtkprog.start_download()
|
||||
try:
|
||||
@ -144,16 +162,16 @@ class BlocklistImport:
|
||||
def configure(self, window):
|
||||
self.gtkconf.start(self.config.get('listtype'),
|
||||
self.config.get('url'),
|
||||
self.config.get('load_on_start'),
|
||||
self.config.get('load_after_days'),
|
||||
window)
|
||||
|
||||
def setconfig(self, url, load_on_start, listtype):
|
||||
def setconfig(self, url, load_after_days, listtype):
|
||||
self.config.set('url', url)
|
||||
self.config.set('load_on_start', load_on_start)
|
||||
self.config.set('load_after_days', load_after_days)
|
||||
self.config.set('listtype', listtype)
|
||||
self.config.save()
|
||||
|
||||
self.loadlist(fetch=True)
|
||||
self.loadlist()
|
||||
|
||||
def disable(self):
|
||||
self.core.reset_ip_filter()
|
||||
|
@ -41,14 +41,29 @@ class GTKConfig(gtk.Dialog):
|
||||
|
||||
hbox = gtk.HBox(False, 6)
|
||||
hbox.pack_start(label)
|
||||
hbox.pack_start(self.url)
|
||||
hbox.pack_end(self.url, expand=True, fill=True)
|
||||
|
||||
self.vbox.pack_start(self.listtype)
|
||||
self.vbox.pack_start(hbox)
|
||||
|
||||
# Load on start
|
||||
self.load_on_start = gtk.CheckButton(_("Download on start"))
|
||||
self.vbox.pack_start(self.load_on_start)
|
||||
# gtk.SpinButton(adjustment=None, climb_rate=0.0, digits=0)
|
||||
label2 = gtk.Label()
|
||||
label2.set_markup('<b>' + _("Download new blocklist every") + '</b>')
|
||||
|
||||
self.load_after_days = gtk.SpinButton(None, 1.0, 0)
|
||||
self.load_after_days.set_increments(1, 3)
|
||||
self.load_after_days.set_range(-1, 14)
|
||||
|
||||
label3 = gtk.Label()
|
||||
label3.set_markup('<b>' + _("days") + '</b>')
|
||||
|
||||
hbox2 = gtk.HBox(False, 6)
|
||||
hbox2.pack_start(label2)
|
||||
hbox2.pack_start(self.load_after_days)
|
||||
hbox2.pack_start(label3)
|
||||
|
||||
self.vbox.pack_start(hbox2)
|
||||
|
||||
self.connect('response', self.ok)
|
||||
self.connect('close', self.cancel)
|
||||
@ -67,9 +82,9 @@ class GTKConfig(gtk.Dialog):
|
||||
ls = self.listtype.get_model()
|
||||
ltype = ls[self.listtype.get_active()][1]
|
||||
url = self.url.get_text()
|
||||
los = self.load_on_start.get_active()
|
||||
days = self.load_after_days.get_value()
|
||||
|
||||
self.plugin.setconfig(url, los, ltype)
|
||||
self.plugin.setconfig(url, days, ltype)
|
||||
|
||||
|
||||
def cancel(self, dialog, signal=None):
|
||||
@ -77,7 +92,7 @@ class GTKConfig(gtk.Dialog):
|
||||
if signal:
|
||||
return True
|
||||
|
||||
def start(self, ltype, url, load, window):
|
||||
def start(self, ltype, url, days, window):
|
||||
self.set_transient_for(window)
|
||||
if ltype:
|
||||
path = BlocklistImport.readers[ltype][2]
|
||||
@ -87,8 +102,8 @@ class GTKConfig(gtk.Dialog):
|
||||
if url:
|
||||
self.url.set_text(url)
|
||||
|
||||
if load:
|
||||
self.load_on_start.set_active(load)
|
||||
if days:
|
||||
self.load_after_days.set_value(days)
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user