diff options
author | Walter Purcaro <vuolter@gmail.com> | 2013-11-17 19:29:37 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2013-11-23 17:39:12 +0100 |
commit | 92888358e14c0a9e50e5604095a1c148ccc8b80d (patch) | |
tree | 2c3f5b0c141ac90e34e2c8360886bc14f9715edd /module/plugins/internal/MultiHoster.py | |
parent | Merge pull request #386 from vuolter/s/setup_clean (diff) | |
download | pyload-92888358e14c0a9e50e5604095a1c148ccc8b80d.tar.xz |
Internal plugins PEP8 cleanup
Diffstat (limited to 'module/plugins/internal/MultiHoster.py')
-rw-r--r-- | module/plugins/internal/MultiHoster.py | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py index a8961aafc..bd6dc7877 100644 --- a/module/plugins/internal/MultiHoster.py +++ b/module/plugins/internal/MultiHoster.py @@ -6,6 +6,7 @@ import re from module.utils import remove_chars from module.plugins.Hook import Hook + class MultiHoster(Hook): """ Generic MultiHoster plugin @@ -14,19 +15,19 @@ class MultiHoster(Hook): __version__ = "0.19" replacements = [("2shared.com", "twoshared.com"), ("4shared.com", "fourshared.com"), ("cloudnator.com", "shragle.com"), - ("ifile.it", "filecloud.io"), ("easy-share.com","crocko.com"), ("freakshare.net","freakshare.com"), - ("hellshare.com", "hellshare.cz"), ("share-rapid.cz","sharerapid.com"), ("sharerapid.cz","sharerapid.com"), - ("ul.to","uploaded.to"), ("uploaded.net","uploaded.to"), ("1fichier.com", "onefichier.com")] + ("ifile.it", "filecloud.io"), ("easy-share.com", "crocko.com"), ("freakshare.net", "freakshare.com"), + ("hellshare.com", "hellshare.cz"), ("share-rapid.cz", "sharerapid.com"), ("sharerapid.cz", "sharerapid.com"), + ("ul.to", "uploaded.to"), ("uploaded.net", "uploaded.to"), ("1fichier.com", "onefichier.com")] ignored = [] - interval = 24 * 60 * 60 # reload hosters daily - + interval = 24 * 60 * 60 #: reload hosters daily + def setup(self): self.hosters = [] self.supported = [] self.new_supported = [] - - def getConfig(self, option, default = ''): - """getConfig with default value - sublass may not implements all config options""" + + def getConfig(self, option, default=''): + """getConfig with default value - sublass may not implements all config options""" try: return self.getConf(option) except KeyError: @@ -40,33 +41,33 @@ class MultiHoster(Hook): except Exception, e: self.logError("%s" % str(e)) return [] - - try: + + try: configMode = self.getConfig('hosterListMode', 'all') if configMode in ("listed", "unlisted"): - configSet = self.toHosterSet(self.getConfig('hosterList', '').replace('|',',').replace(';',',').split(',')) - + configSet = self.toHosterSet(self.getConfig('hosterList', '').replace('|', ',').replace(';', ',').split(',')) + if configMode == "listed": hosterSet &= configSet else: hosterSet -= configSet - + except Exception, e: self.logError("%s" % str(e)) - + self.hosters = list(hosterSet) return self.hosters - + def toHosterSet(self, hosters): hosters = set((str(x).strip().lower() for x in hosters)) - + for rep in self.replacements: if rep[0] in hosters: hosters.remove(rep[0]) hosters.add(rep[1]) - - hosters.discard('') + + hosters.discard('') return hosters def getHoster(self): @@ -75,34 +76,34 @@ class MultiHoster(Hook): :return: List of domain names """ raise NotImplementedError - + def coreReady(self): if self.cb: self.core.scheduler.removeJob(self.cb) - - self.setConfig("activated", True) # config not in sync after plugin reload - - cfg_interval = self.getConfig("interval", None) # reload interval in hours + + self.setConfig("activated", True) #: config not in sync after plugin reload + + cfg_interval = self.getConfig("interval", None) #: reload interval in hours if cfg_interval is not None: - self.interval = cfg_interval * 60 * 60 - + self.interval = cfg_interval * 60 * 60 + if self.interval: self._periodical() else: self.periodical() - + def initPeriodical(self): - pass - + pass + def periodical(self): """reload hoster list periodically""" self.logInfo("Reloading supported hoster list") - + old_supported = self.supported self.supported, self.new_supported, self.hosters = [], [], [] - + self.overridePlugins() - + old_supported = [hoster for hoster in old_supported if hoster not in self.supported] if old_supported: self.logDebug("UNLOAD: %s" % ", ".join(old_supported)) @@ -113,15 +114,15 @@ class MultiHoster(Hook): pluginMap = {} for name in self.core.pluginManager.hosterPlugins.keys(): pluginMap[name.lower()] = name - - accountList = [ name.lower() for name, data in self.core.accountManager.accounts.items() if data ] + + accountList = [name.lower() for name, data in self.core.accountManager.accounts.items() if data] excludedList = [] - + for hoster in self.getHosterCached(): name = remove_chars(hoster.lower(), "-.") if name in accountList: - excludedList.append(hoster) + excludedList.append(hoster) else: if name in pluginMap: self.supported.append(pluginMap[name]) @@ -134,27 +135,27 @@ class MultiHoster(Hook): module = self.core.pluginManager.getPlugin(self.__name__) klass = getattr(module, self.__name__) - + # inject plugin plugin self.logDebug("Overwritten Hosters: %s" % ", ".join(sorted(self.supported))) for hoster in self.supported: dict = self.core.pluginManager.hosterPlugins[hoster] dict["new_module"] = module dict["new_name"] = self.__name__ - + if excludedList: self.logInfo("The following hosters were not overwritten - account exists: %s" % ", ".join(sorted(excludedList))) if self.new_supported: self.logDebug("New Hosters: %s" % ", ".join(sorted(self.new_supported))) - + # create new regexp - regexp = r".*(%s).*" % "|".join([x.replace(".", "\\.") for x in self.new_supported]) + regexp = r".*(%s).*" % "|".join([x.replace(".", "\\.") for x in self.new_supported]) if hasattr(klass, "__pattern__") and isinstance(klass.__pattern__, basestring) and '://' in klass.__pattern__: regexp = r"%s|%s" % (klass.__pattern__, regexp) - + self.logDebug("Regexp: %s" % regexp) - + dict = self.core.pluginManager.hosterPlugins[self.__name__] dict["pattern"] = regexp dict["re"] = re.compile(regexp) @@ -172,18 +173,18 @@ class MultiHoster(Hook): """Remove override for all hosters. Scheduler job is removed by hookmanager""" for hoster in self.supported: self.unloadHoster(hoster) - + # reset pattern klass = getattr(self.core.pluginManager.getPlugin(self.__name__), self.__name__) dict = self.core.pluginManager.hosterPlugins[self.__name__] - dict["pattern"] = getattr(klass, '__pattern__', r"^unmatchable$") - dict["re"] = re.compile(dict["pattern"]) - + dict["pattern"] = getattr(klass, '__pattern__', r"^unmatchable$") + dict["re"] = re.compile(dict["pattern"]) + def downloadFailed(self, pyfile): - """remove plugin override if download fails but not if file is offline/temp.offline""" + """remove plugin override if download fails but not if file is offline/temp.offline""" if pyfile.hasStatus("failed") and self.getConfig("unloadFailing", True): hdict = self.core.pluginManager.hosterPlugins[pyfile.pluginname] if "new_name" in hdict and hdict['new_name'] == self.__name__: - self.logDebug("Unload MultiHoster", pyfile.pluginname, hdict) + self.logDebug("Unload MultiHoster", pyfile.pluginname, hdict) self.unloadHoster(pyfile.pluginname) - pyfile.setStatus("queued")
\ No newline at end of file + pyfile.setStatus("queued") |