From 9ad979dc5b3753e2982855495b240b3da37c3be4 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 2 Dec 2014 12:37:56 +0100 Subject: [SkipRev] Updated --- module/plugins/hooks/SkipRev.py | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 module/plugins/hooks/SkipRev.py (limited to 'module/plugins/hooks/SkipRev.py') diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py new file mode 100644 index 000000000..3b3b450fe --- /dev/null +++ b/module/plugins/hooks/SkipRev.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +import re + +from module.plugins.Hook import Hook +from module.plugins.Plugin import SkipDownload + + +class SkipRev(Hook): + __name__ = "SkipRev" + __type__ = "hook" + __version__ = "0.08" + + __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True) + ("tokeep", "int" , "Min number of rev files to keep for package" , 1), + ("unskip", "bool", "Restart a skipped rev when download fails" , True)] + + __description__ = """Skip files ending with extension rev""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + event_map = [("downloadStarts", skipRev)] + + REV = re.compile(r'\.part(\d+)\.rev$') + + + def skipRev(self, pyfile, url, filename): + if REV.search(pyfile.name) is None or pyfile.getStatusName is "unskipped": + return + + tokeep = self.getConfig("tokeep") + + if tokeep > 0: + saved = [True if link.hasStatus("finished") or link.hasStatus("downloading") and REV.search(link.name) \ + for link in pyfile.package().getChildren()].count(True) + + if saved < tokeep: + return + + raise SkipDownload("SkipRev") + + + def downloadFailed(self, pyfile): + if self.getConfig("auto") is False: + + if self.getConfig("unskip") is False: + return + + if REV.search(pyfile.name) is None: + return + + for link in pyfile.package().getChildren(): + if link.hasStatus("skipped") and REV.search(link.name): + link.setCustomStatus("unskipped", "queued") + break -- cgit v1.2.3 From a611ddfd1d8e4a85b2066cc45bc51682ac10a5f7 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 2 Dec 2014 16:35:12 +0100 Subject: [SkipRev] Fixup 1 --- module/plugins/hooks/SkipRev.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/SkipRev.py') diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index 3b3b450fe..e9cfa2ec5 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -9,10 +9,10 @@ from module.plugins.Plugin import SkipDownload class SkipRev(Hook): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.08" + __version__ = "0.09" - __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True) - ("tokeep", "int" , "Min number of rev files to keep for package" , 1), + __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True), + ("tokeep", "int" , "Min number of rev files to keep for package" , 1), ("unskip", "bool", "Restart a skipped rev when download fails" , True)] __description__ = """Skip files ending with extension rev""" @@ -53,4 +53,4 @@ class SkipRev(Hook): for link in pyfile.package().getChildren(): if link.hasStatus("skipped") and REV.search(link.name): link.setCustomStatus("unskipped", "queued") - break + return -- cgit v1.2.3 From a5a6cc0643c562a0d3e55a8577b4fc391009ff2b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 2 Dec 2014 17:00:36 +0100 Subject: [SkipRev] Typo --- module/plugins/hooks/SkipRev.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/SkipRev.py') diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index e9cfa2ec5..a64f1a83b 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -9,7 +9,7 @@ from module.plugins.Plugin import SkipDownload class SkipRev(Hook): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.09" + __version__ = "0.10" __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True), ("tokeep", "int" , "Min number of rev files to keep for package" , 1), @@ -26,7 +26,7 @@ class SkipRev(Hook): def skipRev(self, pyfile, url, filename): - if REV.search(pyfile.name) is None or pyfile.getStatusName is "unskipped": + if REV.search(pyfile.name) is None or pyfile.getStatusName() is "unskipped": return tokeep = self.getConfig("tokeep") -- cgit v1.2.3 From 69add4e0f3df7f078eafa022e9a59ac21cfaa19b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 3 Dec 2014 00:28:06 +0100 Subject: [SkipRev] Syntax fixes --- module/plugins/hooks/SkipRev.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'module/plugins/hooks/SkipRev.py') diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index a64f1a83b..feed16a2b 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -9,7 +9,7 @@ from module.plugins.Plugin import SkipDownload class SkipRev(Hook): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.10" + __version__ = "0.11" __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True), ("tokeep", "int" , "Min number of rev files to keep for package" , 1), @@ -20,20 +20,20 @@ class SkipRev(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - event_map = [("downloadStarts", skipRev)] + event_list = ["downloadStarts"] REV = re.compile(r'\.part(\d+)\.rev$') - def skipRev(self, pyfile, url, filename): - if REV.search(pyfile.name) is None or pyfile.getStatusName() is "unskipped": + def downloadStarts(self, pyfile, url, filename): + if self.REV.search(pyfile.name) is None or pyfile.getStatusName() is "unskipped": return tokeep = self.getConfig("tokeep") if tokeep > 0: - saved = [True if link.hasStatus("finished") or link.hasStatus("downloading") and REV.search(link.name) \ - for link in pyfile.package().getChildren()].count(True) + saved = [True for link in pyfile.package().getChildren() \ + if link.hasStatus("finished") or link.hasStatus("downloading") and self.REV.search(link.name)].count(True) if saved < tokeep: return @@ -47,10 +47,10 @@ class SkipRev(Hook): if self.getConfig("unskip") is False: return - if REV.search(pyfile.name) is None: + if self.REV.search(pyfile.name) is None: return for link in pyfile.package().getChildren(): - if link.hasStatus("skipped") and REV.search(link.name): + if link.hasStatus("skipped") and self.REV.search(link.name): link.setCustomStatus("unskipped", "queued") return -- cgit v1.2.3 From 7c4c7d4d124b790843ccf6e8150866016e9847a9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 6 Dec 2014 18:11:58 +0100 Subject: [SkipRev] Update --- module/plugins/hooks/SkipRev.py | 42 ++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'module/plugins/hooks/SkipRev.py') diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index feed16a2b..a44d20a3e 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -2,6 +2,9 @@ import re +from urllib import unquote +from urlparse import urljoin, urlparse + from module.plugins.Hook import Hook from module.plugins.Plugin import SkipDownload @@ -9,7 +12,7 @@ from module.plugins.Plugin import SkipDownload class SkipRev(Hook): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.11" + __version__ = "0.12" __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True), ("tokeep", "int" , "Min number of rev files to keep for package" , 1), @@ -20,25 +23,46 @@ class SkipRev(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - event_list = ["downloadStarts"] + def _setup(self): + super(self.pyfile.plugin, self).setup() + if self.pyfile.hasStatus("skipped"): + raise SkipDownload(self.pyfile.getStatusName()) + + + def pyname(self, pyfile): + plugin = pyfile.plugin + + if hasattr(plugin, "info") and 'name' in plugin.info and plugin.info['name']: + name = plugin.info['name'] + + elif hasattr(plugin, "parseInfo"): + name = next(plugin.parseInfo([pyfile.url]))['name'] + + elif hasattr(plugin, "getInfo"): #@NOTE: if parseInfo was not found, getInfo should be missing too + name = plugin.getInfo(pyfile.url)['name'] + + else: + self.logWarning("Unable to grab file name") + name = urlparse(unquote(pyfile.url)).path.split('/')[-1]) - REV = re.compile(r'\.part(\d+)\.rev$') + return name - def downloadStarts(self, pyfile, url, filename): - if self.REV.search(pyfile.name) is None or pyfile.getStatusName() is "unskipped": + def downloadPreparing(self, pyfile): + if pyfile.getStatusName() is "unskipped" or not pyname(pyfile).endswith(".rev"): return tokeep = self.getConfig("tokeep") if tokeep > 0: saved = [True for link in pyfile.package().getChildren() \ - if link.hasStatus("finished") or link.hasStatus("downloading") and self.REV.search(link.name)].count(True) + if link.name.endswith(".rev") and (link.hasStatus("finished") or link.hasStatus("downloading"))].count(True) if saved < tokeep: return - raise SkipDownload("SkipRev") + pyfile.setCustomStatus("SkipRev", "skipped") + pyfile.plugin.setup = _setup #: work-around: inject status checker inside the preprocessing routine of the plugin def downloadFailed(self, pyfile): @@ -47,10 +71,10 @@ class SkipRev(Hook): if self.getConfig("unskip") is False: return - if self.REV.search(pyfile.name) is None: + if not pyfile.name.endswith(".rev"): return for link in pyfile.package().getChildren(): - if link.hasStatus("skipped") and self.REV.search(link.name): + if link.hasStatus("skipped") and link.name.endswith(".rev"): link.setCustomStatus("unskipped", "queued") return -- cgit v1.2.3 From 2e35201317a88f87b7a0e0ff448f3f55eb1861a9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 7 Dec 2014 14:54:27 +0100 Subject: [SkipRev] Tiny fixup --- module/plugins/hooks/SkipRev.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/SkipRev.py') diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index a44d20a3e..76a48a255 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -12,7 +12,7 @@ from module.plugins.Plugin import SkipDownload class SkipRev(Hook): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.12" + __version__ = "0.13" __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True), ("tokeep", "int" , "Min number of rev files to keep for package" , 1), @@ -26,24 +26,25 @@ class SkipRev(Hook): def _setup(self): super(self.pyfile.plugin, self).setup() if self.pyfile.hasStatus("skipped"): - raise SkipDownload(self.pyfile.getStatusName()) + raise SkipDownload(self.pyfile.getStatusName() or self.pyfile.pluginname) def pyname(self, pyfile): + url = pyfile.url plugin = pyfile.plugin if hasattr(plugin, "info") and 'name' in plugin.info and plugin.info['name']: name = plugin.info['name'] elif hasattr(plugin, "parseInfo"): - name = next(plugin.parseInfo([pyfile.url]))['name'] + name = next(plugin.parseInfo([url]))['name'] elif hasattr(plugin, "getInfo"): #@NOTE: if parseInfo was not found, getInfo should be missing too - name = plugin.getInfo(pyfile.url)['name'] + name = plugin.getInfo(url)['name'] else: self.logWarning("Unable to grab file name") - name = urlparse(unquote(pyfile.url)).path.split('/')[-1]) + name = urlparse(unquote(url)).path.split('/')[-1]) return name -- cgit v1.2.3