mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-20 07:08:30 +00:00
remove plugin preference page properly, handle downloads/timeouts better, fixed inf download loop
This commit is contained in:
parent
174ea3c35e
commit
87e7fd5869
@ -33,14 +33,12 @@
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
|
||||
import deluge.component
|
||||
from torrentblocklist import TorrentBlockList
|
||||
from deluge.log import LOG as log
|
||||
from deluge.plugins.corepluginbase import CorePluginBase
|
||||
|
||||
class Core(CorePluginBase):
|
||||
def enable(self):
|
||||
deluge.component.get("Core").session.set_max_connections(0)
|
||||
self.blocklist = TorrentBlockList(self.plugin)
|
||||
self.plugin.register_hook("post_session_load", self._post_session_load)
|
||||
log.debug('Blocklist: Plugin enabled..')
|
||||
|
@ -71,6 +71,7 @@ class GtkUI(ui.UI):
|
||||
def disable(self):
|
||||
deluge.component.get("StatusBar").remove_item(self.blocklist_status)
|
||||
self.plugin.deregister_hook("on_apply_prefs", self.apply_prefs)
|
||||
self.plugin.remove_preferences_page("Blocklist")
|
||||
|
||||
def get_pixmap(self, fname):
|
||||
"""Returns a pixmap file included with plugin"""
|
||||
|
@ -42,8 +42,9 @@
|
||||
import urllib2, httplib, socket, os, datetime, sys
|
||||
import deluge.common
|
||||
import deluge.component # for libtorrent session reference to change connection number
|
||||
import deluge.configmanager # used to retrieve max_global_connections
|
||||
from deluge.log import LOG as log
|
||||
import ui # added by Mark for pausing torrents
|
||||
#import ui # added by Mark for pausing torrents
|
||||
from peerguardian import PGReader, PGException
|
||||
from text import TextReader, GZMuleReader, PGZip
|
||||
|
||||
@ -76,8 +77,7 @@ class HTTPConnection(httplib.HTTPConnection):
|
||||
self.timeout = timeout
|
||||
|
||||
def connect(self):
|
||||
"""Override HTTPConnection.connect to connect to
|
||||
host/port specified in __init__."""
|
||||
"""Override HTTPConnection.connect to connect to host/port specified in __init__."""
|
||||
|
||||
msg = "getaddrinfo returns an empty list"
|
||||
for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
|
||||
@ -129,9 +129,6 @@ class TorrentBlockList:
|
||||
# Check list for modifications from online version
|
||||
self.check_update()
|
||||
|
||||
# Initialize download attempt
|
||||
self.attempt = 0
|
||||
|
||||
if self.fetch == True:
|
||||
self.download()
|
||||
|
||||
@ -139,7 +136,6 @@ class TorrentBlockList:
|
||||
|
||||
|
||||
def load_options(self):
|
||||
#self.config.load()
|
||||
# Fill variables with settings from block list configuration file
|
||||
self.url = self.config['url']
|
||||
self.listtype = self.config['listtype']
|
||||
@ -200,7 +196,7 @@ class TorrentBlockList:
|
||||
while j < self.try_times:
|
||||
# Get current online block lists time stamp and compare it with current
|
||||
try:
|
||||
http_handler = HTTPHandler(timeout = 15)
|
||||
http_handler = HTTPHandler(timeout = self.timeout)
|
||||
opener = urllib2.build_opener(http_handler)
|
||||
request = urllib2.Request(self.url)
|
||||
|
||||
@ -211,9 +207,16 @@ class TorrentBlockList:
|
||||
remote_time = datetime.datetime.strptime(header['last-modified'],"%a, %d %b %Y %H:%M:%S GMT")
|
||||
remote_type = header['content-type']
|
||||
|
||||
except URLError, e:
|
||||
log.warning("Blocklist: Requesnt online blocklist info failed")
|
||||
j += 1
|
||||
break
|
||||
|
||||
except Exception, e:
|
||||
log.warning(e)
|
||||
# HANDLE EXCEPTOIN
|
||||
j = self.try_times
|
||||
break
|
||||
|
||||
log.debug(self.listtype)
|
||||
|
||||
@ -250,7 +253,7 @@ class TorrentBlockList:
|
||||
return
|
||||
|
||||
j+=1
|
||||
log.debug('Blocklist: 6 TRY AGAIN FOO')
|
||||
log.debug('Blocklist: TRY AGAIN FOO')
|
||||
|
||||
# Connection can't be made to check remote time stamps
|
||||
except: # && urllib2.URLError
|
||||
@ -264,18 +267,23 @@ class TorrentBlockList:
|
||||
|
||||
def download(self):
|
||||
log.info('Blocklist: Beginning download')
|
||||
self.attempt += 1
|
||||
|
||||
i = 0
|
||||
while i < self.try_times:
|
||||
success = False
|
||||
|
||||
while i < self.try_times or success == False:
|
||||
# Download a new block list
|
||||
try:
|
||||
log.info('Blocklist: Downloading new list...')
|
||||
http_handler = HTTPHandler(timeout = 15)
|
||||
http_handler = HTTPHandler(timeout = self.timeout)
|
||||
opener = urllib2.build_opener(http_handler)
|
||||
request = urllib2.Request(self.url)
|
||||
new_list = opener.open(request)
|
||||
new_list = opener.open(request)
|
||||
|
||||
file = open(deluge.common.get_config_dir("blocklist.cache"), 'w')
|
||||
log.info('Blocklist: Writing blocklist to disk')
|
||||
|
||||
# Write new blocklist to disk
|
||||
while 1:
|
||||
data = new_list.read()
|
||||
if not len(data):
|
||||
@ -288,7 +296,7 @@ class TorrentBlockList:
|
||||
return
|
||||
|
||||
except:
|
||||
if self.attempt > self.try_times:
|
||||
if i > self.try_times:
|
||||
log.warning('Blocklist: All download attempts failed')
|
||||
return
|
||||
|
||||
@ -297,15 +305,19 @@ class TorrentBlockList:
|
||||
i += 1
|
||||
|
||||
# CHECKSUM
|
||||
|
||||
log.info('Blocklist: List downloaded sucessfully')
|
||||
success = True
|
||||
break
|
||||
# end while loop
|
||||
|
||||
log.info('Blocklist: List downloaded sucessfully')
|
||||
# Download completed
|
||||
|
||||
|
||||
def import_list(self):
|
||||
log.info('Blocklist: Importing list...')
|
||||
# During import, disable remote connections by setting max to 0
|
||||
deluge.component.get("Core").session.set_max_connections(0)
|
||||
|
||||
#TODO: Dont need try anymore
|
||||
try:
|
||||
self.plugin.reset_ip_filter()
|
||||
self.curr = 0
|
||||
@ -325,7 +337,6 @@ class TorrentBlockList:
|
||||
|
||||
try:
|
||||
ips = read_list.next()
|
||||
print ips
|
||||
|
||||
while ips:
|
||||
self.plugin.block_ip_range(ips)
|
||||
@ -339,11 +350,12 @@ class TorrentBlockList:
|
||||
log.debug('Blocklist: Problem with list, re-download')
|
||||
return
|
||||
|
||||
# Throw exception if curr = 0 reset critical settings
|
||||
# If experiencing an unrecoverable error, reset critical settings (url, listtype)
|
||||
if self.curr == 0:
|
||||
log.warning("Blocklist: Improper list read")
|
||||
self.reset_critical_settings()
|
||||
else:
|
||||
|
||||
else: # Sucessful import
|
||||
deluge.component.get("Core").session.set_max_connections(deluge.configmanager.ConfigManager("core.conf")["max_connections_global"])
|
||||
log.info('Blocklist: Import completed sucessfully')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user