diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-03-26 18:15:41 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-03-26 18:15:41 +0100 |
commit | 181ab47c5f775b8b48569361da6b88a801784a30 (patch) | |
tree | f5f6d1d6b75b7f21b89b33733c3536e5ca80e087 /pyload/plugin/addon | |
parent | Merge branch 'stable' into 0.4.10 (diff) | |
download | pyload-181ab47c5f775b8b48569361da6b88a801784a30.tar.xz |
Cleanup
Diffstat (limited to 'pyload/plugin/addon')
-rw-r--r-- | pyload/plugin/addon/AndroidPhoneNotify.py | 4 | ||||
-rw-r--r-- | pyload/plugin/addon/AntiVirus.py | 88 | ||||
-rw-r--r-- | pyload/plugin/addon/Checksum.py | 2 | ||||
-rw-r--r-- | pyload/plugin/addon/ClickAndLoad.py | 5 | ||||
-rw-r--r-- | pyload/plugin/addon/DeleteFinished.py | 2 | ||||
-rw-r--r-- | pyload/plugin/addon/DownloadScheduler.py | 8 | ||||
-rw-r--r-- | pyload/plugin/addon/ExternalScripts.py | 21 | ||||
-rw-r--r-- | pyload/plugin/addon/ExtractArchive.py | 2 | ||||
-rw-r--r-- | pyload/plugin/addon/IRCInterface.py | 3 | ||||
-rw-r--r-- | pyload/plugin/addon/JustPremium.py | 5 | ||||
-rw-r--r-- | pyload/plugin/addon/MergeFiles.py | 6 | ||||
-rw-r--r-- | pyload/plugin/addon/MultiHome.py | 4 | ||||
-rw-r--r-- | pyload/plugin/addon/RestartFailed.py | 1 | ||||
-rw-r--r-- | pyload/plugin/addon/RestartSlow.py | 7 | ||||
-rw-r--r-- | pyload/plugin/addon/SkipRev.py | 17 | ||||
-rw-r--r-- | pyload/plugin/addon/UnSkipOnFail.py | 3 | ||||
-rw-r--r-- | pyload/plugin/addon/UpdateManager.py | 25 | ||||
-rw-r--r-- | pyload/plugin/addon/WindowsPhoneNotify.py | 10 |
18 files changed, 126 insertions, 87 deletions
diff --git a/pyload/plugin/addon/AndroidPhoneNotify.py b/pyload/plugin/addon/AndroidPhoneNotify.py index 53af8aa1c..d3b390e6e 100644 --- a/pyload/plugin/addon/AndroidPhoneNotify.py +++ b/pyload/plugin/addon/AndroidPhoneNotify.py @@ -28,11 +28,9 @@ class AndroidPhoneNotify(Addon): 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.notifications = 0 @@ -44,7 +42,7 @@ class AndroidPhoneNotify(Addon): self.notify(_("Plugins updated"), str(type_plugins)) - def coreExiting(self): + def exit(self): if not self.getConfig('notifyexit'): return diff --git a/pyload/plugin/addon/AntiVirus.py b/pyload/plugin/addon/AntiVirus.py new file mode 100644 index 000000000..619893735 --- /dev/null +++ b/pyload/plugin/addon/AntiVirus.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- + +import os +import shutil +import subprocess + +from pyload.plugin.Addon import Addon, Expose, threaded +from pyload.utils import fs_encode, fs_join + + +class AntiVirus(Addon): + __name__ = "AntiVirus" + __type__ = "addon" + __version__ = "0.05" + + #@TODO: add trash option (use Send2Trash lib) + __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"), + ("quardir" , "folder" , "Quarantine folder" , "" ), + ("scanfailed", "bool" , "Scan incompleted files (failed downloads)", False ), + ("cmdfile" , "file" , "Antivirus executable" , "" ), + ("cmdargs" , "str" , "Scan options" , "" ), + ("ignore-err", "bool" , "Ignore scan errors" , False )] + + __description__ = """Scan downloaded files with antivirus program""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + @Expose + @threaded + def scan(self, pyfile, thread): + file = fs_encode(pyfile.plugin.lastDownload) + filename = os.path.basename(pyfile.plugin.lastDownload) + cmdfile = fs_encode(self.getConfig('cmdfile')) + cmdargs = fs_encode(self.getConfig('cmdargs').strip()) + + if not os.path.isfile(file) or not os.path.isfile(cmdfile): + return + + thread.addActive(pyfile) + pyfile.setCustomStatus(_("virus scanning")) + + try: + p = subprocess.Popen([cmdfile, cmdargs, file], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + out, err = map(str.strip, p.communicate()) + + if out: + self.logInfo(filename, out) + + if err: + self.logWarning(filename, err) + if not self.getConfig('ignore-err'): + self.logDebug("Delete/Quarantine task is aborted") + return + + if p.returncode: + pyfile.error = _("infected file") + action = self.getConfig('action') + try: + if action == "Delete": + os.remove(file) + + elif action == "Quarantine": + pyfile.setCustomStatus(_("file moving")) + pyfile.setProgress(0) + shutil.move(file, self.getConfig('quardir')) + + except (IOError, shutil.Error), e: + self.logError(filename, action + " action failed!", e) + + elif not out and not err: + self.logDebug(filename, "No infected file found") + + finally: + pyfile.setProgress(100) + thread.finishFile(pyfile) + + + def downloadFinished(self, pyfile): + return self.scan(pyfile) + + + def downloadFailed(self, pyfile): + #: Check if pyfile is still "failed", + # maybe might has been restarted in meantime + if pyfile.status == 8 and self.getConfig('scanfailed'): + return self.scan(pyfile) diff --git a/pyload/plugin/addon/Checksum.py b/pyload/plugin/addon/Checksum.py index 7ba5d7ab6..4b1380506 100644 --- a/pyload/plugin/addon/Checksum.py +++ b/pyload/plugin/addon/Checksum.py @@ -56,7 +56,6 @@ class Checksum(Addon): ("stickell" , "l.stickell@yahoo.it")] - interval = 0 #@TODO: Remove in 0.4.10 methods = {'sfv' : 'crc32', 'crc' : 'crc32', 'hash': 'md5'} @@ -72,7 +71,6 @@ class Checksum(Addon): 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) diff --git a/pyload/plugin/addon/ClickAndLoad.py b/pyload/plugin/addon/ClickAndLoad.py index 63647e30a..df8d09806 100644 --- a/pyload/plugin/addon/ClickAndLoad.py +++ b/pyload/plugin/addon/ClickAndLoad.py @@ -30,15 +30,12 @@ class ClickAndLoad(Addon): ("port" , "int" , "Port" , 9666), ("extern" , "bool", "Listen on the public network interface", True)] - __description__ = """Click'n'Load hook plugin""" + __description__ = """Click'n'Load addon plugin""" __license__ = "GPLv3" __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 diff --git a/pyload/plugin/addon/DeleteFinished.py b/pyload/plugin/addon/DeleteFinished.py index aad05891e..989271fa8 100644 --- a/pyload/plugin/addon/DeleteFinished.py +++ b/pyload/plugin/addon/DeleteFinished.py @@ -25,7 +25,6 @@ class DeleteFinished(Addon): ## overwritten methods ## def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 self.interval = self.MIN_CHECK_INTERVAL @@ -56,6 +55,7 @@ class DeleteFinished(Addon): # self.pluginConfigChanged(self.__name__, 'interval', interval) self.interval = max(self.MIN_CHECK_INTERVAL, self.getConfig('interval') * 60 * 60) self.addEvent('packageFinished', self.wakeup) + self.initPeriodical() ## own methods ## diff --git a/pyload/plugin/addon/DownloadScheduler.py b/pyload/plugin/addon/DownloadScheduler.py index ff65a478d..de961cc1f 100644 --- a/pyload/plugin/addon/DownloadScheduler.py +++ b/pyload/plugin/addon/DownloadScheduler.py @@ -20,14 +20,6 @@ class DownloadScheduler(Addon): ("stickell", "l.stickell@yahoo.it")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - 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): self.updateSchedule() diff --git a/pyload/plugin/addon/ExternalScripts.py b/pyload/plugin/addon/ExternalScripts.py index 139be1299..502a6dc7b 100644 --- a/pyload/plugin/addon/ExternalScripts.py +++ b/pyload/plugin/addon/ExternalScripts.py @@ -28,7 +28,6 @@ class ExternalScripts(Addon): "all_archives_extracted", "all_archives_processed", "allDownloadsFinished" , "allDownloadsProcessed" , "packageDeleted"] - interval = 0 #@TODO: Remove in 0.4.10 def setup(self): @@ -65,7 +64,7 @@ class ExternalScripts(Addon): return for filename in os.listdir(dir): - file = save_join(dir, filename) + file = fs_join(dir, filename) if not os.path.isfile(file): continue @@ -102,7 +101,7 @@ class ExternalScripts(Addon): self.callScript(script) - def coreExiting(self): + def exit(self): for script in self.scripts['pyload_restart' if self.core.do_restart else 'pyload_stop']: self.callScript(script) @@ -125,23 +124,23 @@ class ExternalScripts(Addon): def downloadFailed(self, pyfile): if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + download_folder = fs_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) + file = fs_join(download_folder, pyfile.name) self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file) def downloadFinished(self, pyfile): if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + download_folder = fs_join(self.config['general']['download_folder'], pyfile.package().folder) else: download_folder = self.config['general']['download_folder'] for script in self.scripts['download_finished']: - file = save_join(download_folder, pyfile.name) + file = fs_join(download_folder, pyfile.name) self.callScript(script, pyfile.id, pyfile.name, pyfile.pluginname, pyfile.url, file) @@ -157,7 +156,7 @@ class ExternalScripts(Addon): def packageFinished(self, pypack): if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + download_folder = fs_join(self.config['general']['download_folder'], pypack.folder) else: download_folder = self.config['general']['download_folder'] @@ -169,7 +168,7 @@ class ExternalScripts(Addon): pack = self.core.api.getPackageInfo(pid) if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pack.folder) + download_folder = fs_join(self.config['general']['download_folder'], pack.folder) else: download_folder = self.config['general']['download_folder'] @@ -179,7 +178,7 @@ class ExternalScripts(Addon): def package_extract_failed(self, pypack): if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + download_folder = fs_join(self.config['general']['download_folder'], pypack.folder) else: download_folder = self.config['general']['download_folder'] @@ -189,7 +188,7 @@ class ExternalScripts(Addon): def package_extracted(self, pypack): if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + download_folder = fs_join(self.config['general']['download_folder'], pypack.folder) else: download_folder = self.config['general']['download_folder'] diff --git a/pyload/plugin/addon/ExtractArchive.py b/pyload/plugin/addon/ExtractArchive.py index 3c71e7e1a..419ca609e 100644 --- a/pyload/plugin/addon/ExtractArchive.py +++ b/pyload/plugin/addon/ExtractArchive.py @@ -137,8 +137,6 @@ class ExtractArchive(Addon): def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - self.queue = ArchiveQueue(self, "Queue") self.failed = ArchiveQueue(self, "Failed") diff --git a/pyload/plugin/addon/IRCInterface.py b/pyload/plugin/addon/IRCInterface.py index 9038ce993..6d85a5681 100644 --- a/pyload/plugin/addon/IRCInterface.py +++ b/pyload/plugin/addon/IRCInterface.py @@ -37,9 +37,6 @@ 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) diff --git a/pyload/plugin/addon/JustPremium.py b/pyload/plugin/addon/JustPremium.py index e69bc24f6..b878f302d 100644 --- a/pyload/plugin/addon/JustPremium.py +++ b/pyload/plugin/addon/JustPremium.py @@ -21,11 +21,6 @@ class JustPremium(Addon): 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): diff --git a/pyload/plugin/addon/MergeFiles.py b/pyload/plugin/addon/MergeFiles.py index 374604d82..e0233af10 100644 --- a/pyload/plugin/addon/MergeFiles.py +++ b/pyload/plugin/addon/MergeFiles.py @@ -23,15 +23,9 @@ class MergeFiles(Addon): __authors__ = [("and9000", "me@has-no-mail.com")] - interval = 0 #@TODO: Remove in 0.4.10 - BUFFER_SIZE = 4096 - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 - - @threaded def packageFinished(self, pack): files = {} diff --git a/pyload/plugin/addon/MultiHome.py b/pyload/plugin/addon/MultiHome.py index 0cebf35b8..03974d6c6 100644 --- a/pyload/plugin/addon/MultiHome.py +++ b/pyload/plugin/addon/MultiHome.py @@ -17,11 +17,7 @@ class MultiHome(Addon): __authors__ = [("mkaay", "mkaay@mkaay.de")] - interval = 0 #@TODO: Remove in 0.4.10 - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 self.register = {} self.interfaces = [] diff --git a/pyload/plugin/addon/RestartFailed.py b/pyload/plugin/addon/RestartFailed.py index e34424a8c..c568bfb0a 100644 --- a/pyload/plugin/addon/RestartFailed.py +++ b/pyload/plugin/addon/RestartFailed.py @@ -40,3 +40,4 @@ class RestartFailed(Addon): def activate(self): # self.pluginConfigChanged(self.__name__, "interval", self.getConfig('interval')) self.interval = max(self.MIN_CHECK_INTERVAL, self.getConfig('interval') * 60) + self.initPeriodical() diff --git a/pyload/plugin/addon/RestartSlow.py b/pyload/plugin/addon/RestartSlow.py index cd503518d..34416e79a 100644 --- a/pyload/plugin/addon/RestartSlow.py +++ b/pyload/plugin/addon/RestartSlow.py @@ -22,11 +22,12 @@ class RestartSlow(Addon): 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 @@ -36,8 +37,8 @@ class RestartSlow(Addon): limit = 5 else: type = "premium" if self.pyfile.plugin.premium else "free" - time = max(30, self.getConfig("%s_time" % type) * 60) - limit = max(5, self.getConfig("%s_limit" % type) * 1024) + time = max(30, self.getConfig('%s_time' % type) * 60) + limit = max(5, self.getConfig('%s_limit' % type) * 1024) chunks = [chunk for chunk in self.pyfile.plugin.req.dl.chunks \ if chunk.id not in self.info['chunk'] or self.info['chunk'][chunk.id] is not (time, limit)] diff --git a/pyload/plugin/addon/SkipRev.py b/pyload/plugin/addon/SkipRev.py index 157b55bbd..1c42ddfd8 100644 --- a/pyload/plugin/addon/SkipRev.py +++ b/pyload/plugin/addon/SkipRev.py @@ -6,14 +6,14 @@ from types import MethodType from urllib import unquote from urlparse import urlparse -from module.PyFile import PyFile -from module.plugins.Hook import Hook -from module.plugins.Plugin import SkipDownload +from pyload.datatype.File import PyFile +from pyload.plugin.Addon import Addon +from pyload.plugin.Plugin import SkipDownload -class SkipRev(Hook): +class SkipRev(Addon): __name__ = "SkipRev" - __type__ = "hook" + __type__ = "addon" __version__ = "0.29" __config__ = [("mode" , "Auto;Manual", "Choose recovery archives to skip" , "Auto"), @@ -24,13 +24,6 @@ class SkipRev(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - 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() diff --git a/pyload/plugin/addon/UnSkipOnFail.py b/pyload/plugin/addon/UnSkipOnFail.py index 55de85082..f81066daa 100644 --- a/pyload/plugin/addon/UnSkipOnFail.py +++ b/pyload/plugin/addon/UnSkipOnFail.py @@ -16,9 +16,6 @@ class UnSkipOnFail(Addon): __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 diff --git a/pyload/plugin/addon/UpdateManager.py b/pyload/plugin/addon/UpdateManager.py index 643b5c2d1..cd8dc9a03 100644 --- a/pyload/plugin/addon/UpdateManager.py +++ b/pyload/plugin/addon/UpdateManager.py @@ -9,9 +9,9 @@ import time from operator import itemgetter -from module.network.RequestFactory import getURL -from module.plugins.Hook import Expose, Hook, threaded -from module.utils import save_join +from pyload.network.RequestFactory import getURL +from pyload.plugin.Addon import Expose, Addon, threaded +from pyload.utils import fs_join # Case-sensitive os.path.exists @@ -26,9 +26,9 @@ def exists(path): return False -class UpdateManager(Hook): +class UpdateManager(Addon): __name__ = "UpdateManager" - __type__ = "hook" + __type__ = "addon" __version__ = "0.50" __config__ = [("activated" , "bool", "Activated" , True ), @@ -43,14 +43,11 @@ class UpdateManager(Hook): __license__ = "GPLv3" __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - - interval = 0 - SERVER_URL = "http://updatemanager.pyload.org" MIN_CHECK_INTERVAL = 3 * 60 * 60 #: 3 hours - def coreReady(self): + def activate(self): if self.checkonstart: self.update() @@ -189,7 +186,7 @@ class UpdateManager(Hook): # Protect UpdateManager from self-removing try: - type_plugins.remove(("hook", "UpdateManager")) + type_plugins.remove(("addon", "UpdateManager")) except ValueError: pass @@ -242,7 +239,7 @@ class UpdateManager(Hook): m = VERSION.search(content) if m and m.group(2) == version: - with open(save_join("userplugins", prefix, filename), "wb") as f: + with open(fs_join("userplugins", prefix, filename), "wb") as f: f.write(content) updated.append((prefix, name)) @@ -288,12 +285,12 @@ class UpdateManager(Hook): rootplugins = os.path.join(pypath, "module", "plugins") for dir in ("userplugins", rootplugins): - py_filename = save_join(dir, type, name + ".py") + py_filename = fs_join(dir, type, name + ".py") pyc_filename = py_filename + "c" - if type == "hook": + if type == "addon": try: - self.manager.deactivateHook(name) + self.manager.deactivateAddon(name) except Exception, e: self.logDebug(e) diff --git a/pyload/plugin/addon/WindowsPhoneNotify.py b/pyload/plugin/addon/WindowsPhoneNotify.py index e61057f9f..341e682b2 100644 --- a/pyload/plugin/addon/WindowsPhoneNotify.py +++ b/pyload/plugin/addon/WindowsPhoneNotify.py @@ -3,12 +3,12 @@ import httplib import time -from module.plugins.Hook import Hook, Expose +from pyload.plugin.Addon import Addon, Expose -class WindowsPhoneNotify(Hook): +class WindowsPhoneNotify(Addon): __name__ = "WindowsPhoneNotify" - __type__ = "hook" + __type__ = "addon" __version__ = "0.09" __config__ = [("id" , "str" , "Push ID" , "" ), @@ -29,11 +29,9 @@ class WindowsPhoneNotify(Hook): 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.notifications = 0 @@ -45,7 +43,7 @@ class WindowsPhoneNotify(Hook): self.notify(_("Plugins updated"), str(type_plugins)) - def coreExiting(self): + def exit(self): if not self.getConfig('notifyexit'): return |