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