diff options
Diffstat (limited to 'module/plugins/hooks/SkipRev.py')
-rw-r--r-- | module/plugins/hooks/SkipRev.py | 58 |
1 files changed, 23 insertions, 35 deletions
diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index 7901ca540..a1ddc3094 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -7,14 +7,14 @@ import urlparse from types import MethodType from module.PyFile import PyFile -from module.plugins.Hook import Hook -from module.plugins.Plugin import SkipDownload +from module.plugins.internal.Addon import Addon -class SkipRev(Hook): +class SkipRev(Addon): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.29" + __version__ = "0.33" + __status__ = "testing" __config__ = [("mode" , "Auto;Manual", "Choose recovery archives to skip" , "Auto"), ("revtokeep", "int" , "Number of recovery archives to keep for package", 0 )] @@ -24,30 +24,19 @@ 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() + def _init(self): + self.pyfile.plugin._init() if self.pyfile.hasStatus("skipped"): - raise SkipDownload(self.pyfile.statusname or self.pyfile.pluginname) + self.skip(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.urlparse(urllib.unquote(pyfile.url)).path.split('/')[-1] + return pyfile.pluginclass.get_info(pyfile.url)['name'] def _pyfile(self, link): - return PyFile(self.core.files, + return PyFile(self.pyload.files, link.fid, link.url, link.name, @@ -59,47 +48,46 @@ class SkipRev(Hook): link.order) - def downloadPreparing(self, pyfile): + def download_preparing(self, pyfile): name = self._name(pyfile) if pyfile.statusname is _("unskipped") or not name.endswith(".rev") or not ".part" in name: return - revtokeep = -1 if self.getConfig('mode') == "Auto" else self.getConfig('revtokeep') + revtokeep = -1 if self.get_config('mode') == "Auto" else self.get_config('revtokeep') 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 \ + queued = [True for link in self.pyload.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 + if not queued or queued < revtokeep: #: Keep one rev at least in auto mode return pyfile.setCustomStatus("SkipRev", "skipped") - 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) + if not hasattr(pyfile.plugin, "_init"): + #: Work-around: inject status checker inside the preprocessing routine of the plugin + pyfile.plugin._init = pyfile.plugin.init + pyfile.plugin.init = MethodType(self._init, pyfile.plugin) - def downloadFailed(self, pyfile): - #: Check if pyfile is still "failed", - # maybe might has been restarted in meantime + def download_failed(self, pyfile): + #: 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 - revtokeep = -1 if self.getConfig('mode') == "Auto" else self.getConfig('revtokeep') + revtokeep = -1 if self.get_config('mode') == "Auto" else self.get_config('revtokeep') 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 pyname.match(link.name): + for link in self.pyload.api.getPackageData(pyfile.package().id).links: + if link.status == 4 and pyname.match(link.name): pylink = self._pyfile(link) if revtokeep > -1 or pyfile.name.endswith(".rev"): @@ -107,6 +95,6 @@ class SkipRev(Hook): else: pylink.setCustomStatus(_("unskipped"), "queued") - self.core.files.save() + self.pyload.files.save() pylink.release() return |