summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/SkipRev.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hooks/SkipRev.py')
-rw-r--r--module/plugins/hooks/SkipRev.py89
1 files changed, 49 insertions, 40 deletions
diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py
index 1eaee0118..7901ca540 100644
--- a/module/plugins/hooks/SkipRev.py
+++ b/module/plugins/hooks/SkipRev.py
@@ -1,55 +1,49 @@
# -*- coding: utf-8 -*-
+import re
+import urllib
+import urlparse
+
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
-def _setup(self):
- self.pyfile.plugin._setup()
- if self.pyfile.hasStatus("skipped"):
- raise SkipDownload(self.pyfile.statusname or self.pyfile.pluginname)
-
-
class SkipRev(Hook):
__name__ = "SkipRev"
__type__ = "hook"
- __version__ = "0.20"
+ __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")]
- #@TODO: Remove in 0.4.10
- def initPeriodical(self):
- pass
+ interval = 0 #@TODO: Remove in 0.4.10
- def _pyname(self, pyfile):
- url = pyfile.url
- plugin = pyfile.plugin
+ def setup(self):
+ self.info = {} #@TODO: Remove in 0.4.10
- if hasattr(plugin, "info") and 'name' in plugin.info and plugin.info['name']:
- name = plugin.info['name']
- elif hasattr(plugin, "parseInfos"):
- name = next(plugin.parseInfos([url]))['name']
+ @staticmethod
+ def _setup(self):
+ self.pyfile.plugin._setup()
+ if self.pyfile.hasStatus("skipped"):
+ raise SkipDownload(self.pyfile.statusname or self.pyfile.pluginname)
- elif hasattr(plugin, "getInfo"): #@NOTE: if parseInfos was not found, getInfo should be missing too
- name = plugin.getInfo(url)['name']
+ 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")
- name = urlparse(unquote(url)).path.split('/')[-1]
-
- return name
+ return urlparse.urlparse(urllib.unquote(pyfile.url)).path.split('/')[-1]
def _pyfile(self, link):
@@ -66,37 +60,52 @@ class SkipRev(Hook):
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:
- saved = [True for link in self.core.api.getPackageData(pyfile.packageid).links \
- if link.name.endswith(".rev") and link.status in (0, 12)].count(True)
+ 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('.', '\.'))
- if not saved or saved < tokeep: #: keep one rev at least in auto mode
+ queued = [True for link in self.core.api.getPackageData(pyfile.package().id).links \
+ if link.status not in status_list and pyname.match(link.name)].count(True)
+
+ 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):
- tokeep = self.getConfig("tokeep")
+ #: Check if pyfile is still "failed",
+ # maybe might has been restarted in meantime
+ if pyfile.status != 8 or pyfile.name.rsplit('.', 1)[-1].strip() not in ("rar", "rev"):
+ return
- if not tokeep:
+ revtokeep = -1 if self.getConfig('mode') == "Auto" else self.getConfig('revtokeep')
+
+ if not revtokeep:
return
- for link in self.core.api.getPackageData(pyfile.packageid).links:
- if link.status is 4 and link.name.endswith(".rev"):
+ 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 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()