summaryrefslogtreecommitdiffstats
path: root/pyload/plugin/addon
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugin/addon')
-rw-r--r--pyload/plugin/addon/AndroidPhoneNotify.py93
-rw-r--r--pyload/plugin/addon/Checksum.py36
-rw-r--r--pyload/plugin/addon/ClickAndLoad.py65
-rw-r--r--pyload/plugin/addon/DeleteFinished.py47
-rw-r--r--pyload/plugin/addon/DownloadScheduler.py15
-rw-r--r--pyload/plugin/addon/ExternalScripts.py201
-rw-r--r--pyload/plugin/addon/ExtractArchive.py171
-rw-r--r--pyload/plugin/addon/HotFolder.py12
-rw-r--r--pyload/plugin/addon/IRCInterface.py30
-rw-r--r--pyload/plugin/addon/JustPremium.py32
-rw-r--r--pyload/plugin/addon/MergeFiles.py4
-rw-r--r--pyload/plugin/addon/MultiHome.py14
-rw-r--r--pyload/plugin/addon/RestartFailed.py31
-rw-r--r--pyload/plugin/addon/RestartSlow.py9
-rw-r--r--pyload/plugin/addon/SkipRev.py81
-rw-r--r--pyload/plugin/addon/UnSkipOnFail.py7
-rw-r--r--pyload/plugin/addon/UpdateManager.py283
-rw-r--r--pyload/plugin/addon/WindowsPhoneNotify.py93
-rw-r--r--pyload/plugin/addon/XMPPInterface.py14
19 files changed, 730 insertions, 508 deletions
diff --git a/pyload/plugin/addon/AndroidPhoneNotify.py b/pyload/plugin/addon/AndroidPhoneNotify.py
index 2b4f8fcca..53af8aa1c 100644
--- a/pyload/plugin/addon/AndroidPhoneNotify.py
+++ b/pyload/plugin/addon/AndroidPhoneNotify.py
@@ -1,55 +1,74 @@
# -*- coding: utf-8 -*-
-from time import time
+import time
from pyload.network.RequestFactory import getURL
-from pyload.plugin.Addon import Addon
+from pyload.plugin.Addon import Addon, Expose
class AndroidPhoneNotify(Addon):
__name__ = "AndroidPhoneNotify"
__type__ = "addon"
- __version__ = "0.05"
+ __version__ = "0.07"
__config__ = [("apikey" , "str" , "API key" , "" ),
("notifycaptcha" , "bool", "Notify captcha request" , True ),
("notifypackage" , "bool", "Notify package finished" , True ),
- ("notifyprocessed", "bool", "Notify processed packages status" , True ),
- ("timeout" , "int" , "Timeout between captchas in seconds" , 5 ),
- ("force" , "bool", "Send notifications if client is connected", False)]
-
- __description__ = """Send push notifications to your Android Phone using notifymyandroid.com"""
+ ("notifyprocessed", "bool", "Notify packages processed" , True ),
+ ("notifyupdate" , "bool", "Notify plugin updates" , True ),
+ ("notifyexit" , "bool", "Notify pyLoad shutdown" , True ),
+ ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ),
+ ("sendpermin" , "int" , "Max notifications per minute" , 12 ),
+ ("ignoreclient" , "bool", "Send notifications if client is connected", False)]
+
+ __description__ = """Send push notifications to your Android Phone (using notifymyandroid.com)"""
__license__ = "GPLv3"
- __authors__ = [("Steven Kosyra", "steven.kosyra@gmail.com"),
- ("Walter Purcaro", "vuolter@gmail.com")]
+ __authors__ = [("Steven Kosyra" , "steven.kosyra@gmail.com"),
+ ("Walter Purcaro", "vuolter@gmail.com" )]
- event_list = ["allDownloadsProcessed"]
+ event_list = ["allDownloadsProcessed", "plugin_updated"]
+ interval = 0 #@TODO: Remove in 0.4.10
def setup(self):
- self.info = {} #@TODO: Remove in 0.4.10
- self.last_notify = 0
+ self.info = {} #@TODO: Remove in 0.4.10
+ self.last_notify = 0
+ self.notifications = 0
- def newCaptchaTask(self, task):
- if not self.getConfig("notifycaptcha"):
- return False
+ def plugin_updated(self, type_plugins):
+ if not self.getConfig('notifyupdate'):
+ return
+
+ self.notify(_("Plugins updated"), str(type_plugins))
+
+
+ def coreExiting(self):
+ if not self.getConfig('notifyexit'):
+ return
+
+ if self.core.do_restart:
+ self.notify(_("Restarting pyLoad"))
+ else:
+ self.notify(_("Exiting pyLoad"))
- if time() - self.last_notify < self.getConf("timeout"):
- return False
+
+ def newCaptchaTask(self, task):
+ if not self.getConfig('notifycaptcha'):
+ return
self.notify(_("Captcha"), _("New request waiting user input"))
def packageFinished(self, pypack):
- if self.getConfig("notifypackage"):
+ if self.getConfig('notifypackage'):
self.notify(_("Package finished"), pypack.name)
def allDownloadsProcessed(self):
- if not self.getConfig("notifyprocessed"):
- return False
+ if not self.getConfig('notifyprocessed'):
+ return
if any(True for pdata in self.core.api.getQueue() if pdata.linksdone < pdata.linkstotal):
self.notify(_("Package failed"), _("One or more packages was not completed successfully"))
@@ -57,19 +76,35 @@ class AndroidPhoneNotify(Addon):
self.notify(_("All packages finished"))
- def notify(self, event, msg=""):
- apikey = self.getConfig("apikey")
+ @Expose
+ def notify(self,
+ event,
+ msg="",
+ key=self.getConfig('apikey')):
+
+ if not key:
+ return
+
+ if self.core.isClientConnected() and not self.getConfig('ignoreclient'):
+ return
+
+ elapsed_time = time.time() - self.last_notify
+
+ if elapsed_time < self.getConf("sendtimewait"):
+ return
+
+ if elapsed_time > 60:
+ self.notifications = 0
- if not apikey:
- return False
+ elif self.notifications >= self.getConf("sendpermin"):
+ return
- if self.core.isClientConnected() and not self.getConfig("force"):
- return False
getURL("http://www.notifymyandroid.com/publicapi/notify",
- get={'apikey' : apikey,
+ get={'apikey' : key,
'application': "pyLoad",
'event' : event,
'description': msg})
- self.last_notify = time()
+ self.last_notify = time.time()
+ self.notifications += 1
diff --git a/pyload/plugin/addon/Checksum.py b/pyload/plugin/addon/Checksum.py
index a45e21812..7ba5d7ab6 100644
--- a/pyload/plugin/addon/Checksum.py
+++ b/pyload/plugin/addon/Checksum.py
@@ -51,29 +51,33 @@ class Checksum(Addon):
__description__ = """Verify downloaded file size and checksum"""
__license__ = "GPLv3"
- __authors__ = [("zoidberg", "zoidberg@mujmail.cz"),
- ("Walter Purcaro", "vuolter@gmail.com"),
- ("stickell", "l.stickell@yahoo.it")]
+ __authors__ = [("zoidberg" , "zoidberg@mujmail.cz"),
+ ("Walter Purcaro", "vuolter@gmail.com" ),
+ ("stickell" , "l.stickell@yahoo.it")]
- methods = {'sfv' : 'crc32',
- 'crc' : 'crc32',
- 'hash': 'md5'}
- regexps = {'sfv' : r'^(?P<NAME>[^;].+)\s+(?P<HASH>[0-9A-Fa-f]{8})$',
- 'md5' : r'^(?P<NAME>[0-9A-Fa-f]{32}) (?P<FILE>.+)$',
- 'crc' : r'filename=(?P<NAME>.+)\nsize=(?P<SIZE>\d+)\ncrc32=(?P<HASH>[0-9A-Fa-f]{8})$',
- 'default': r'^(?P<HASH>[0-9A-Fa-f]+)\s+\*?(?P<NAME>.+)$'}
+ interval = 0 #@TODO: Remove in 0.4.10
+ methods = {'sfv' : 'crc32',
+ 'crc' : 'crc32',
+ 'hash': 'md5'}
+ regexps = {'sfv' : r'^(?P<NAME>[^;].+)\s+(?P<HASH>[0-9A-Fa-f]{8})$',
+ 'md5' : r'^(?P<NAME>[0-9A-Fa-f]{32}) (?P<FILE>.+)$',
+ 'crc' : r'filename=(?P<NAME>.+)\nsize=(?P<SIZE>\d+)\ncrc32=(?P<HASH>[0-9A-Fa-f]{8})$',
+ 'default': r'^(?P<HASH>[0-9A-Fa-f]+)\s+\*?(?P<NAME>.+)$'}
def activate(self):
- if not self.getConfig("check_checksum"):
+ if not self.getConfig('check_checksum'):
self.logInfo(_("Checksum validation is disabled in plugin configuration"))
def setup(self):
+ self.info = {} #@TODO: Remove in 0.4.10
self.algorithms = sorted(
getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse=True)
+
self.algorithms.extend(["crc32", "adler32"])
+
self.formats = self.algorithms + ["sfv", "crc", "hash"]
@@ -121,7 +125,7 @@ class Checksum(Addon):
data.pop('size', None)
# validate checksum
- if data and self.getConfig("check_checksum"):
+ if data and self.getConfig('check_checksum'):
if not 'md5' in data:
for type in ("checksum", "hashsum", "hash"):
@@ -148,14 +152,14 @@ class Checksum(Addon):
def checkFailed(self, pyfile, local_file, msg):
- check_action = self.getConfig("check_action")
+ check_action = self.getConfig('check_action')
if check_action == "retry":
- max_tries = self.getConfig("max_tries")
- retry_action = self.getConfig("retry_action")
+ max_tries = self.getConfig('max_tries')
+ retry_action = self.getConfig('retry_action')
if pyfile.plugin.retries < max_tries:
if local_file:
remove(local_file)
- pyfile.plugin.retry(max_tries, self.getConfig("wait_time"), msg)
+ pyfile.plugin.retry(max_tries, self.getConfig('wait_time'), msg)
elif retry_action == "nothing":
return
elif check_action == "nothing":
diff --git a/pyload/plugin/addon/ClickAndLoad.py b/pyload/plugin/addon/ClickAndLoad.py
index 728580cac..63647e30a 100644
--- a/pyload/plugin/addon/ClickAndLoad.py
+++ b/pyload/plugin/addon/ClickAndLoad.py
@@ -17,30 +17,34 @@ def forward(source, destination):
bufdata = source.recv(bufsize)
finally:
destination.shutdown(socket.SHUT_WR)
+ # destination.close()
#@TODO: IPv6 support
class ClickAndLoad(Addon):
__name__ = "ClickAndLoad"
__type__ = "addon"
- __version__ = "0.37"
+ __version__ = "0.41"
__config__ = [("activated", "bool", "Activated" , True),
- ("port" , "int" , "Port" , 9666),
- ("extern" , "bool", "Listen on the public network interface", True)]
+ ("port" , "int" , "Port" , 9666),
+ ("extern" , "bool", "Listen on the public network interface", True)]
- __description__ = """Click'N'Load addon plugin"""
+ __description__ = """Click'n'Load hook plugin"""
__license__ = "GPLv3"
- __authors__ = [("RaNaN", "RaNaN@pyload.de"),
+ __authors__ = [("RaNaN" , "RaNaN@pyload.de" ),
("Walter Purcaro", "vuolter@gmail.com")]
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
def activate(self):
if not self.config['webinterface']['activated']:
return
- ip = "" if self.getConfig("extern") else "127.0.0.1"
- webport = int(self.config['webinterface']['port'])
+ ip = "" if self.getConfig('extern') else "127.0.0.1"
+ webport = self.config['webinterface']['port']
cnlport = self.getConfig('port')
self.proxy(ip, webport, cnlport)
@@ -48,40 +52,39 @@ class ClickAndLoad(Addon):
@threaded
def proxy(self, ip, webport, cnlport):
- self.logInfo(_("Proxy listening on %s:%s") % (ip, cnlport))
- self.manager.startThread(self._server, ip, webport, cnlport)
+ time.sleep(10) #@TODO: Remove in 0.4.10 (implement addon delay on startup)
+
+ self.logInfo(_("Proxy listening on %s:%s") % (ip or "0.0.0.0", cnlport))
+
+ self._server(ip, webport, cnlport)
+
lock = Lock()
lock.acquire()
lock.acquire()
- def _server(self, ip, webport, cnlport, thread):
+ @threaded
+ def _server(self, ip, webport, cnlport):
try:
- try:
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-
- server_socket.bind((ip, cnlport))
- server_socket.listen(5)
+ dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ dock_socket.bind((ip, cnlport))
+ dock_socket.listen(5)
- while True:
- client_socket = server_socket.accept()[0]
- dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ while True:
+ client_socket, client_addr = dock_socket.accept()
+ self.logDebug("Connection from %s:%s" % client_addr)
- dock_socket.connect(("127.0.0.1", webport))
-
- self.manager.startThread(forward, dock_socket, client_socket)
- self.manager.startThread(forward, client_socket, dock_socket)
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ server_socket.connect(("127.0.0.1", webport))
- except socket.timeout:
- self.logDebug("Connection timed out, retrying...")
- return self._server(ip, webport, cnlport, thread)
+ self.manager.startThread(forward, client_socket, server_socket)
+ self.manager.startThread(forward, server_socket, client_socket)
- finally:
- server_socket.close()
- client_socket.close()
- dock_socket.close()
+ except socket.timeout:
+ self.logDebug("Connection timed out, retrying...")
+ return self._server(ip, webport, cnlport)
except socket.error, e:
self.logError(e)
- time.sleep(120)
- self._server(ip, webport, cnlport, thread)
+ time.sleep(240)
+ return self._server(ip, webport, cnlport)
diff --git a/pyload/plugin/addon/DeleteFinished.py b/pyload/plugin/addon/DeleteFinished.py
index 59f2e3321..aad05891e 100644
--- a/pyload/plugin/addon/DeleteFinished.py
+++ b/pyload/plugin/addon/DeleteFinished.py
@@ -7,10 +7,11 @@ from pyload.plugin.Addon import Addon
class DeleteFinished(Addon):
__name__ = "DeleteFinished"
__type__ = "addon"
- __version__ = "1.11"
+ __version__ = "1.12"
- __config__ = [('interval' , 'int' , 'Delete every (hours)' , '72' ),
- ('deloffline', 'bool', 'Delete packages with offline links', 'False')]
+ __config__ = [("activated" , "bool", "Activated" , "False"),
+ ("interval" , "int" , "Delete every (hours)" , "72" ),
+ ("deloffline", "bool", "Delete packages with offline links", "False")]
__description__ = """Automatically delete all finished packages from queue"""
__license__ = "GPLv3"
@@ -19,8 +20,15 @@ class DeleteFinished(Addon):
# event_list = ["pluginConfigChanged"]
+ MIN_CHECK_INTERVAL = 1 * 60 * 60 #: 1 hour
+
## overwritten methods ##
+ def setup(self):
+ self.info = {} #@TODO: Remove in 0.4.10
+ self.interval = self.MIN_CHECK_INTERVAL
+
+
def periodical(self):
if not self.info['sleep']:
deloffline = self.getConfig('deloffline')
@@ -32,20 +40,21 @@ class DeleteFinished(Addon):
self.addEvent('packageFinished', self.wakeup)
- def pluginConfigChanged(self, plugin, name, value):
- if name == "interval" and value != self.interval:
- self.interval = value * 3600
- self.initPeriodical()
+ # def pluginConfigChanged(self, plugin, name, value):
+ # if name == "interval" and value != self.interval:
+ # self.interval = value * 3600
+ # self.initPeriodical()
def deactivate(self):
- self.removeEvent('packageFinished', self.wakeup)
+ self.manager.removeEvent('packageFinished', self.wakeup)
def activate(self):
- self.info = {'sleep': True}
- interval = self.getConfig('interval')
- self.pluginConfigChanged(self.__name__, 'interval', interval)
+ self.info['sleep'] = True
+ # interval = self.getConfig('interval')
+ # self.pluginConfigChanged(self.__name__, 'interval', interval)
+ self.interval = max(self.MIN_CHECK_INTERVAL, self.getConfig('interval') * 60 * 60)
self.addEvent('packageFinished', self.wakeup)
@@ -57,23 +66,17 @@ class DeleteFinished(Addon):
def wakeup(self, pypack):
- self.removeEvent('packageFinished', self.wakeup)
+ self.manager.removeEvent('packageFinished', self.wakeup)
self.info['sleep'] = False
## event managing ##
def addEvent(self, event, func):
"""Adds an event listener for event name"""
- if event in self.m.events:
- if func in self.m.events[event]:
+ if event in self.manager.events:
+ if func in self.manager.events[event]:
self.logDebug("Function already registered", func)
else:
- self.m.events[event].append(func)
+ self.manager.events[event].append(func)
else:
- self.m.events[event] = [func]
-
-
- def setup(self):
- self.interval = 0
- self.m = self.manager
- self.removeEvent = self.m.removeEvent
+ self.manager.events[event] = [func]
diff --git a/pyload/plugin/addon/DownloadScheduler.py b/pyload/plugin/addon/DownloadScheduler.py
index e5e25e389..ff65a478d 100644
--- a/pyload/plugin/addon/DownloadScheduler.py
+++ b/pyload/plugin/addon/DownloadScheduler.py
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
import re
-
-from time import localtime
+import time
from pyload.plugin.Addon import Addon
@@ -21,8 +20,12 @@ class DownloadScheduler(Addon):
("stickell", "l.stickell@yahoo.it")]
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
def setup(self):
- self.cb = None #: callback to scheduler job; will be by removed AddonManager when addon unloaded
+ self.info = {} #@TODO: Remove in 0.4.10
+ self.cb = None # callback to scheduler job; will be by removed hookmanager when hook unloaded
def activate(self):
@@ -31,7 +34,7 @@ class DownloadScheduler(Addon):
def updateSchedule(self, schedule=None):
if schedule is None:
- schedule = self.getConfig("timetable")
+ schedule = self.getConfig('timetable')
schedule = re.findall("(\d{1,2}):(\d{2})[\s]*(-?\d+)",
schedule.lower().replace("full", "-1").replace("none", "0"))
@@ -39,7 +42,7 @@ class DownloadScheduler(Addon):
self.logError(_("Invalid schedule"))
return
- t0 = localtime()
+ t0 = time.localtime()
now = (t0.tm_hour, t0.tm_min, t0.tm_sec, "X")
schedule = sorted([(int(x[0]), int(x[1]), 0, int(x[2])) for x in schedule] + [now])
@@ -59,7 +62,7 @@ class DownloadScheduler(Addon):
def setDownloadSpeed(self, speed):
if speed == 0:
- abort = self.getConfig("abort")
+ abort = self.getConfig('abort')
self.logInfo(_("Stopping download server. (Running downloads will %sbe aborted.)") % '' if abort else _('not '))
self.core.api.pauseServer()
if abort:
diff --git a/pyload/plugin/addon/ExternalScripts.py b/pyload/plugin/addon/ExternalScripts.py
index 3d490a1f5..139be1299 100644
--- a/pyload/plugin/addon/ExternalScripts.py
+++ b/pyload/plugin/addon/ExternalScripts.py
@@ -3,148 +3,215 @@
import os
import subprocess
-from itertools import chain
-
from pyload.plugin.Addon import Addon
-from pyload.utils import fs_join
+from pyload.utils import fs_encode, fs_join
class ExternalScripts(Addon):
__name__ = "ExternalScripts"
__type__ = "addon"
- __version__ = "0.29"
+ __version__ = "0.37"
__config__ = [("activated", "bool", "Activated" , True ),
- ("wait" , "bool", "Wait script ending", False)]
+ ("waitend" , "bool", "Wait script ending", False)]
__description__ = """Run external scripts"""
__license__ = "GPLv3"
- __authors__ = [("mkaay", "mkaay@mkaay.de"),
- ("RaNaN", "ranan@pyload.org"),
- ("spoob", "spoob@pyload.org"),
- ("Walter Purcaro", "vuolter@gmail.com")]
+ __authors__ = [("mkaay" , "mkaay@mkaay.de" ),
+ ("RaNaN" , "ranan@pyload.org" ),
+ ("spoob" , "spoob@pyload.org" ),
+ ("Walter Purcaro", "vuolter@gmail.com")]
- event_map = {'archive-extracted' : "archive_extracted",
- 'package-extracted' : "package_extracted",
- 'all_archives-extracted' : "all_archives_extracted",
- 'all_archives-processed' : "all_archives_processed",
- 'all_downloads-finished' : "allDownloadsFinished",
- 'all_downloads-processed': "allDownloadsProcessed"}
+ event_list = ["archive_extract_failed", "archive_extracted" ,
+ "package_extract_failed", "package_extracted" ,
+ "all_archives_extracted", "all_archives_processed",
+ "allDownloadsFinished" , "allDownloadsProcessed" ,
+ "packageDeleted"]
+ interval = 0 #@TODO: Remove in 0.4.10
def setup(self):
+ self.info = {'oldip': None}
self.scripts = {}
- folders = ["download_preparing", "download_finished", "all_downloads_finished", "all_downloads_processed",
+ folders = ["pyload_start", "pyload_restart", "pyload_stop",
"before_reconnect", "after_reconnect",
- "package_finished", "package_extracted",
- "archive_extracted", "all_archives_extracted", "all_archives_processed",
- # deprecated folders
- "unrar_finished", "all_dls_finished", "all_dls_processed"]
+ "download_preparing", "download_failed", "download_finished",
+ "archive_extract_failed", "archive_extracted",
+ "package_finished", "package_deleted", "package_extract_failed", "package_extracted",
+ "all_downloads_processed", "all_downloads_finished", #@TODO: Invert `all_downloads_processed`, `all_downloads_finished` order in 0.4.10
+ "all_archives_extracted", "all_archives_processed"]
for folder in folders:
self.scripts[folder] = []
-
- self.initPluginType(folder, os.path.join(pypath, 'scripts', folder))
- self.initPluginType(folder, os.path.join('scripts', folder))
+ for dir in (pypath, ''):
+ self.initPluginType(folder, os.path.join(dir, 'scripts', folder))
for script_type, names in self.scripts.iteritems():
if names:
- self.logInfo(_("Installed scripts for"), script_type, ", ".join(map(os.path.basename, names)))
+ self.logInfo(_("Installed scripts for: ") + script_type, ", ".join(map(os.path.basename, names)))
+ self.pyload_start()
- def initPluginType(self, folder, path):
- if not os.path.exists(path):
+
+ def initPluginType(self, name, dir):
+ if not os.path.isdir(dir):
try:
- os.makedirs(path)
+ os.makedirs(dir)
- except Exception:
- self.logDebug("Script folder %s not created" % folder)
+ except OSError, e:
+ self.logDebug(e)
return
- for f in os.listdir(path):
- if f.startswith("#") or f.startswith(".") or f.startswith("_") or f.endswith("~") or f.endswith(".swp"):
+ for filename in os.listdir(dir):
+ file = save_join(dir, filename)
+
+ if not os.path.isfile(file):
+ continue
+
+ if filename[0] in ("#", "_") or filename.endswith("~") or filename.endswith(".swp"):
continue
- if not os.access(os.path.join(path, f), os.X_OK):
- self.logWarning(_("Script not executable:") + " %s/%s" % (folder, f))
+ if not os.access(file, os.X_OK):
+ self.logWarning(_("Script not executable:") + " %s/%s" % (name, filename))
- self.scripts[folder].append(os.path.join(path, f))
+ self.scripts[name].append(file)
def callScript(self, script, *args):
try:
- cmd = [script] + [str(x) if not isinstance(x, basestring) else x for x in args]
+ cmd_args = [fs_encode(str(x) if not isinstance(x, basestring) else x) for x in args]
+ cmd = [script] + cmd_args
- self.logDebug("Executing", os.path.abspath(script), " ".join(cmd))
+ self.logDebug("Executing: %s" % os.path.abspath(script), "Args: " + ' '.join(cmd_args))
p = subprocess.Popen(cmd, bufsize=-1) #@NOTE: output goes to pyload
- if self.getConfig('wait'):
+ if self.getConfig('waitend'):
p.communicate()
except Exception, e:
- self.logError(_("Error in %(script)s: %(error)s") % {"script": os.path.basename(script), "error": e})
+ try:
+ self.logError(_("Runtime error: %s") % os.path.abspath(script), e)
+ except Exception:
+ self.logError(_("Runtime error: %s") % os.path.abspath(script), _("Unknown error"))
+
+
+ def pyload_start(self):
+ for script in self.scripts['pyload_start']:
+ self.callScript(script)
+
+
+ def coreExiting(self):
+ for script in self.scripts['pyload_restart' if self.core.do_restart else 'pyload_stop']:
+ self.callScript(script)
+
+
+ def beforeReconnecting(self, ip):
+ for script in self.scripts['before_reconnect']:
+ self.callScript(script, ip)
+ self.info['oldip'] = ip
+
+
+ def afterReconnecting(self, ip):
+ for script in self.scripts['after_reconnect']:
+ self.callScript(script, ip, self.info['oldip']) #@TODO: Use built-in oldip in 0.4.10
def downloadPreparing(self, pyfile):
for script in self.scripts['download_preparing']:
- self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.id)
+ self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, None)
+
+
+ def downloadFailed(self, pyfile):
+ if self.config['general']['folder_per_package']:
+ download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder)
+ else:
+ download_folder = self.config['general']['download_folder']
+
+ for script in self.scripts['download_failed']:
+ file = save_join(download_folder, pyfile.name)
+ self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file)
def downloadFinished(self, pyfile):
- download_folder = self.config['general']['download_folder']
+ if self.config['general']['folder_per_package']:
+ download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder)
+ else:
+ download_folder = self.config['general']['download_folder']
+
for script in self.scripts['download_finished']:
- filename = fs_join(download_folder, pyfile.package().folder, pyfile.name)
- self.callScript(script, pyfile.pluginname, pyfile.url, pyfile.name, filename, pyfile.id)
+ file = save_join(download_folder, pyfile.name)
+ self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file)
+
+
+ def archive_extract_failed(self, pyfile, archive):
+ for script in self.scripts['archive_extract_failed']:
+ self.callScript(script, pyfile.id, pyfile.name, archive.out, archive.filename, archive.files)
+
+
+ def archive_extracted(self, pyfile, archive):
+ for script in self.scripts['archive_extracted']:
+ self.callScript(script, pyfile.id, pyfile.name, archive.out, archive.filename, archive.files)
def packageFinished(self, pypack):
- download_folder = self.config['general']['download_folder']
+ if self.config['general']['folder_per_package']:
+ download_folder = save_join(self.config['general']['download_folder'], pypack.folder)
+ else:
+ download_folder = self.config['general']['download_folder']
+
for script in self.scripts['package_finished']:
- folder = fs_join(download_folder, pypack.folder)
- self.callScript(script, pypack.name, folder, pypack.password, pypack.id)
+ self.callScript(script, pypack.id, pypack.name, download_folder)
- def beforeReconnecting(self, ip):
- for script in self.scripts['before_reconnect']:
- self.callScript(script, ip)
+ def packageDeleted(self, pid):
+ pack = self.core.api.getPackageInfo(pid)
+ if self.config['general']['folder_per_package']:
+ download_folder = save_join(self.config['general']['download_folder'], pack.folder)
+ else:
+ download_folder = self.config['general']['download_folder']
- def afterReconnecting(self, ip):
- for script in self.scripts['after_reconnect']:
- self.callScript(script, ip)
+ for script in self.scripts['package_deleted']:
+ self.callScript(script, pack.id, pack.name, download_folder)
- def archive_extracted(self, pyfile, folder, filename, files):
- for script in self.scripts['archive_extracted']:
- self.callScript(script, folder, filename, files)
- for script in self.scripts['unrar_finished']: #: deprecated
- self.callScript(script, folder, filename)
+ def package_extract_failed(self, pypack):
+ if self.config['general']['folder_per_package']:
+ download_folder = save_join(self.config['general']['download_folder'], pypack.folder)
+ else:
+ download_folder = self.config['general']['download_folder']
+
+ for script in self.scripts['package_extract_failed']:
+ self.callScript(script, pypack.id, pypack.name, download_folder)
def package_extracted(self, pypack):
- download_folder = self.config['general']['download_folder']
+ if self.config['general']['folder_per_package']:
+ download_folder = save_join(self.config['general']['download_folder'], pypack.folder)
+ else:
+ download_folder = self.config['general']['download_folder']
+
for script in self.scripts['package_extracted']:
- folder = fs_join(download_folder, pypack.folder)
- self.callScript(script, pypack.name, folder, pypack.password, pypack.id)
+ self.callScript(script, pypack.id, pypack.name, download_folder)
- def all_archives_extracted(self):
- for script in self.scripts['all_archives_extracted']:
+ def allDownloadsFinished(self):
+ for script in self.scripts['all_downloads_finished']:
self.callScript(script)
- def all_archives_processed(self):
- for script in self.scripts['all_archives_processed']:
+ def allDownloadsProcessed(self):
+ for script in self.scripts['all_downloads_processed']:
self.callScript(script)
- def allDownloadsFinished(self):
- for script in chain(self.scripts['all_downloads_finished'], self.scripts['all_dls_finished']):
+ def all_archives_extracted(self):
+ for script in self.scripts['all_archives_extracted']:
self.callScript(script)
- def allDownloadsProcessed(self):
- for script in chain(self.scripts['all_downloads_processed'], self.scripts['all_dls_processed']):
+ def all_archives_processed(self):
+ for script in self.scripts['all_archives_processed']:
self.callScript(script)
diff --git a/pyload/plugin/addon/ExtractArchive.py b/pyload/plugin/addon/ExtractArchive.py
index 337b3ea30..3c71e7e1a 100644
--- a/pyload/plugin/addon/ExtractArchive.py
+++ b/pyload/plugin/addon/ExtractArchive.py
@@ -12,8 +12,7 @@ from traceback import print_exc
# http://bugs.python.org/issue6122 , http://bugs.python.org/issue1236 , http://bugs.python.org/issue1731717
if sys.version_info < (2, 7) and os.name != "nt":
import errno
-
- from subprocess import Popen
+ import subprocess
def _eintr_retry_call(func, *args):
while True:
@@ -33,6 +32,7 @@ if sys.version_info < (2, 7) and os.name != "nt":
if self.returncode is None:
try:
pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
+
except OSError, e:
if e.errno != errno.ECHILD:
raise
@@ -43,7 +43,7 @@ if sys.version_info < (2, 7) and os.name != "nt":
self._handle_exitstatus(sts)
return self.returncode
- Popen.wait = wait
+ subprocess.Popen.wait = wait
if os.name != "nt":
from grp import getgrnam
@@ -93,35 +93,37 @@ class ArchiveQueue(object):
queue = self.get()
try:
queue.remove(item)
+
except ValueError:
pass
+
if queue == []:
return self.delete()
- return self.set(queue)
+ return self.set(queue)
class ExtractArchive(Addon):
__name__ = "ExtractArchive"
__type__ = "addon"
- __version__ = "1.30"
-
- __config__ = [("activated" , "bool" , "Activated" , True ),
- ("fullpath" , "bool" , "Extract with full paths" , True ),
- ("overwrite" , "bool" , "Overwrite files" , False ),
- ("keepbroken" , "bool" , "Try to extract broken archives" , False ),
- ("repair" , "bool" , "Repair broken archives (rar required)" , False ),
- ("test" , "bool" , "Test archive before extracting" , False ),
- ("usepasswordfile" , "bool" , "Use password file" , True ),
- ("passwordfile" , "file" , "Password file" , "archive_password.txt" ),
- ("delete" , "bool" , "Delete archive when successfully extracted", False ),
- ("subfolder" , "bool" , "Create subfolder for each package" , False ),
- ("destination" , "folder", "Extract files to folder" , "" ),
- ("extensions" , "str" , "Extract the following extensions" , "7z,bz2,bzip2,gz,gzip,lha,lzh,lzma,rar,tar,taz,tbz,tbz2,tgz,xar,xz,z,zip"),
- ("excludefiles" , "str" , "Don't extract the following files" , "*.nfo,*.DS_Store,index.dat,thumb.db" ),
- ("recursive" , "bool" , "Extract archives in archives" , True ),
- ("waitall" , "bool" , "Wait for all downloads to be finished" , False ),
- ("renice" , "int" , "CPU priority" , 0 )]
+ __version__ = "1.38"
+
+ __config__ = [("activated" , "bool" , "Activated" , True ),
+ ("fullpath" , "bool" , "Extract with full paths" , True ),
+ ("overwrite" , "bool" , "Overwrite files" , False ),
+ ("keepbroken" , "bool" , "Try to extract broken archives" , False ),
+ ("repair" , "bool" , "Repair broken archives (RAR required)" , False ),
+ ("test" , "bool" , "Test archive before extracting" , False ),
+ ("usepasswordfile", "bool" , "Use password file" , True ),
+ ("passwordfile" , "file" , "Password file" , "archive_password.txt" ),
+ ("delete" , "No;Permanent;Trash", "Delete archive after extraction" , "No" ),
+ ("subfolder" , "bool" , "Create subfolder for each package" , False ),
+ ("destination" , "folder" , "Extract files to folder" , "" ),
+ ("extensions" , "str" , "Extract archives ending with extension", "7z,bz2,bzip2,gz,gzip,lha,lzh,lzma,rar,tar,taz,tbz,tbz2,tgz,xar,xz,z,zip"),
+ ("excludefiles" , "str" , "Don't extract the following files" , "*.nfo,*.DS_Store,index.dat,thumb.db" ),
+ ("recursive" , "bool" , "Extract archives in archives" , True ),
+ ("waitall" , "bool" , "Run after all downloads was processed" , False ),
+ ("renice" , "int" , "CPU priority" , 0 )]
__description__ = """Extract different kind of archives"""
__license__ = "GPLv3"
@@ -135,6 +137,8 @@ class ExtractArchive(Addon):
def setup(self):
+ self.info = {} #@TODO: Remove in 0.4.10
+
self.queue = ArchiveQueue(self, "Queue")
self.failed = ArchiveQueue(self, "Failed")
@@ -144,6 +148,7 @@ class ExtractArchive(Addon):
self.extractors = []
self.passwords = []
self.repair = False
+ self.trash = False
def activate(self):
@@ -154,7 +159,7 @@ class ExtractArchive(Addon):
if klass.isUsable():
self.extractors.append(klass)
if klass.REPAIR:
- self.repair = self.getConfig("repair")
+ self.repair = self.getConfig('repair')
except OSError, e:
if e.errno == 2:
@@ -175,11 +180,12 @@ class ExtractArchive(Addon):
else:
self.logInfo(_("No Extract plugins activated"))
+
@threaded
- def extractQueued(self,thread):
+ def extractQueued(self, thread):
packages = self.queue.get()
while packages:
- if self.lastPackage: # called from allDownloadsProcessed
+ if self.lastPackage: #: called from allDownloadsProcessed
self.lastPackage = False
if self.extract(packages, thread): #@NOTE: check only if all gone fine, no failed reporting for now
self.manager.dispatchEvent("all_archives_extracted")
@@ -188,7 +194,7 @@ class ExtractArchive(Addon):
if self.extract(packages, thread): #@NOTE: check only if all gone fine, no failed reporting for now
pass
- packages = self.queue.get() # check for packages added during extraction
+ packages = self.queue.get() #: check for packages added during extraction
@Expose
@@ -196,7 +202,7 @@ class ExtractArchive(Addon):
""" Extract packages with given id"""
for id in ids:
self.queue.add(id)
- if not self.getConfig("waitall") and not self.extracting:
+ if not self.getConfig('waitall') and not self.extracting:
self.extractQueued()
@@ -206,7 +212,7 @@ class ExtractArchive(Addon):
def packageFinished(self, pypack):
self.queue.add(pypack.id)
- if not self.getConfig("waitall") and not self.extracting:
+ if not self.getConfig('waitall') and not self.extracting:
self.extractQueued()
@@ -216,7 +222,8 @@ class ExtractArchive(Addon):
self.extractQueued()
- def extract(self, ids, thread=None):
+ @Expose
+ def extract(self, ids, thread=None): #@TODO: Use pypack, not pid to improve method usability
if not ids:
return False
@@ -228,17 +235,17 @@ class ExtractArchive(Addon):
toList = lambda string: string.replace(' ', '').replace(',', '|').replace(';', '|').split('|')
- destination = self.getConfig("destination")
- subfolder = self.getConfig("subfolder")
- fullpath = self.getConfig("fullpath")
- overwrite = self.getConfig("overwrite")
- renice = self.getConfig("renice")
- recursive = self.getConfig("recursive")
- delete = self.getConfig("delete")
- keepbroken = self.getConfig("keepbroken")
+ destination = self.getConfig('destination')
+ subfolder = self.getConfig('subfolder')
+ fullpath = self.getConfig('fullpath')
+ overwrite = self.getConfig('overwrite')
+ renice = self.getConfig('renice')
+ recursive = self.getConfig('recursive')
+ delete = self.getConfig('delete')
+ keepbroken = self.getConfig('keepbroken')
- extensions = [x.lstrip('.').lower() for x in toList(self.getConfig("extensions"))]
- excludefiles = toList(self.getConfig("excludefiles"))
+ extensions = [x.lstrip('.').lower() for x in toList(self.getConfig('extensions'))]
+ excludefiles = toList(self.getConfig('excludefiles'))
if extensions:
self.logDebug("Use for extensions: %s" % "|.".join(extensions))
@@ -246,20 +253,20 @@ class ExtractArchive(Addon):
# reload from txt file
self.reloadPasswords()
- # dl folder
- dl = self.config['general']['download_folder']
+ download_folder = self.config['general']['download_folder']
- #iterate packages -> extractors -> targets
+ # iterate packages -> extractors -> targets
for pid in ids:
pypack = self.core.files.getPackage(pid)
if not pypack:
+ self.queue.remove(pid)
continue
self.logInfo(_("Check package: %s") % pypack.name)
# determine output folder
- out = fs_join(dl, pypack.folder, destination, "") #: force trailing slash
+ out = fs_join(download_folder, pypack.folder, destination, "") #: force trailing slash
if subfolder:
out = fs_join(out, pypack.folder)
@@ -269,7 +276,8 @@ class ExtractArchive(Addon):
matched = False
success = True
- files_ids = [(fs_join(dl, pypack.folder, pylink['name']), pylink['id'], out) for pylink in pypack.getChildren().itervalues()]
+ files_ids = dict((pylink['name'],((fs_join(download_folder, pypack.folder, pylink['name'])), pylink['id'], out)) for pylink \
+ in sorted(pypack.getChildren().itervalues(), key=lambda k: k['name'])).values() #: remove duplicates
# check as long there are unseen files
while files_ids:
@@ -294,6 +302,7 @@ class ExtractArchive(Addon):
self.logInfo(name, _("Extract to: %s") % fout)
try:
+ pyfile = self.core.files.getFile(fid)
archive = Extractor(self,
fname,
fout,
@@ -304,16 +313,24 @@ class ExtractArchive(Addon):
delete,
keepbroken,
fid)
+
+ thread.addActive(pyfile)
archive.init()
- new_files = self._extract(archive, fid, pypack.password, thread)
+ try:
+ new_files = self._extract(pyfile, archive, pypack.password)
+
+ finally:
+ thread.finishFile(pyfile)
except Exception, e:
self.logError(name, e)
success = False
continue
- files_ids.remove((fname, fid, fout)) # don't let other extractors spam log
+ # remove processed file and related multiparts from list
+ files_ids = [(fname, fid, fout) for fname, fid, fout in files_ids \
+ if fname not in archive.getDeleteFiles()]
self.logDebug("Extracted files: %s" % new_files)
self.setPermissions(new_files)
@@ -324,12 +341,11 @@ class ExtractArchive(Addon):
continue
if recursive and os.path.isfile(file):
- new_files_ids.append((filename, fid, os.path.dirname(filename))) # append as new target
+ new_files_ids.append((filename, fid, os.path.dirname(filename))) #: append as new target
- pyfile = self.core.files.getFile(fid)
- self.manager.dispatchEvent("archive_extracted", pyfile, archive.out, archive.filename, new_files)
+ self.manager.dispatchEvent("archive_extracted", pyfile, archive)
- files_ids = new_files_ids # also check extracted files
+ files_ids = new_files_ids #: also check extracted files
if matched:
if success:
@@ -357,25 +373,23 @@ class ExtractArchive(Addon):
return True if not failed else False
- def _extract(self, archive, fid, password, thread):
- pyfile = self.core.files.getFile(fid)
+ def _extract(self, pyfile, archive, password):
name = os.path.basename(archive.filename)
- thread.addActive(pyfile)
pyfile.setStatus("processing")
encrypted = False
try:
self.logDebug("Password: %s" % (password or "None provided"))
- passwords = uniqify([password] + self.getPasswords(False)) if self.getConfig("usepasswordfile") else [password]
+ passwords = uniqify([password] + self.getPasswords(False)) if self.getConfig('usepasswordfile') else [password]
for pw in passwords:
try:
- if self.getConfig("test") or self.repair:
- pyfile.setCustomStatus(_("testing"))
+ if self.getConfig('test') or self.repair:
+ pyfile.setCustomStatus(_("archive testing"))
if pw:
self.logDebug("Testing with password: %s" % pw)
pyfile.setProgress(0)
- archive.test(pw)
+ archive.verify(pw)
pyfile.setProgress(100)
else:
archive.check(pw)
@@ -395,12 +409,12 @@ class ExtractArchive(Addon):
if self.repair:
self.logWarning(name, _("Repairing..."))
- pyfile.setCustomStatus(_("repairing"))
+ pyfile.setCustomStatus(_("archive repairing"))
pyfile.setProgress(0)
repaired = archive.repair()
pyfile.setProgress(100)
- if not repaired and not self.getConfig("keepbroken"):
+ if not repaired and not self.getConfig('keepbroken'):
raise CRCError("Archive damaged")
self.addPassword(pw)
@@ -414,7 +428,7 @@ class ExtractArchive(Addon):
pyfile.setCustomStatus(_("extracting"))
pyfile.setProgress(0)
- if not encrypted or not self.getConfig("usepasswordfile"):
+ if not encrypted or not self.getConfig('usepasswordfile'):
self.logDebug("Extracting using password: %s" % (password or "None"))
archive.extract(password)
else:
@@ -432,17 +446,31 @@ class ExtractArchive(Addon):
raise PasswordError
pyfile.setProgress(100)
- pyfile.setCustomStatus(_("finalizing"))
+ pyfile.setStatus("processing")
+ delfiles = archive.getDeleteFiles()
if self.core.debug:
- self.logDebug("Would delete: %s" % ", ".join(archive.getDeleteFiles()))
+ self.logDebug("Would delete: %s" % ", ".join(delfiles))
- if self.getConfig("delete"):
- files = archive.getDeleteFiles()
- self.logInfo(_("Deleting %s files") % len(files))
- for f in files:
+ if self.getConfig('delete') != 'No':
+ try:
+ from send2trash import send2trash
+ if self.getConfig('delete') == "Trash":
+ self.trash = True
+ self.logInfo(_("Sending %s files to trash") % len(delfiles))
+ except ImportError:
+ self.logError(name, _("Send2Trash not installed, no files deleted"))
+ self.trash = False
+
+ if self.getConfig('delete') == "Permanent":
+ self.trash = False
+ self.logInfo(_("Deleting %s files") % len(delfiles))
+
+ for f in delfiles:
file = fs_encode(f)
- if os.path.exists(file):
+ if os.path.exists(file) and self.trash:
+ send2trash(file)
+ elif os.path.exists(file):
os.remove(file)
else:
self.logDebug("%s does not exists" % f)
@@ -466,10 +494,7 @@ class ExtractArchive(Addon):
if self.core.debug:
print_exc()
- finally:
- pyfile.finishIfDone()
-
- self.manager.dispatchEvent("archive_extract_failed", pyfile)
+ self.manager.dispatchEvent("archive_extract_failed", pyfile, archive)
raise Exception(_("Extract failed"))
@@ -487,7 +512,7 @@ class ExtractArchive(Addon):
try:
passwords = []
- file = fs_encode(self.getConfig("passwordfile"))
+ file = fs_encode(self.getConfig('passwordfile'))
with open(file) as f:
for pw in f.read().splitlines():
passwords.append(pw)
@@ -505,7 +530,7 @@ class ExtractArchive(Addon):
try:
self.passwords = uniqify([password] + self.passwords)
- file = fs_encode(self.getConfig("passwordfile"))
+ file = fs_encode(self.getConfig('passwordfile'))
with open(file, "wb") as f:
for pw in self.passwords:
f.write(pw + '\n')
diff --git a/pyload/plugin/addon/HotFolder.py b/pyload/plugin/addon/HotFolder.py
index 1b1235f09..0137514a8 100644
--- a/pyload/plugin/addon/HotFolder.py
+++ b/pyload/plugin/addon/HotFolder.py
@@ -14,7 +14,7 @@ from pyload.utils import fs_encode, fs_join
class HotFolder(Addon):
__name__ = "HotFolder"
__type__ = "addon"
- __version__ = "0.13"
+ __version__ = "0.14"
__config__ = [("folder" , "str" , "Folder to observe" , "container"),
("watch_file", "bool", "Observe link file" , False ),
@@ -35,14 +35,14 @@ class HotFolder(Addon):
def periodical(self):
- folder = fs_encode(self.getConfig("folder"))
- file = fs_encode(self.getConfig("file"))
+ folder = fs_encode(self.getConfig('folder'))
+ file = fs_encode(self.getConfig('file'))
try:
if not os.path.isdir(os.path.join(folder, "finished")):
os.makedirs(os.path.join(folder, "finished"))
- if self.getConfig("watch_file"):
+ if self.getConfig('watch_file'):
with open(file, "a+") as f:
f.seek(0)
content = f.read().strip()
@@ -64,11 +64,11 @@ class HotFolder(Addon):
if not os.path.isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."):
continue
- newpath = os.path.join(folder, "finished", f if self.getConfig("keep") else "tmp_" + f)
+ newpath = os.path.join(folder, "finished", f if self.getConfig('keep') else "tmp_" + f)
move(path, newpath)
self.logInfo(_("Added %s from HotFolder") % f)
self.core.api.addPackage(f, [newpath], 1)
- except IOError, e:
+ except (IOError, OSError), e:
self.logError(e)
diff --git a/pyload/plugin/addon/IRCInterface.py b/pyload/plugin/addon/IRCInterface.py
index 86d9ea688..9038ce993 100644
--- a/pyload/plugin/addon/IRCInterface.py
+++ b/pyload/plugin/addon/IRCInterface.py
@@ -8,7 +8,6 @@ import time
from pycurl import FORM_FILE
from select import select
from threading import Thread
-from time import sleep
from traceback import print_exc
from pyload.api import PackageDoesNotExists, FileDoesNotExists
@@ -38,6 +37,9 @@ class IRCInterface(Thread, Addon):
__authors__ = [("Jeix", "Jeix@hasnomail.com")]
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
def __init__(self, core, manager):
Thread.__init__(self)
Addon.__init__(self, core, manager)
@@ -54,7 +56,7 @@ class IRCInterface(Thread, Addon):
def packageFinished(self, pypack):
try:
- if self.getConfig("info_pack"):
+ if self.getConfig('info_pack'):
self.response(_("Package finished: %s") % pypack.name)
except Exception:
pass
@@ -62,7 +64,7 @@ class IRCInterface(Thread, Addon):
def downloadFinished(self, pyfile):
try:
- if self.getConfig("info_file"):
+ if self.getConfig('info_file'):
self.response(
_("Download finished: %(name)s @ %(plugin)s ") % {"name": pyfile.name, "plugin": pyfile.pluginname})
except Exception:
@@ -70,7 +72,7 @@ class IRCInterface(Thread, Addon):
def captchaTask(self, task):
- if self.getConfig("captcha") and task.isTextual():
+ if self.getConfig('captcha') and task.isTextual():
task.handler.append(self)
task.setWaiting(60)
@@ -85,16 +87,16 @@ class IRCInterface(Thread, Addon):
def run(self):
# connect to IRC etc.
self.sock = socket.socket()
- host = self.getConfig("host")
- self.sock.connect((host, self.getConfig("port")))
+ host = self.getConfig('host')
+ self.sock.connect((host, self.getConfig('port')))
- if self.getConfig("ssl"):
- self.sock = ssl.wrap_socket(self.sock, cert_reqs=ssl.CERT_NONE) #@TODO: support custom certificate
+ if self.getConfig('ssl'):
+ self.sock = ssl.wrap_socket(self.sock, cert_reqs=ssl.CERT_NONE) #@TODO: support certificate
- nick = self.getConfig("nick")
+ nick = self.getConfig('nick')
self.sock.send("NICK %s\r\n" % nick)
self.sock.send("USER %s %s bla :%s\r\n" % (nick, host, nick))
- for t in self.getConfig("owner").split():
+ for t in self.getConfig('owner').split():
if t.strip().startswith("#"):
self.sock.send("JOIN %s\r\n" % t.strip())
self.logInfo(_("Connected to"), host)
@@ -111,7 +113,7 @@ class IRCInterface(Thread, Addon):
def main_loop(self):
readbuffer = ""
while True:
- sleep(1)
+ time.sleep(1)
fdset = select([self.sock], [], [], 0)
if self.sock not in fdset[0]:
continue
@@ -148,10 +150,10 @@ class IRCInterface(Thread, Addon):
def handle_events(self, msg):
- if not msg['origin'].split("!", 1)[0] in self.getConfig("owner").split():
+ if not msg['origin'].split("!", 1)[0] in self.getConfig('owner').split():
return
- if msg['target'].split("!", 1)[0] != self.getConfig("nick"):
+ if msg['target'].split("!", 1)[0] != self.getConfig('nick'):
return
if msg['action'] != "PRIVMSG":
@@ -192,7 +194,7 @@ class IRCInterface(Thread, Addon):
def response(self, msg, origin=""):
if origin == "":
- for t in self.getConfig("owner").split():
+ for t in self.getConfig('owner').split():
self.sock.send("PRIVMSG %s :%s\r\n" % (t.strip(), msg))
else:
self.sock.send("PRIVMSG %s :%s\r\n" % (origin.split("!", 1)[0], msg))
diff --git a/pyload/plugin/addon/JustPremium.py b/pyload/plugin/addon/JustPremium.py
index d3c4d8eff..e69bc24f6 100644
--- a/pyload/plugin/addon/JustPremium.py
+++ b/pyload/plugin/addon/JustPremium.py
@@ -8,18 +8,24 @@ from pyload.plugin.Addon import Addon
class JustPremium(Addon):
__name__ = "JustPremium"
__type__ = "addon"
- __version__ = "0.21"
+ __version__ = "0.22"
- __config__ = [("excluded", "str", "Exclude hosters (comma separated)", "")]
+ __config__ = [("excluded", "str", "Exclude hosters (comma separated)", ""),
+ ("included", "str", "Include hosters (comma separated)", "")]
- __description__ = """Remove all not premium links from urls added"""
+ __description__ = """Remove not-premium links from added urls"""
__license__ = "GPLv3"
- __authors__ = [("mazleu", "mazleica@gmail.com"),
- ("Walter Purcaro", "vuolter@gmail.com"),
- ("immenz", "immenz@gmx.net")]
+ __authors__ = [("mazleu" , "mazleica@gmail.com"),
+ ("Walter Purcaro", "vuolter@gmail.com" ),
+ ("immenz" , "immenz@gmx.net" )]
event_list = ["linksAdded"]
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
+ def setup(self):
+ self.info = {} #@TODO: Remove in 0.4.10
def linksAdded(self, links, pid):
@@ -32,14 +38,18 @@ class JustPremium(Addon):
if 'new_name' in hosterdict[hoster] \
and hosterdict[hoster]['new_name'] in premiumplugins)
- #: Found at least one hoster with account or multihoster
- if not any(True for pluginname in linkdict if pluginname in premiumplugins | multihosters):
- return
-
excluded = map(lambda domain: "".join(part.capitalize() for part in re.split(r'(\.|\d+)', domain) if part != '.'),
self.getConfig('excluded').replace(' ', '').replace(',', '|').replace(';', '|').split('|'))
+ included = map(lambda domain: "".join(part.capitalize() for part in re.split(r'(\.|\d+)', domain) if part != '.'),
+ self.getConfig('included').replace(' ', '').replace(',', '|').replace(';', '|').split('|'))
+
+ hosterlist = (premiumplugins | multihosters).union(excluded).difference(included)
+
+ #: Found at least one hoster with account or multihoster
+ if not any( True for pluginname in linkdict if pluginname in hosterlist ):
+ return
- for pluginname in set(linkdict.keys()) - (premiumplugins | multihosters).union(excluded):
+ for pluginname in set(linkdict.keys()) - hosterlist:
self.logInfo(_("Remove links of plugin: %s") % pluginname)
for link in linkdict[pluginname]:
self.logDebug("Remove link: %s" % link)
diff --git a/pyload/plugin/addon/MergeFiles.py b/pyload/plugin/addon/MergeFiles.py
index d4cecf05d..374604d82 100644
--- a/pyload/plugin/addon/MergeFiles.py
+++ b/pyload/plugin/addon/MergeFiles.py
@@ -23,11 +23,13 @@ class MergeFiles(Addon):
__authors__ = [("and9000", "me@has-no-mail.com")]
+ interval = 0 #@TODO: Remove in 0.4.10
+
BUFFER_SIZE = 4096
def setup(self):
- pass
+ self.info = {} #@TODO: Remove in 0.4.10
@threaded
diff --git a/pyload/plugin/addon/MultiHome.py b/pyload/plugin/addon/MultiHome.py
index 521749fc8..0cebf35b8 100644
--- a/pyload/plugin/addon/MultiHome.py
+++ b/pyload/plugin/addon/MultiHome.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-from time import time
+import time
from pyload.plugin.Addon import Addon
@@ -17,10 +17,16 @@ class MultiHome(Addon):
__authors__ = [("mkaay", "mkaay@mkaay.de")]
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
def setup(self):
- self.register = {}
+ self.info = {} #@TODO: Remove in 0.4.10
+ self.register = {}
self.interfaces = []
- self.parseInterfaces(self.getConfig("interfaces").split(";"))
+
+ self.parseInterfaces(self.getConfig('interfaces').split(";"))
+
if not self.interfaces:
self.parseInterfaces([self.config['download']['interface']])
self.setConfig("interfaces", self.toConfig())
@@ -74,7 +80,7 @@ class Interface(object):
def useFor(self, pluginName, account):
- self.history[(pluginName, account)] = time()
+ self.history[(pluginName, account)] = time.time()
def __repr__(self):
diff --git a/pyload/plugin/addon/RestartFailed.py b/pyload/plugin/addon/RestartFailed.py
index 2fe5f13bf..e34424a8c 100644
--- a/pyload/plugin/addon/RestartFailed.py
+++ b/pyload/plugin/addon/RestartFailed.py
@@ -6,30 +6,30 @@ from pyload.plugin.Addon import Addon
class RestartFailed(Addon):
__name__ = "RestartFailed"
__type__ = "addon"
- __version__ = "1.57"
+ __version__ = "1.58"
__config__ = [("activated", "bool", "Activated" , True),
("interval" , "int" , "Check interval in minutes", 90 )]
- __description__ = """Periodically restart all failed downloads in queue"""
+ __description__ = """Restart all the failed downloads in queue"""
__license__ = "GPLv3"
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
# event_list = ["pluginConfigChanged"]
- MIN_INTERVAL = 15 * 60 #: 15m minimum check interval (value is in seconds)
+ MIN_CHECK_INTERVAL = 15 * 60 #: 15 minutes
- def pluginConfigChanged(self, plugin, name, value):
- if name == "interval":
- interval = value * 60
- if self.MIN_INTERVAL <= interval != self.interval:
- self.core.scheduler.removeJob(self.cb)
- self.interval = interval
- self.initPeriodical()
- else:
- self.logDebug("Invalid interval value, kept current")
+ # def pluginConfigChanged(self, plugin, name, value):
+ # if name == "interval":
+ # interval = value * 60
+ # if self.MIN_CHECK_INTERVAL <= interval != self.interval:
+ # self.core.scheduler.removeJob(self.cb)
+ # self.interval = interval
+ # self.initPeriodical()
+ # else:
+ # self.logDebug("Invalid interval value, kept current")
def periodical(self):
@@ -37,9 +37,6 @@ class RestartFailed(Addon):
self.core.api.restartFailed()
- def setup(self):
- self.interval = 0
-
-
def activate(self):
- self.pluginConfigChanged(self.__name__, "interval", self.getConfig("interval"))
+ # self.pluginConfigChanged(self.__name__, "interval", self.getConfig('interval'))
+ self.interval = max(self.MIN_CHECK_INTERVAL, self.getConfig('interval') * 60)
diff --git a/pyload/plugin/addon/RestartSlow.py b/pyload/plugin/addon/RestartSlow.py
index 332047da7..cd503518d 100644
--- a/pyload/plugin/addon/RestartSlow.py
+++ b/pyload/plugin/addon/RestartSlow.py
@@ -21,18 +21,17 @@ class RestartSlow(Addon):
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- event_map = {'download-start': "downloadStarts"}
+ event_list = ["downloadStarts"]
+ interval = 0 #@TODO: Remove in 0.4.10
def setup(self):
self.info = {'chunk': {}}
-
-
def periodical(self):
if not self.pyfile.plugin.req.dl:
return
- if self.getConfig("safe_mode") and not self.pyfile.plugin.resumeDownload:
+ if self.getConfig('safe_mode') and not self.pyfile.plugin.resumeDownload:
time = 30
limit = 5
else:
@@ -51,7 +50,7 @@ class RestartSlow(Addon):
def downloadStarts(self, pyfile, url, filename):
- if self.cb or (self.getConfig("safe_mode") and not pyfile.plugin.resumeDownload):
+ if self.cb or (self.getConfig('safe_mode') and not pyfile.plugin.resumeDownload):
return
self.pyfile = pyfile
self.initPeriodical()
diff --git a/pyload/plugin/addon/SkipRev.py b/pyload/plugin/addon/SkipRev.py
index efc96cb7b..157b55bbd 100644
--- a/pyload/plugin/addon/SkipRev.py
+++ b/pyload/plugin/addon/SkipRev.py
@@ -1,35 +1,46 @@
# -*- coding: utf-8 -*-
+import re
+
from types import MethodType
from urllib import unquote
from urlparse import urlparse
-from pyload.datatype.File import PyFile
-from pyload.plugin.Addon import Addon
-from pyload.plugin.Plugin import SkipDownload
-
-
-def _setup(self):
- self.pyfile.plugin._setup()
- if self.pyfile.hasStatus("skipped"):
- raise SkipDownload(self.pyfile.statusname or self.pyfile.pluginname)
+from module.PyFile import PyFile
+from module.plugins.Hook import Hook
+from module.plugins.Plugin import SkipDownload
-class SkipRev(Addon):
+class SkipRev(Hook):
__name__ = "SkipRev"
- __type__ = "addon"
- __version__ = "0.25"
+ __type__ = "hook"
+ __version__ = "0.29"
- __config__ = [("tokeep", "int", "Number of rev files to keep for package (-1 to auto)", -1)]
+ __config__ = [("mode" , "Auto;Manual", "Choose recovery archives to skip" , "Auto"),
+ ("revtokeep", "int" , "Number of recovery archives to keep for package", 0 )]
- __description__ = """Skip files ending with extension rev"""
+ __description__ = """Skip recovery archives (.rev)"""
__license__ = "GPLv3"
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- def _pyname(self, pyfile):
- if hasattr(pyfile.pluginmodule, "getInfo"):
- return getattr(pyfile.pluginmodule, "getInfo")([pyfile.url]).next()[0]
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
+ def setup(self):
+ self.info = {} #@TODO: Remove in 0.4.10
+
+
+ @staticmethod
+ def _setup(self):
+ self.pyfile.plugin._setup()
+ if self.pyfile.hasStatus("skipped"):
+ raise SkipDownload(self.pyfile.statusname or self.pyfile.pluginname)
+
+
+ def _name(self, pyfile):
+ if hasattr(pyfile.pluginmodule, "getInfo"): #@NOTE: getInfo is deprecated in 0.4.10
+ return pyfile.pluginmodule.getInfo([pyfile.url]).next()[0]
else:
self.logWarning("Unable to grab file name")
return urlparse(unquote(pyfile.url)).path.split('/')[-1]
@@ -49,44 +60,52 @@ class SkipRev(Addon):
def downloadPreparing(self, pyfile):
- if pyfile.statusname is "unskipped" or not self._pyname(pyfile).endswith(".rev"):
+ name = self._name(pyfile)
+
+ if pyfile.statusname is _("unskipped") or not name.endswith(".rev") or not ".part" in name:
return
- tokeep = self.getConfig("tokeep")
+ revtokeep = -1 if self.getConfig('mode') == "Auto" else self.getConfig('revtokeep')
- if tokeep:
- status_list = (1, 4, 8, 9, 14) if tokeep < 0 else (1, 3, 4, 8, 9, 14)
+ if revtokeep:
+ status_list = (1, 4, 8, 9, 14) if revtokeep < 0 else (1, 3, 4, 8, 9, 14)
+ pyname = re.compile(r'%s\.part\d+\.rev$' % name.rsplit('.', 2)[0].replace('.', '\.'))
queued = [True for link in self.core.api.getPackageData(pyfile.package().id).links \
- if link.name.endswith(".rev") and link.status not in status_list].count(True)
+ if link.status not in status_list and pyname.match(link.name)].count(True)
- if not queued or queued < tokeep: #: keep one rev at least in auto mode
+ if not queued or queued < revtokeep: #: keep one rev at least in auto mode
return
pyfile.setCustomStatus("SkipRev", "skipped")
- pyfile.plugin._setup = pyfile.plugin.setup
- pyfile.plugin.setup = MethodType(_setup, pyfile.plugin) #: work-around: inject status checker inside the preprocessing routine of the plugin
+
+ if not hasattr(pyfile.plugin, "_setup"):
+ # Work-around: inject status checker inside the preprocessing routine of the plugin
+ pyfile.plugin._setup = pyfile.plugin.setup
+ pyfile.plugin.setup = MethodType(self._setup, pyfile.plugin)
def downloadFailed(self, pyfile):
#: Check if pyfile is still "failed",
# maybe might has been restarted in meantime
- if pyfile.status != 8:
+ if pyfile.status != 8 or pyfile.name.rsplit('.', 1)[-1].strip() not in ("rar", "rev"):
return
- tokeep = self.getConfig("tokeep")
+ revtokeep = -1 if self.getConfig('mode') == "Auto" else self.getConfig('revtokeep')
- if not tokeep:
+ if not revtokeep:
return
+ pyname = re.compile(r'%s\.part\d+\.rev$' % pyfile.name.rsplit('.', 2)[0].replace('.', '\.'))
+
for link in self.core.api.getPackageData(pyfile.package().id).links:
- if link.status is 4 and link.name.endswith(".rev"):
+ if link.status is 4 and pyname.match(link.name):
pylink = self._pyfile(link)
- if tokeep > -1 or pyfile.name.endswith(".rev"):
+ if revtokeep > -1 or pyfile.name.endswith(".rev"):
pylink.setStatus("queued")
else:
- pylink.setCustomStatus("unskipped", "queued")
+ pylink.setCustomStatus(_("unskipped"), "queued")
self.core.files.save()
pylink.release()
diff --git a/pyload/plugin/addon/UnSkipOnFail.py b/pyload/plugin/addon/UnSkipOnFail.py
index 7d787d1ed..55de85082 100644
--- a/pyload/plugin/addon/UnSkipOnFail.py
+++ b/pyload/plugin/addon/UnSkipOnFail.py
@@ -11,11 +11,14 @@ class UnSkipOnFail(Addon):
__config__ = [("activated", "bool", "Activated", True)]
- __description__ = """Queue skipped duplicates when download fails"""
+ __description__ = """Restart skipped duplicates when download fails"""
__license__ = "GPLv3"
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
def downloadFailed(self, pyfile):
#: Check if pyfile is still "failed",
# maybe might has been restarted in meantime
@@ -38,7 +41,7 @@ class UnSkipOnFail(Addon):
# the core.files-manager to save its data.
pylink = _pyfile(link)
- pylink.setCustomStatus("UnSkipOnFail", "queued")
+ pylink.setCustomStatus(_("unskipped"), "queued")
self.core.files.save()
pylink.release()
diff --git a/pyload/plugin/addon/UpdateManager.py b/pyload/plugin/addon/UpdateManager.py
index 5fdd6011a..643b5c2d1 100644
--- a/pyload/plugin/addon/UpdateManager.py
+++ b/pyload/plugin/addon/UpdateManager.py
@@ -2,88 +2,91 @@
from __future__ import with_statement
+import os
import re
import sys
+import time
from operator import itemgetter
-from os import path, remove, stat
-from pyload.network.RequestFactory import getURL
-from pyload.plugin.Addon import Expose, Addon, threaded
-from pyload.utils import fs_join
+from module.network.RequestFactory import getURL
+from module.plugins.Hook import Expose, Hook, threaded
+from module.utils import save_join
-class UpdateManager(Addon):
- __name__ = "UpdateManager"
- __type__ = "addon"
- __version__ = "0.43"
+# Case-sensitive os.path.exists
+def exists(path):
+ if os.path.exists(path):
+ if os.name == 'nt':
+ dir, name = os.path.split(path)
+ return name in os.listdir(dir)
+ else:
+ return True
+ else:
+ return False
- __config__ = [("activated" , "bool" , "Activated" , True ),
- ("mode" , "pyLoad + plugins;plugins only", "Check updates for" , "pyLoad + plugins"),
- ("interval" , "int" , "Check interval in hours" , 8 ),
- ("autorestart" , "bool" , "Automatically restart pyLoad when required" , True ),
- ("reloadplugins", "bool" , "Monitor plugins for code changes in debug mode", True ),
- ("nodebugupdate", "bool" , "Don't check for updates in debug mode" , False )]
- __description__ = """Check for updates"""
+class UpdateManager(Hook):
+ __name__ = "UpdateManager"
+ __type__ = "hook"
+ __version__ = "0.50"
+
+ __config__ = [("activated" , "bool", "Activated" , True ),
+ ("checkinterval", "int" , "Check interval in hours" , 8 ),
+ ("autorestart" , "bool", "Auto-restart pyLoad when required" , True ),
+ ("checkonstart" , "bool", "Check for updates on startup" , True ),
+ ("checkperiod" , "bool", "Check for updates periodically" , True ),
+ ("reloadplugins", "bool", "Monitor plugin code changes in debug mode", True ),
+ ("nodebugupdate", "bool", "Don't update plugins in debug mode" , False)]
+
+ __description__ = """ Check for updates """
__license__ = "GPLv3"
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- # event_list = ["pluginConfigChanged"]
-
- SERVER_URL = "http://updatemanager.pyload.org"
- VERSION = re.compile(r'__version__.*=.*("|\')([\d.]+)')
- MIN_INTERVAL = 3 * 60 * 60 #: 3h minimum check interval (value is in seconds)
-
-
- def pluginConfigChanged(self, plugin, name, value):
- if name == "interval":
- interval = value * 60 * 60
- if self.MIN_INTERVAL <= interval != self.interval:
- self.core.scheduler.removeJob(self.cb)
- self.interval = interval
- self.initPeriodical()
- else:
- self.logDebug("Invalid interval value, kept current")
-
- elif name == "reloadplugins":
- if self.cb2:
- self.core.scheduler.removeJob(self.cb2)
- if value is True and self.core.debug:
- self.periodical2()
+ interval = 0
+ SERVER_URL = "http://updatemanager.pyload.org"
+ MIN_CHECK_INTERVAL = 3 * 60 * 60 #: 3 hours
- def activate(self):
- self.pluginConfigChanged(self.__name__, "interval", self.getConfig("interval"))
- x = lambda: self.pluginConfigChanged(self.__name__, "reloadplugins", self.getConfig("reloadplugins"))
- self.core.scheduler.addJob(10, x, threaded=False)
+ def coreReady(self):
+ if self.checkonstart:
+ self.update()
- def deactivate(self):
- self.pluginConfigChanged(self.__name__, "reloadplugins", False)
+ self.initPeriodical()
def setup(self):
- self.cb2 = None
- self.interval = 0
- self.updating = False
- self.info = {'pyload': False, 'version': None, 'plugins': False}
+ self.interval = 10
+ self.info = {'pyload': False, 'version': None, 'plugins': False, 'last_check': time.time()}
self.mtimes = {} #: store modification time for each plugin
+ if self.getConfig('checkonstart'):
+ self.core.api.pauseServer()
+ self.checkonstart = True
+ else:
+ self.checkonstart = False
+
- def periodical2(self):
- if not self.updating:
- self.autoreloadPlugins()
+ def periodical(self):
+ if self.core.debug:
+ if self.getConfig('reloadplugins'):
+ self.autoreloadPlugins()
+
+ if self.getConfig('nodebugupdate'):
+ return
- self.cb2 = self.core.scheduler.addJob(4, self.periodical2, threaded=False)
+ if self.getConfig('checkperiod') \
+ and time.time() - max(self.MIN_CHECK_INTERVAL, self.getConfig('checkinterval') * 60 * 60) > self.info['last_check']:
+ self.update()
@Expose
def autoreloadPlugins(self):
""" reload and reindex all modified plugins """
modules = filter(
- lambda m: m and (m.__name__.startswith("pyload.plugin.") or
+ lambda m: m and (m.__name__.startswith("module.plugins.") or
m.__name__.startswith("userplugins.")) and
m.__name__.count(".") >= 2, sys.modules.itervalues()
)
@@ -95,10 +98,10 @@ class UpdateManager(Addon):
id = (type, name)
if type in self.core.pluginManager.plugins:
f = m.__file__.replace(".pyc", ".py")
- if not path.isfile(f):
+ if not os.path.isfile(f):
continue
- mtime = stat(f).st_mtime
+ mtime = os.stat(f).st_mtime
if id not in self.mtimes:
self.mtimes[id] = mtime
@@ -109,109 +112,102 @@ class UpdateManager(Addon):
return True if self.core.pluginManager.reloadPlugins(reloads) else False
- def periodical(self):
- if self.info['pyload'] or self.getConfig("nodebugupdate") and self.core.debug:
- return
-
- self.updateThread()
-
-
- def server_request(self):
+ def server_response(self):
try:
return getURL(self.SERVER_URL, get={'v': self.core.api.getServerVersion()}).splitlines()
+
except Exception:
self.logWarning(_("Unable to contact server to get updates"))
+ @Expose
@threaded
- def updateThread(self):
- self.updating = True
+ def update(self):
+ """ check for updates """
- status = self.update(onlyplugin=self.getConfig("mode") == "plugins only")
+ self.core.api.pauseServer()
- if status is 2 and self.getConfig("autorestart"):
+ if self._update() is 2 and self.getConfig('autorestart'):
self.core.api.restart()
else:
- self.updating = False
+ self.core.api.unpauseServer()
- @Expose
- def updatePlugins(self):
- """ simple wrapper for calling plugin update quickly """
- return self.update(onlyplugin=True)
+ def _update(self):
+ data = self.server_response()
-
- @Expose
- def update(self, onlyplugin=False):
- """ check for updates """
- data = self.server_request()
+ self.info['last_check'] = time.time()
if not data:
exitcode = 0
elif data[0] == "None":
self.logInfo(_("No new pyLoad version available"))
- updates = data[1:]
- exitcode = self._updatePlugins(updates)
+ exitcode = self._updatePlugins(data[1:])
elif onlyplugin:
exitcode = 0
else:
- newversion = data[0]
- self.logInfo(_("*** New pyLoad Version %s available ***") % newversion)
+ self.logInfo(_("*** New pyLoad Version %s available ***") % data[0])
self.logInfo(_("*** Get it here: https://github.com/pyload/pyload/releases ***"))
+ self.info['pyload'] = True
+ self.info['version'] = data[0]
exitcode = 3
- self.info['pyload'] = True
- self.info['version'] = newversion
- return exitcode #: 0 = No plugins updated; 1 = Plugins updated; 2 = Plugins updated, but restart required; 3 = No plugins updated, new pyLoad version available
+ # Exit codes:
+ # -1 = No plugin updated, new pyLoad version available
+ # 0 = No plugin updated
+ # 1 = Plugins updated
+ # 2 = Plugins updated, but restart required
+ return exitcode
- def _updatePlugins(self, updates):
+ def _updatePlugins(self, data):
""" check for plugin updates """
- if self.info['plugins']:
- return False #: plugins were already updated
-
exitcode = 0
updated = []
- url = updates[0]
- schema = updates[1].split('|')
+ url = data[0]
+ schema = data[1].split('|')
- if "BLACKLIST" in updates:
- blacklist = updates[updates.index('BLACKLIST') + 1:]
- updates = updates[2:updates.index('BLACKLIST')]
+ VERSION = re.compile(r'__version__.*=.*("|\')([\d.]+)')
+
+ if "BLACKLIST" in data:
+ blacklist = data[data.index('BLACKLIST') + 1:]
+ updatelist = data[2:data.index('BLACKLIST')]
else:
- blacklist = None
- updates = updates[2:]
+ blacklist = []
+ updatelist = data[2:]
- upgradable = [dict(zip(schema, x.split('|'))) for x in updates]
- blacklisted = [(x.split('|')[0], x.split('|')[1].rsplit('.', 1)[0]) for x in blacklist] if blacklist else []
+ updatelist = [dict(zip(schema, x.split('|'))) for x in updatelist]
+ blacklist = [dict(zip(schema, x.split('|'))) for x in blacklist]
if blacklist:
+ type_plugins = [(plugin['type'], plugin['name'].rsplit('.', 1)[0]) for plugin in blacklist]
+
# Protect UpdateManager from self-removing
try:
- blacklisted.remove(("addon", "UpdateManager"))
- except Exception:
+ type_plugins.remove(("hook", "UpdateManager"))
+ except ValueError:
pass
- for t, n in blacklisted:
- for idx, plugin in enumerate(upgradable):
+ for t, n in type_plugins:
+ for idx, plugin in enumerate(updatelist):
if n == plugin['name'] and t == plugin['type']:
- upgradable.pop(idx)
+ updatelist.pop(idx)
break
- for t, n in self.removePlugins(sorted(blacklisted)):
- self.logInfo(_("Removed blacklisted plugin [%(type)s] %(name)s") % {
+ for t, n in self.removePlugins(sorted(type_plugins)):
+ self.logInfo(_("Removed blacklisted plugin: [%(type)s] %(name)s") % {
'type': t,
'name': n,
})
- for plugin in sorted(upgradable, key=itemgetter("type", "name")):
+ for plugin in sorted(updatelist, key=itemgetter("type", "name")):
filename = plugin['name']
- type = plugin['type']
+ prefix = plugin['type']
version = plugin['version']
if filename.endswith(".pyc"):
@@ -219,9 +215,15 @@ class UpdateManager(Addon):
else:
name = filename.replace(".py", "")
+ #@TODO: Remove in 0.4.10
+ if prefix.endswith("s"):
+ type = prefix[:-1]
+ else:
+ type = prefix
+
plugins = getattr(self.core.pluginManager, "%sPlugins" % type)
- oldver = float(plugins[name]['version']) if name in plugins else None
+ oldver = float(plugins[name]['v']) if name in plugins else None
newver = float(version)
if not oldver:
@@ -237,10 +239,10 @@ class UpdateManager(Addon):
'newver': newver})
try:
content = getURL(url % plugin)
- m = self.VERSION.search(content)
+ m = VERSION.search(content)
if m and m.group(2) == version:
- with open(fs_join("userplugins", prefix, filename), "wb") as f:
+ with open(save_join("userplugins", prefix, filename), "wb") as f:
f.write(content)
updated.append((prefix, name))
@@ -248,21 +250,27 @@ class UpdateManager(Addon):
raise Exception, _("Version mismatch")
except Exception, e:
- self.logError(_("Error updating plugin: %s") % filename, str(e))
+ self.logError(_("Error updating plugin: %s") % filename, e)
if updated:
- reloaded = self.core.pluginManager.reloadPlugins(updated)
- if reloaded:
- self.logInfo(_("Plugins updated and reloaded"))
+ self.logInfo(_("*** Plugins updated ***"))
+
+ if self.core.pluginManager.reloadPlugins(updated):
exitcode = 1
else:
- self.logInfo(_("*** Plugins have been updated, but need a pyLoad restart to be reloaded ***"))
+ self.logWarning(_("pyLoad restart required to reload the updated plugins"))
self.info['plugins'] = True
exitcode = 2
+
+ self.manager.dispatchEvent("plugin_updated", updated)
else:
self.logInfo(_("No plugin updates available"))
- return exitcode #: 0 = No plugins updated; 1 = Plugins updated; 2 = Plugins updated, but restart required
+ # Exit codes:
+ # 0 = No plugin updated
+ # 1 = Plugins updated
+ # 2 = Plugins updated, but restart required
+ return exitcode
@Expose
@@ -272,35 +280,36 @@ class UpdateManager(Addon):
if not type_plugins:
return
- self.logDebug("Requested deletion of plugins: %s" % type_plugins)
+ removed = set()
- removed = []
+ self.logDebug("Requested deletion of plugins: %s" % type_plugins)
for type, name in type_plugins:
- err = False
- file = name + ".py"
+ rootplugins = os.path.join(pypath, "module", "plugins")
- for root in ("userplugins", path.join(pypath, "pyload", "plugins")):
+ for dir in ("userplugins", rootplugins):
+ py_filename = save_join(dir, type, name + ".py")
+ pyc_filename = py_filename + "c"
- filename = fs_join(root, type, file)
- try:
- remove(filename)
- except Exception, e:
- self.logDebug("Error deleting: %s" % path.basename(filename), e)
- err = True
-
- filename += "c"
- if path.isfile(filename):
+ if type == "hook":
try:
- if type == "addon":
- self.manager.deactivateAddon(name)
- remove(filename)
+ self.manager.deactivateHook(name)
+
except Exception, e:
- self.logDebug("Error deleting: %s" % path.basename(filename), e)
- err = True
+ self.logDebug(e)
+
+ for filename in (py_filename, pyc_filename):
+ if not exists(filename):
+ continue
+
+ try:
+ os.remove(filename)
+
+ except OSError, e:
+ self.logError(_("Error removing: %s") % filename, e)
- if not err:
- id = (type, name)
- removed.append(id)
+ else:
+ id = (type, name)
+ removed.add(id)
- return removed #: return a list of the plugins successfully removed
+ return list(removed) #: return a list of the plugins successfully removed
diff --git a/pyload/plugin/addon/WindowsPhoneNotify.py b/pyload/plugin/addon/WindowsPhoneNotify.py
index b9710c2f0..e61057f9f 100644
--- a/pyload/plugin/addon/WindowsPhoneNotify.py
+++ b/pyload/plugin/addon/WindowsPhoneNotify.py
@@ -1,57 +1,75 @@
# -*- coding: utf-8 -*-
import httplib
+import time
-from time import time
+from module.plugins.Hook import Hook, Expose
-from pyload.plugin.Addon import Addon
-
-class WindowsPhoneNotify(Addon):
+class WindowsPhoneNotify(Hook):
__name__ = "WindowsPhoneNotify"
- __type__ = "addon"
- __version__ = "0.07"
+ __type__ = "hook"
+ __version__ = "0.09"
__config__ = [("id" , "str" , "Push ID" , "" ),
("url" , "str" , "Push url" , "" ),
("notifycaptcha" , "bool", "Notify captcha request" , True ),
("notifypackage" , "bool", "Notify package finished" , True ),
- ("notifyprocessed", "bool", "Notify processed packages status" , True ),
- ("timeout" , "int" , "Timeout between captchas in seconds" , 5 ),
- ("force" , "bool", "Send notifications if client is connected", False)]
+ ("notifyprocessed", "bool", "Notify packages processed" , True ),
+ ("notifyupdate" , "bool", "Notify plugin updates" , True ),
+ ("notifyexit" , "bool", "Notify pyLoad shutdown" , True ),
+ ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ),
+ ("sendpermin" , "int" , "Max notifications per minute" , 12 ),
+ ("ignoreclient" , "bool", "Send notifications if client is connected", False)]
__description__ = """Send push notifications to Windows Phone"""
__license__ = "GPLv3"
- __authors__ = [("Andy Voigt", "phone-support@hotmail.de"),
- ("Walter Purcaro", "vuolter@gmail.com")]
+ __authors__ = [("Andy Voigt" , "phone-support@hotmail.de"),
+ ("Walter Purcaro", "vuolter@gmail.com" )]
- event_list = ["allDownloadsProcessed"]
+ event_list = ["allDownloadsProcessed", "plugin_updated"]
+ interval = 0 #@TODO: Remove in 0.4.10
def setup(self):
- self.info = {} #@TODO: Remove in 0.4.10
- self.last_notify = 0
+ self.info = {} #@TODO: Remove in 0.4.10
+ self.last_notify = 0
+ self.notifications = 0
- def newCaptchaTask(self, task):
- if not self.getConfig("notifycaptcha"):
- return False
+ def plugin_updated(self, type_plugins):
+ if not self.getConfig('notifyupdate'):
+ return
+
+ self.notify(_("Plugins updated"), str(type_plugins))
+
- if time() - self.last_notify < self.getConf("timeout"):
- return False
+ def coreExiting(self):
+ if not self.getConfig('notifyexit'):
+ return
+
+ if self.core.do_restart:
+ self.notify(_("Restarting pyLoad"))
+ else:
+ self.notify(_("Exiting pyLoad"))
+
+
+ def newCaptchaTask(self, task):
+ if not self.getConfig('notifycaptcha'):
+ return
self.notify(_("Captcha"), _("New request waiting user input"))
def packageFinished(self, pypack):
- if self.getConfig("notifypackage"):
+ if self.getConfig('notifypackage'):
self.notify(_("Package finished"), pypack.name)
def allDownloadsProcessed(self):
- if not self.getConfig("notifyprocessed"):
- return False
+ if not self.getConfig('notifyprocessed'):
+ return
if any(True for pdata in self.core.api.getQueue() if pdata.linksdone < pdata.linkstotal):
self.notify(_("Package failed"), _("One or more packages was not completed successfully"))
@@ -65,15 +83,31 @@ class WindowsPhoneNotify(Addon):
"</wp:Toast> </wp:Notification>" % msg)
- def notify(self, event, msg=""):
- id = self.getConfig("id")
- url = self.getConfig("url")
+ @Expose
+ def notify(self,
+ event,
+ msg="",
+ key=(self.getConfig('id'), self.getConfig('url'))):
+
+ id, url = key
if not id or not url:
- return False
+ return
+
+ if self.core.isClientConnected() and not self.getConfig('ignoreclient'):
+ return
+
+ elapsed_time = time.time() - self.last_notify
+
+ if elapsed_time < self.getConf("sendtimewait"):
+ return
+
+ if elapsed_time > 60:
+ self.notifications = 0
+
+ elif self.notifications >= self.getConf("sendpermin"):
+ return
- if self.core.isClientConnected() and not self.getConfig("force"):
- return False
request = self.getXmlData("%s: %s" % (event, msg) if msg else event)
webservice = httplib.HTTP(url)
@@ -88,4 +122,5 @@ class WindowsPhoneNotify(Addon):
webservice.send(request)
webservice.close()
- self.last_notify = time()
+ self.last_notify = time.time()
+ self.notifications += 1
diff --git a/pyload/plugin/addon/XMPPInterface.py b/pyload/plugin/addon/XMPPInterface.py
index 77a49af6f..c0c31c738 100644
--- a/pyload/plugin/addon/XMPPInterface.py
+++ b/pyload/plugin/addon/XMPPInterface.py
@@ -33,14 +33,14 @@ class XMPPInterface(IRCInterface, JabberClient):
def __init__(self, core, manager):
IRCInterface.__init__(self, core, manager)
- self.jid = JID(self.getConfig("jid"))
- password = self.getConfig("pw")
+ self.jid = JID(self.getConfig('jid'))
+ password = self.getConfig('pw')
# if bare JID is provided add a resource -- it is required
if not self.jid.resource:
self.jid = JID(self.jid.node, self.jid.domain, "pyLoad")
- if self.getConfig("tls"):
+ if self.getConfig('tls'):
tls_settings = streamtls.TLSSettings(require=True, verify_peer=False)
auth = ("sasl:PLAIN", "sasl:DIGEST-MD5")
else:
@@ -67,7 +67,7 @@ class XMPPInterface(IRCInterface, JabberClient):
def packageFinished(self, pypack):
try:
- if self.getConfig("info_pack"):
+ if self.getConfig('info_pack'):
self.announce(_("Package finished: %s") % pypack.name)
except Exception:
pass
@@ -75,7 +75,7 @@ class XMPPInterface(IRCInterface, JabberClient):
def downloadFinished(self, pyfile):
try:
- if self.getConfig("info_file"):
+ if self.getConfig('info_file'):
self.announce(
_("Download finished: %(name)s @ %(plugin)s") % {"name": pyfile.name, "plugin": pyfile.pluginname})
except Exception:
@@ -139,7 +139,7 @@ class XMPPInterface(IRCInterface, JabberClient):
to_name = to_jid.as_utf8()
from_name = from_jid.as_utf8()
- names = self.getConfig("owners").split(";")
+ names = self.getConfig('owners').split(";")
if to_name in names or to_jid.node + "@" + to_jid.domain in names:
messages = []
@@ -182,7 +182,7 @@ class XMPPInterface(IRCInterface, JabberClient):
def announce(self, message):
""" send message to all owners"""
- for user in self.getConfig("owners").split(";"):
+ for user in self.getConfig('owners').split(";"):
self.logDebug("Send message to", user)
to_jid = JID(user)