diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-06-15 21:06:10 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-06-24 22:38:26 +0200 |
commit | 5a139055ae658d3a05cbb658cbd66aeae0d01db5 (patch) | |
tree | b283d2f470fe2a4115474959e4982a59bc686067 | |
parent | Merge pull request #1537 from GammaC0de/patch-1 (diff) | |
download | pyload-5a139055ae658d3a05cbb658cbd66aeae0d01db5.tar.xz |
Spare code cosmetics
40 files changed, 163 insertions, 164 deletions
diff --git a/module/plugins/accounts/LinksnappyCom.py b/module/plugins/accounts/LinksnappyCom.py index 9d5202945..2b1d1aebf 100644 --- a/module/plugins/accounts/LinksnappyCom.py +++ b/module/plugins/accounts/LinksnappyCom.py @@ -10,6 +10,7 @@ class LinksnappyCom(Account): __name__ = "LinksnappyCom" __type__ = "account" __version__ = "0.06" + __description__ = """Linksnappy.com account plugin""" __license__ = "GPLv3" __authors__ = [("stickell", "l.stickell@yahoo.it")] @@ -25,7 +26,7 @@ class LinksnappyCom(Account): j = json_loads(r) if j['error']: - return {"premium": False} + return {'premium': False} validuntil = j['return']['expire'] @@ -33,7 +34,7 @@ class LinksnappyCom(Account): validuntil = -1 elif validuntil == 'expired': - return {"premium": False} + return {'premium': False} else: validuntil = float(validuntil) @@ -43,15 +44,17 @@ class LinksnappyCom(Account): else: trafficleft = self.parseTraffic("%d MB" % j['return']['trafficleft']) - return {"premium": True, "validuntil": validuntil, "trafficleft": trafficleft} + return {'premium' : True , + 'validuntil' : validuntil , + 'trafficleft': trafficleft} def login(self, user, data, req): - r = req.load("https://gen.linksnappy.com/lseAPI.php", - get={'act' : 'USERDETAILS', - 'username': user, - 'password': hashlib.md5(data['password']).hexdigest()}, - decode=True) + html = req.load("https://gen.linksnappy.com/lseAPI.php", + get={'act' : 'USERDETAILS', + 'username': user, + 'password': hashlib.md5(data['password']).hexdigest()}, + decode=True) - if 'Invalid Account Details' in r: + if "Invalid Account Details" in html: self.wrongPassword() diff --git a/module/plugins/container/CCF.py b/module/plugins/container/CCF.py index 082786e2b..395f8c953 100644 --- a/module/plugins/container/CCF.py +++ b/module/plugins/container/CCF.py @@ -7,7 +7,7 @@ import re import urllib2 from module.plugins.internal.Container import Container -from module.utils import fs_encode, save_join +from module.utils import fs_encode, save_join as fs_join class CCF(Container): @@ -32,8 +32,8 @@ class CCF(Container): 'filename': "test.ccf", 'upload' : open(fs_filename, "rb")}).read() - download_folder = self.config['general']['download_folder'] - dlc_file = save_join(download_folder, "tmp_%s.dlc" % pyfile.name) + download_folder = self.core.config['general']['download_folder'] + dlc_file = fs_join(download_folder, "tmp_%s.dlc" % pyfile.name) try: dlc = re.search(r'<dlc>(.+)</dlc>', dlc_content, re.S).group(1).decode('base64') diff --git a/module/plugins/crypter/DailymotionComFolder.py b/module/plugins/crypter/DailymotionComFolder.py index 2458b15b1..26e870d31 100644 --- a/module/plugins/crypter/DailymotionComFolder.py +++ b/module/plugins/crypter/DailymotionComFolder.py @@ -5,7 +5,7 @@ import urlparse from module.common.json_layer import json_loads from module.plugins.internal.Crypter import Crypter -from module.utils import save_join +from module.utils import save_join as fs_join class DailymotionComFolder(Crypter): @@ -100,6 +100,6 @@ class DailymotionComFolder(Crypter): for p_id, p_name, p_owner in playlists: p_videos = self.getVideos(p_id) - p_folder = save_join(self.config['general']['download_folder'], p_owner, p_name) + p_folder = fs_join(self.core.config['general']['download_folder'], p_owner, p_name) self.logDebug("%s video\s found on playlist \"%s\"" % (len(p_videos), p_name)) self.packages.append((p_name, p_videos, p_folder)) #: folder is NOT recognized by pyload 0.4.9! diff --git a/module/plugins/crypter/RelinkUs.py b/module/plugins/crypter/RelinkUs.py index 7dfb3876f..316d44b4c 100644 --- a/module/plugins/crypter/RelinkUs.py +++ b/module/plugins/crypter/RelinkUs.py @@ -8,7 +8,7 @@ import os from Crypto.Cipher import AES from module.plugins.internal.Crypter import Crypter -from module.utils import save_join +from module.utils import save_join as fs_join class RelinkUs(Crypter): @@ -219,7 +219,7 @@ class RelinkUs(Crypter): try: dlc = self.load(container_url) dlc_filename = self.fileid + ".dlc" - dlc_filepath = save_join(self.config['general']['download_folder'], dlc_filename) + dlc_filepath = fs_join(self.core.config['general']['download_folder'], dlc_filename) with open(dlc_filepath, "wb") as f: f.write(dlc) package_links.append(dlc_filepath) diff --git a/module/plugins/crypter/YoutubeComFolder.py b/module/plugins/crypter/YoutubeComFolder.py index bcaa7effe..29a889615 100644 --- a/module/plugins/crypter/YoutubeComFolder.py +++ b/module/plugins/crypter/YoutubeComFolder.py @@ -5,7 +5,7 @@ import urlparse from module.common.json_layer import json_loads from module.plugins.internal.Crypter import Crypter -from module.utils import save_join +from module.utils import save_join as fs_join class YoutubeComFolder(Crypter): @@ -131,7 +131,7 @@ class YoutubeComFolder(Crypter): for p in playlists: p_name = p['title'] p_videos = self.getVideosId(p['id']) - p_folder = save_join(self.config['general']['download_folder'], p['channelTitle'], p_name) + p_folder = fs_join(self.core.config['general']['download_folder'], p['channelTitle'], p_name) self.logDebug("%s video\s found on playlist \"%s\"" % (len(p_videos), p_name)) if not p_videos: diff --git a/module/plugins/hooks/AndroidPhoneNotify.py b/module/plugins/hooks/AndroidPhoneNotify.py index c9493bfd0..e775b785b 100644 --- a/module/plugins/hooks/AndroidPhoneNotify.py +++ b/module/plugins/hooks/AndroidPhoneNotify.py @@ -67,7 +67,7 @@ class AndroidPhoneNotify(Hook): self.notify(_("Captcha"), _("New request waiting user input")) - def packageFinished(self, pypack): + def package_finished(self, pypack): if self.getConfig('notifypackage'): self.notify(_("Package finished"), pypack.name) diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py index 09872650f..1faa6ebe3 100644 --- a/module/plugins/hooks/AntiVirus.py +++ b/module/plugins/hooks/AntiVirus.py @@ -10,7 +10,7 @@ except ImportError: pass from module.plugins.internal.Hook import Hook, Expose, threaded -from module.utils import fs_encode, save_join +from module.utils import fs_encode, save_join as fs_join class AntiVirus(Hook): @@ -108,11 +108,11 @@ class AntiVirus(Hook): thread.finishFile(pyfile) - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): return self.scan(pyfile) - def downloadFailed(self, pyfile): + def download_failed(self, pyfile): #: Check if pyfile is still "failed", # maybe might has been restarted in meantime if pyfile.status == 8 and self.getConfig('scanfailed'): diff --git a/module/plugins/hooks/BypassCaptcha.py b/module/plugins/hooks/BypassCaptcha.py index 4b50ef800..bbbe96b73 100644 --- a/module/plugins/hooks/BypassCaptcha.py +++ b/module/plugins/hooks/BypassCaptcha.py @@ -118,12 +118,12 @@ class BypassCaptcha(Hook): self.logInfo(_("Your %s account has not enough credits") % self.__name__) - def captchaCorrect(self, task): + def captcha_correct(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: self.respond(task.data['ticket'], True) - def captchaInvalid(self, task): + def captcha_invalid(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: self.respond(task.data['ticket'], False) diff --git a/module/plugins/hooks/Captcha9Kw.py b/module/plugins/hooks/Captcha9Kw.py index ea15d7651..85bbb7924 100644 --- a/module/plugins/hooks/Captcha9Kw.py +++ b/module/plugins/hooks/Captcha9Kw.py @@ -246,9 +246,9 @@ class Captcha9Kw(Hook): self.logDebug("Could not send %s request: %s" % (type, res)) - def captchaCorrect(self, task): + def captcha_correct(self, task): self._captchaResponse(task, True) - def captchaInvalid(self, task): + def captcha_invalid(self, task): self._captchaResponse(task, False) diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py index eecf49515..1f2bbf956 100644 --- a/module/plugins/hooks/CaptchaBrotherhood.py +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -154,7 +154,7 @@ class CaptchaBrotherhood(Hook): self.logInfo(_("Your CaptchaBrotherhood Account has not enough credits")) - def captchaInvalid(self, task): + def captcha_invalid(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: res = self.api_response("complainCaptcha", task.data['ticket']) diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index f132c37d1..9287fda9c 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -8,7 +8,7 @@ import re import zlib from module.plugins.internal.Hook import Hook -from module.utils import save_join, fs_encode +from module.utils import save_join as fs_join, fs_encode def computeChecksum(local_file, algorithm): @@ -78,7 +78,7 @@ class Checksum(Hook): self.formats = self.algorithms + ["sfv", "crc", "hash"] - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): """ Compute checksum for the downloaded file and compare it with the hash provided by the hoster. pyfile.plugin.check_data should be a dictionary which can contain: @@ -104,8 +104,8 @@ class Checksum(Hook): self.checkFailed(pyfile, None, "No file downloaded") local_file = fs_encode(pyfile.plugin.lastDownload) - #download_folder = self.config['general']['download_folder'] - #local_file = fs_encode(save_join(download_folder, pyfile.package().folder, pyfile.name)) + #download_folder = self.core.config['general']['download_folder'] + #local_file = fs_encode(fs_join(download_folder, pyfile.package().folder, pyfile.name)) if not os.path.isfile(local_file): self.checkFailed(pyfile, None, "File does not exist") @@ -164,8 +164,8 @@ class Checksum(Hook): pyfile.plugin.fail(reason=msg) - def packageFinished(self, pypack): - download_folder = save_join(self.config['general']['download_folder'], pypack.folder, "") + def package_finished(self, pypack): + download_folder = fs_join(self.core.config['general']['download_folder'], pypack.folder, "") for link in pypack.getChildren().itervalues(): file_type = os.path.splitext(link['name'])[1][1:].lower() @@ -173,7 +173,7 @@ class Checksum(Hook): if file_type not in self.formats: continue - hash_file = fs_encode(save_join(download_folder, link['name'])) + hash_file = fs_encode(fs_join(download_folder, link['name'])) if not os.path.isfile(hash_file): self.logWarning(_("File not found"), link['name']) continue @@ -185,7 +185,7 @@ class Checksum(Hook): data = m.groupdict() self.logDebug(link['name'], data) - local_file = fs_encode(save_join(download_folder, data['NAME'])) + local_file = fs_encode(fs_join(download_folder, data['NAME'])) algorithm = self.methods.get(file_type, file_type) checksum = computeChecksum(local_file, algorithm) if checksum == data['HASH']: diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py index e9e231a28..81a446ef3 100644 --- a/module/plugins/hooks/ClickAndLoad.py +++ b/module/plugins/hooks/ClickAndLoad.py @@ -49,11 +49,11 @@ class ClickAndLoad(Hook): def activate(self): - if not self.config['webinterface']['activated']: + if not self.core.config['webinterface']['activated']: return ip = "" if self.getConfig('extern') else "127.0.0.1" - webport = self.config['webinterface']['port'] + webport = self.core.config['webinterface']['port'] cnlport = self.getConfig('port') self.proxy(ip, webport, cnlport) @@ -85,7 +85,7 @@ class ClickAndLoad(Hook): server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - if self.config['webinterface']['https']: + if self.core.config['webinterface']['https']: try: server_socket = ssl.wrap_socket(server_socket) diff --git a/module/plugins/hooks/DeathByCaptcha.py b/module/plugins/hooks/DeathByCaptcha.py index 073f01d57..1ece35bdb 100644 --- a/module/plugins/hooks/DeathByCaptcha.py +++ b/module/plugins/hooks/DeathByCaptcha.py @@ -194,7 +194,7 @@ class DeathByCaptcha(Hook): self._processCaptcha(task) - def captchaInvalid(self, task): + def captcha_invalid(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: try: res = self.api_response("captcha/%d/report" % task.data['ticket'], True) diff --git a/module/plugins/hooks/DeleteFinished.py b/module/plugins/hooks/DeleteFinished.py index 29bd7a4e1..38d2a7ed0 100644 --- a/module/plugins/hooks/DeleteFinished.py +++ b/module/plugins/hooks/DeleteFinished.py @@ -35,17 +35,17 @@ class DeleteFinished(Hook): self.logInfo(msg % (_('including') if deloffline else _('excluding'))) self.deleteFinished(mode) self.info['sleep'] = True - self.addEvent('packageFinished', self.wakeup) + self.addEvent('package_finished', self.wakeup) # def pluginConfigChanged(self, plugin, name, value): # if name == "interval" and value != self.interval: # self.interval = value * 3600 - # self.initPeriodical() + # self.init_periodical() def deactivate(self): - self.manager.removeEvent('packageFinished', self.wakeup) + self.manager.removeEvent('package_finished', self.wakeup) def activate(self): @@ -53,7 +53,7 @@ class DeleteFinished(Hook): # interval = self.getConfig('interval') # self.pluginConfigChanged(self.__name__, 'interval', interval) self.interval = max(self.MIN_CHECK_INTERVAL, self.getConfig('interval') * 60 * 60) - self.addEvent('packageFinished', self.wakeup) + self.addEvent('package_finished', self.wakeup) ## own methods ## @@ -64,7 +64,7 @@ class DeleteFinished(Hook): def wakeup(self, pypack): - self.manager.removeEvent('packageFinished', self.wakeup) + self.manager.removeEvent('package_finished', self.wakeup) self.info['sleep'] = False diff --git a/module/plugins/hooks/ExpertDecoders.py b/module/plugins/hooks/ExpertDecoders.py index 8a2a836aa..13289f8d1 100644 --- a/module/plugins/hooks/ExpertDecoders.py +++ b/module/plugins/hooks/ExpertDecoders.py @@ -91,7 +91,7 @@ class ExpertDecoders(Hook): self.logInfo(_("Your ExpertDecoders Account has not enough credits")) - def captchaInvalid(self, task): + def captcha_invalid(self, task): if "ticket" in task.data: try: diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 140dcb057..85df87a23 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -4,7 +4,7 @@ import os import subprocess from module.plugins.internal.Hook import Hook -from module.utils import fs_encode, save_join +from module.utils import fs_encode, save_join as fs_join class ExternalScripts(Hook): @@ -66,7 +66,7 @@ class ExternalScripts(Hook): return for filename in os.listdir(dir): - file = save_join(dir, filename) + file = fs_join(dir, filename) if not os.path.isfile(file): continue @@ -108,41 +108,41 @@ class ExternalScripts(Hook): self.callScript(script) - def beforeReconnecting(self, ip): + def before_reconnect(self, ip): for script in self.scripts['before_reconnect']: self.callScript(script, ip) self.info['oldip'] = ip - def afterReconnecting(self, ip): + def after_reconnect(self, ip): for script in self.scripts['after_reconnect']: self.callScript(script, ip, self.info['oldip']) #@TODO: Use built-in oldip in 0.4.10 - def downloadPreparing(self, pyfile): + def download_preparing(self, pyfile): for script in self.scripts['download_preparing']: self.callScript(script, pyfile.id, pyfile.name, None, pyfile.pluginname, pyfile.url) - def downloadFailed(self, pyfile): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + def download_failed(self, pyfile): + if self.core.config['general']['folder_per_package']: + download_folder = fs_join(self.core.config['general']['download_folder'], pyfile.package().folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.core.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, file, pyfile.pluginname, pyfile.url) - def downloadFinished(self, pyfile): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pyfile.package().folder) + def download_finished(self, pyfile): + if self.core.config['general']['folder_per_package']: + download_folder = fs_join(self.core.config['general']['download_folder'], pyfile.package().folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.core.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, file, pyfile.pluginname, pyfile.url) @@ -156,11 +156,11 @@ class ExternalScripts(Hook): self.callScript(script, pyfile.id, pyfile.name, archive.filename, archive.out, archive.files) - def packageFinished(self, pypack): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + def package_finished(self, pypack): + if self.core.config['general']['folder_per_package']: + download_folder = fs_join(self.core.config['general']['download_folder'], pypack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] for script in self.scripts['package_finished']: self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password) @@ -169,30 +169,30 @@ class ExternalScripts(Hook): def packageDeleted(self, pid): pack = self.core.api.getPackageInfo(pid) - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pack.folder) + if self.core.config['general']['folder_per_package']: + download_folder = fs_join(self.core.config['general']['download_folder'], pack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] for script in self.scripts['package_deleted']: self.callScript(script, pack.id, pack.name, download_folder, pack.password) def package_extract_failed(self, pypack): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + if self.core.config['general']['folder_per_package']: + download_folder = fs_join(self.core.config['general']['download_folder'], pypack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] for script in self.scripts['package_extract_failed']: self.callScript(script, pypack.id, pypack.name, download_folder, pypack.password) def package_extracted(self, pypack): - if self.config['general']['folder_per_package']: - download_folder = save_join(self.config['general']['download_folder'], pypack.folder) + if self.core.config['general']['folder_per_package']: + download_folder = fs_join(self.core.config['general']['download_folder'], pypack.folder) else: - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] for script in self.scripts['package_extracted']: self.callScript(script, pypack.id, pypack.name, download_folder) diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index dae04c811..2c0d68f3e 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -56,7 +56,7 @@ if os.name != "nt": from module.plugins.internal.Hook import Hook, Expose, threaded from module.plugins.internal.Extractor import ArchiveError, CRCError, PasswordError from module.plugins.internal.SimpleHoster import replace_patterns -from module.utils import fs_encode, save_join, uniqify +from module.utils import fs_encode, save_join as fs_join, uniqify class ArchiveQueue(object): @@ -220,7 +220,7 @@ class ExtractArchive(Hook): self.queue.remove(pid) - def packageFinished(self, pypack): + def package_finished(self, pypack): self.queue.add(pypack.id) if not self.getConfig('waitall') and not self.extracting: self.extractQueued() @@ -261,7 +261,7 @@ class ExtractArchive(Hook): # reload from txt file self.reloadPasswords() - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] # iterate packages -> extractors -> targets for pid in ids: @@ -274,17 +274,17 @@ class ExtractArchive(Hook): self.logInfo(_("Check package: %s") % pypack.name) # determine output folder - out = save_join(download_folder, pypack.folder, destination, "") #: force trailing slash + out = fs_join(download_folder, pypack.folder, destination, "") #: force trailing slash if subfolder: - out = save_join(out, pypack.folder) + out = fs_join(out, pypack.folder) if not os.path.exists(out): os.makedirs(out) matched = False success = True - files_ids = dict((pylink['name'],((save_join(download_folder, pypack.folder, pylink['name'])), pylink['id'], out)) for pylink \ + files_ids = dict((pylink['name'],((fs_join(download_folder, pypack.folder, pylink['name'])), pylink['id'], out)) for pylink \ in sorted(pypack.getChildren().itervalues(), key=lambda k: k['name'])).values() #: remove duplicates # check as long there are unseen files @@ -344,7 +344,7 @@ class ExtractArchive(Hook): self.setPermissions(new_files) for filename in new_files: - file = fs_encode(save_join(os.path.dirname(archive.filename), filename)) + file = fs_encode(fs_join(os.path.dirname(archive.filename), filename)) if not os.path.exists(file): self.logDebug("New file %s does not exists" % filename) continue @@ -554,16 +554,16 @@ class ExtractArchive(Hook): continue try: - if self.config['permission']['change_file']: + if self.core.config['permission']['change_file']: if os.path.isfile(f): - os.chmod(f, int(self.config['permission']['file'], 8)) + os.chmod(f, int(self.core.config['permission']['file'], 8)) elif os.path.isdir(f): - os.chmod(f, int(self.config['permission']['folder'], 8)) + os.chmod(f, int(self.core.config['permission']['folder'], 8)) - if self.config['permission']['change_dl'] and os.name != "nt": - uid = getpwnam(self.config['permission']['user'])[2] - gid = getgrnam(self.config['permission']['group'])[2] + if self.core.config['permission']['change_dl'] and os.name != "nt": + uid = getpwnam(self.core.config['permission']['user'])[2] + gid = getgrnam(self.core.config['permission']['group'])[2] os.chown(f, uid, gid) except Exception, e: diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py index ff5240e35..8c922f47a 100644 --- a/module/plugins/hooks/HotFolder.py +++ b/module/plugins/hooks/HotFolder.py @@ -8,7 +8,7 @@ import time from shutil import move from module.plugins.internal.Hook import Hook -from module.utils import fs_encode, save_join +from module.utils import fs_encode, save_join as fs_join class HotFolder(Hook): @@ -50,7 +50,7 @@ class HotFolder(Hook): name = "%s_%s.txt" % (file, time.strftime("%H-%M-%S_%d%b%Y")) - with open(save_join(folder, "finished", name), "wb") as f: + with open(fs_join(folder, "finished", name), "wb") as f: f.write(content) self.core.api.addPackage(f.name, [f.name], 1) diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index b3b3d9b89..e24691bde 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -54,7 +54,7 @@ class IRCInterface(Thread, Hook): self.start() - def packageFinished(self, pypack): + def package_finished(self, pypack): try: if self.getConfig('info_pack'): self.response(_("Package finished: %s") % pypack.name) @@ -62,7 +62,7 @@ class IRCInterface(Thread, Hook): pass - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): try: if self.getConfig('info_file'): self.response( diff --git a/module/plugins/hooks/ImageTyperz.py b/module/plugins/hooks/ImageTyperz.py index 06c371f1d..7fb642250 100644 --- a/module/plugins/hooks/ImageTyperz.py +++ b/module/plugins/hooks/ImageTyperz.py @@ -132,7 +132,7 @@ class ImageTyperz(Hook): self.logInfo(_("Your %s account has not enough credits") % self.__name__) - def captchaInvalid(self, task): + def captcha_invalid(self, task): if task.data['service'] == self.__name__ and "ticket" in task.data: res = getURL(self.RESPOND_URL, post={'action': "SETBADIMAGE", diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index db7432eac..0b0f7e475 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -7,7 +7,7 @@ import re import traceback from module.plugins.internal.Hook import Hook, threaded -from module.utils import save_join +from module.utils import save_join as fs_join class MergeFiles(Hook): @@ -32,7 +32,7 @@ class MergeFiles(Hook): @threaded - def packageFinished(self, pack): + def package_finished(self, pack): files = {} fid_dict = {} for fid, data in pack.getChildren().iteritems(): @@ -43,15 +43,15 @@ class MergeFiles(Hook): files[data['name'][:-4]].sort() fid_dict[data['name']] = fid - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] - if self.config['general']['folder_per_package']: - download_folder = save_join(download_folder, pack.folder) + if self.core.config['general']['folder_per_package']: + download_folder = fs_join(download_folder, pack.folder) for name, file_list in files.iteritems(): self.logInfo(_("Starting merging of"), name) - with open(save_join(download_folder, name), "wb") as final_file: + with open(fs_join(download_folder, name), "wb") as final_file: for splitted_file in file_list: self.logDebug("Merging part", splitted_file) @@ -60,7 +60,7 @@ class MergeFiles(Hook): pyfile.setStatus("processing") try: - with open(save_join(download_folder, splitted_file), "rb") as s_file: + with open(fs_join(download_folder, splitted_file), "rb") as s_file: size_written = 0 s_file_size = int(os.path.getsize(os.path.join(download_folder, splitted_file))) while True: diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py index 63c1fee05..fe7f39a12 100644 --- a/module/plugins/hooks/MultiHome.py +++ b/module/plugins/hooks/MultiHome.py @@ -28,7 +28,7 @@ class MultiHome(Hook): self.parseInterfaces(self.getConfig('interfaces').split(";")) if not self.interfaces: - self.parseInterfaces([self.config['download']['interface']]) + self.parseInterfaces([self.core.config['download']['interface']]) self.setConfig("interfaces", self.toConfig()) diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py index eb49a5418..153b4716c 100644 --- a/module/plugins/hooks/RestartFailed.py +++ b/module/plugins/hooks/RestartFailed.py @@ -24,7 +24,7 @@ class RestartFailed(Hook): # if self.MIN_CHECK_INTERVAL <= interval != self.interval: # self.core.scheduler.removeJob(self.cb) # self.interval = interval - # self.initPeriodical() + # self.init_periodical() # else: # self.logDebug("Invalid interval value, kept current") diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index da9f24883..0457f9b55 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -59,7 +59,7 @@ 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: @@ -85,7 +85,7 @@ class SkipRev(Hook): pyfile.plugin.setup = MethodType(self._setup, pyfile.plugin) - def downloadFailed(self, pyfile): + 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"): diff --git a/module/plugins/hooks/UnSkipOnFail.py b/module/plugins/hooks/UnSkipOnFail.py index b9ae93fee..234e1052b 100644 --- a/module/plugins/hooks/UnSkipOnFail.py +++ b/module/plugins/hooks/UnSkipOnFail.py @@ -23,7 +23,7 @@ class UnSkipOnFail(Hook): self.info = {} #@TODO: Remove in 0.4.10 - def downloadFailed(self, pyfile): + def download_failed(self, pyfile): #: Check if pyfile is still "failed", # maybe might has been restarted in meantime if pyfile.status != 8: diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 958be4e12..f555e4ff3 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -11,7 +11,7 @@ from operator import itemgetter from module.network.RequestFactory import getURL from module.plugins.internal.Hook import Expose, Hook, threaded -from module.utils import save_join +from module.utils import save_join as fs_join # Case-sensitive os.path.exists @@ -57,7 +57,7 @@ class UpdateManager(Hook): if self.do_restart is False: self.core.api.unpauseServer() - self.initPeriodical() + self.init_periodical() def setup(self): @@ -257,7 +257,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)) @@ -303,7 +303,7 @@ 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": diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 0637936f9..0504ec9d0 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -27,7 +27,7 @@ class UserAgentSwitcher(Hook): self.info = {} #@TODO: Remove in 0.4.10 - def downloadPreparing(self, pyfile): + def download_preparing(self, pyfile): connecttimeout = self.getConfig('connecttimeout') maxredirs = self.getConfig('maxredirs') useragent = self.getConfig('useragent').encode("utf8", "replace") #@TODO: Remove `encode` in 0.4.10 diff --git a/module/plugins/hooks/WindowsPhoneNotify.py b/module/plugins/hooks/WindowsPhoneNotify.py index 86a5f2308..713499322 100644 --- a/module/plugins/hooks/WindowsPhoneNotify.py +++ b/module/plugins/hooks/WindowsPhoneNotify.py @@ -68,7 +68,7 @@ class WindowsPhoneNotify(Hook): self.notify(_("Captcha"), _("New request waiting user input")) - def packageFinished(self, pypack): + def package_finished(self, pypack): if self.getConfig('notifypackage'): self.notify(_("Package finished"), pypack.name) diff --git a/module/plugins/hooks/XFileSharingPro.py b/module/plugins/hooks/XFileSharingPro.py index f13a78d4a..8ef5941d1 100644 --- a/module/plugins/hooks/XFileSharingPro.py +++ b/module/plugins/hooks/XFileSharingPro.py @@ -126,7 +126,7 @@ class XFileSharingPro(Hook): return False - # def downloadFailed(self, pyfile): + # def download_failed(self, pyfile): # if pyfile.pluginname == "BasePlugin" \ # and pyfile.hasStatus("failed") \ # and not self.getConfig('use_hoster_list') \ diff --git a/module/plugins/hooks/XMPPInterface.py b/module/plugins/hooks/XMPPInterface.py index e93da98bf..053817bef 100644 --- a/module/plugins/hooks/XMPPInterface.py +++ b/module/plugins/hooks/XMPPInterface.py @@ -65,7 +65,7 @@ class XMPPInterface(IRCInterface, JabberClient): self.start() - def packageFinished(self, pypack): + def package_finished(self, pypack): try: if self.getConfig('info_pack'): self.announce(_("Package finished: %s") % pypack.name) @@ -73,7 +73,7 @@ class XMPPInterface(IRCInterface, JabberClient): pass - def downloadFinished(self, pyfile): + def download_finished(self, pyfile): try: if self.getConfig('info_file'): self.announce( @@ -200,11 +200,11 @@ class XMPPInterface(IRCInterface, JabberClient): stream.send(m) - def beforeReconnecting(self, ip): + def before_reconnect(self, ip): self.disconnect() - def afterReconnecting(self, ip): + def after_reconnect(self, ip): self.connect() diff --git a/module/plugins/hoster/Xdcc.py b/module/plugins/hoster/Xdcc.py index 8bbeb83fb..b6f7466b5 100644 --- a/module/plugins/hoster/Xdcc.py +++ b/module/plugins/hoster/Xdcc.py @@ -9,7 +9,7 @@ import time from select import select from module.plugins.internal.Hoster import Hoster -from module.utils import save_join +from module.utils import save_join as fs_join class Xdcc(Hoster): @@ -189,8 +189,8 @@ class Xdcc(Hoster): self.pyfile.name = packname - download_folder = self.config['general']['download_folder'] - filename = save_join(download_folder, packname) + download_folder = self.core.config['general']['download_folder'] + filename = fs_join(download_folder, packname) self.logInfo(_("Downloading %s from %s:%d") % (packname, ip, port)) diff --git a/module/plugins/internal/Account.py b/module/plugins/internal/Account.py index 27a040e24..aa472f297 100644 --- a/module/plugins/internal/Account.py +++ b/module/plugins/internal/Account.py @@ -5,7 +5,7 @@ import threading import time import traceback -from module.plugins.internal.Plugin import Base +from module.plugins.internal.Plugin import Plugin from module.utils import compare_time, lock, parseFileSize @@ -13,7 +13,7 @@ class WrongPassword(Exception): pass -class Account(Base): +class Account(Plugin): __name__ = "Account" __type__ = "account" __version__ = "0.03" diff --git a/module/plugins/internal/Captcha.py b/module/plugins/internal/Captcha.py index e5a44d750..8d040515c 100644 --- a/module/plugins/internal/Captcha.py +++ b/module/plugins/internal/Captcha.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -from module.plugins.internal.Plugin import Base +from module.plugins.internal.Plugin import Plugin #@TODO: Extend (new) Plugin class; remove all `html` args -class Captcha(Base): +class Captcha(Plugin): __name__ = "Captcha" __type__ = "captcha" __version__ = "0.30" diff --git a/module/plugins/internal/Container.py b/module/plugins/internal/Container.py index 3b3eb88aa..097b04ac7 100644 --- a/module/plugins/internal/Container.py +++ b/module/plugins/internal/Container.py @@ -6,7 +6,7 @@ import os import re from module.plugins.internal.Crypter import Crypter -from module.utils import save_join +from module.utils import save_join as fs_join class Container(Crypter): @@ -43,7 +43,7 @@ class Container(Crypter): if self.pyfile.url.startswith("http"): self.pyfile.name = re.findall("([^\/=]+)", self.pyfile.url)[-1] content = self.load(self.pyfile.url) - self.pyfile.url = save_join(self.core.config.get("general", "download_folder"), self.pyfile.name) + self.pyfile.url = fs_join(self.core.config.get("general", "download_folder"), self.pyfile.name) try: with open(self.pyfile.url, "wb") as f: f.write(content) @@ -53,8 +53,8 @@ class Container(Crypter): else: self.pyfile.name = os.path.basename(self.pyfile.url) if not os.path.exists(self.pyfile.url): - if os.path.exists(save_join(pypath, self.pyfile.url)): - self.pyfile.url = save_join(pypath, self.pyfile.url) + if os.path.exists(fs_join(pypath, self.pyfile.url)): + self.pyfile.url = fs_join(pypath, self.pyfile.url) else: self.fail(_("File not exists")) diff --git a/module/plugins/internal/Crypter.py b/module/plugins/internal/Crypter.py index 5fb9bc5c2..39b09129f 100644 --- a/module/plugins/internal/Crypter.py +++ b/module/plugins/internal/Crypter.py @@ -3,7 +3,7 @@ import urlparse from module.plugins.internal.Plugin import Plugin -from module.utils import decode, save_path +from module.utils import decode, save_path as safe_filename class Crypter(Plugin): @@ -98,7 +98,7 @@ class Crypter(Plugin): if not folder: folder = urlparse.urlparse(name).path.split("/")[-1] - setFolder(save_path(folder)) + setFolder(safe_filename(folder)) self.logDebug("Set package %(name)s folder to: %(folder)s" % {"name": name, "folder": folder}) elif folder_per_package: diff --git a/module/plugins/internal/Hook.py b/module/plugins/internal/Hook.py index 7d785ded0..8d620e794 100644 --- a/module/plugins/internal/Hook.py +++ b/module/plugins/internal/Hook.py @@ -2,7 +2,7 @@ import traceback -from module.plugins.internal.Plugin import Base +from module.plugins.internal.Plugin import Plugin class Expose(object): @@ -21,7 +21,7 @@ def threaded(fn): return run -class Hook(Base): +class Hook(Plugin): __name__ = "Hook" __type__ = "hook" __version__ = "0.08" diff --git a/module/plugins/internal/OCR.py b/module/plugins/internal/OCR.py index 2349d32af..1782e17f0 100644 --- a/module/plugins/internal/OCR.py +++ b/module/plugins/internal/OCR.py @@ -13,7 +13,7 @@ import os import subprocess #import tempfile -from module.utils import save_join +from module.utils import save_join as fs_join class OCR(object): @@ -59,11 +59,11 @@ class OCR(object): def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True): #tmpTif = tempfile.NamedTemporaryFile(suffix=".tif") try: - tmpTif = open(save_join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") + tmpTif = open(fs_join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") tmpTif.close() #tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt") - tmpTxt = open(save_join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") + tmpTxt = open(fs_join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") tmpTxt.close() except IOError, e: @@ -82,7 +82,7 @@ class OCR(object): if subset and (digits or lowercase or uppercase): #tmpSub = tempfile.NamedTemporaryFile(suffix=".subset") - with open(save_join("tmp", "tmpSub_%s.subset" % self.__name__), "wb") as tmpSub: + with open(fs_join("tmp", "tmpSub_%s.subset" % self.__name__), "wb") as tmpSub: tmpSub.write("tessedit_char_whitelist ") if digits: diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 16aa9cc45..da597ef42 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -32,7 +32,7 @@ if os.name != "nt": from itertools import islice from module.plugins.Plugin import Abort, Fail, Reconnect, Retry, SkipDownload as Skip #@TODO: Remove in 0.4.10 -from module.utils import save_join, save_path, fs_encode, fs_decode +from module.utils import save_join as fs_join, save_path as safe_filename, fs_encode, fs_decode def chunks(iterable, size): it = iter(iterable) @@ -50,10 +50,6 @@ class Base(object): def __init__(self, core): #: Core instance self.core = core - #: logging instance - self.log = core.log - #: core config - self.config = core.config #: Log functions @@ -183,7 +179,7 @@ class Plugin(Base): def __init__(self, pyfile): - Base.__init__(self, pyfile.m.core) + super(Plugin, self).__init__(pyfile.m.core) self.wantReconnect = False #: enables simultaneous processing of multiple downloads @@ -239,8 +235,8 @@ class Plugin(Base): def getChunkCount(self): if self.chunkLimit <= 0: - return self.config["download"]["chunks"] - return min(self.config["download"]["chunks"], self.chunkLimit) + return self.core.config["download"]["chunks"] + return min(self.core.config["download"]["chunks"], self.chunkLimit) def __call__(self): return self.__name__ @@ -416,7 +412,7 @@ class Plugin(Base): self.fail(_("No captcha result obtained in appropiate time by any of the plugins.")) result = task.result - self.log.debug("Received captcha result: %s" % str(result)) + self.core.log.debug("Received captcha result: %s" % str(result)) if not self.core.debug: try: @@ -504,25 +500,25 @@ class Plugin(Base): self.pyfile.setStatus("downloading") - download_folder = self.config['general']['download_folder'] + download_folder = self.core.config['general']['download_folder'] - location = save_join(download_folder, self.pyfile.package().folder) + location = fs_join(download_folder, self.pyfile.package().folder) if not exists(location): makedirs(location, int(self.core.config["permission"]["folder"], 8)) if self.core.config["permission"]["change_dl"] and os.name != "nt": try: - uid = getpwnam(self.config["permission"]["user"])[2] - gid = getgrnam(self.config["permission"]["group"])[2] + uid = getpwnam(self.core.config["permission"]["user"])[2] + gid = getgrnam(self.core.config["permission"]["group"])[2] chown(location, uid, gid) except Exception, e: - self.log.warning(_("Setting User and Group failed: %s") % str(e)) + self.core.log.warning(_("Setting User and Group failed: %s") % str(e)) # convert back to unicode location = fs_decode(location) - name = save_path(self.pyfile.name) + name = safe_filename(self.pyfile.name) filename = join(location, name) @@ -536,7 +532,7 @@ class Plugin(Base): self.pyfile.size = self.req.size if disposition and newname and newname != name: #triple check, just to be sure - self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname}) + self.core.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname}) self.pyfile.name = newname filename = join(location, newname) @@ -547,12 +543,12 @@ class Plugin(Base): if self.core.config["permission"]["change_dl"] and os.name != "nt": try: - uid = getpwnam(self.config["permission"]["user"])[2] - gid = getgrnam(self.config["permission"]["group"])[2] + uid = getpwnam(self.core.config["permission"]["user"])[2] + gid = getgrnam(self.core.config["permission"]["group"])[2] chown(fs_filename, uid, gid) except Exception, e: - self.log.warning(_("Setting User and Group failed: %s") % str(e)) + self.core.log.warning(_("Setting User and Group failed: %s") % str(e)) self.lastDownload = filename return self.lastDownload @@ -575,12 +571,12 @@ class Plugin(Base): if api_size and api_size <= size: return None elif size > max_size and not read_size: return None - self.log.debug("Download Check triggered") + self.core.log.debug("Download Check triggered") f = open(lastDownload, "rb") content = f.read(read_size if read_size else -1) f.close() #produces encoding errors, better log to other file in the future? - #self.log.debug("Content: %s" % content) + #self.core.log.debug("Content: %s" % content) for name, rule in rules.iteritems(): if type(rule) in (str, unicode): if rule in content: @@ -620,8 +616,8 @@ class Plugin(Base): 5, 7) and starting: #a download is waiting/starting and was appenrently started before self.skip(pyfile.pluginname) - download_folder = self.config['general']['download_folder'] - location = save_join(download_folder, pack.folder, self.pyfile.name) + download_folder = self.core.config['general']['download_folder'] + location = fs_join(download_folder, pack.folder, self.pyfile.name) if starting and self.core.config['download']['skip_existing'] and exists(location): size = os.stat(location).st_size @@ -633,7 +629,7 @@ class Plugin(Base): if exists(location): self.skip(pyfile[0]) - self.log.debug("File %s not skipped, because it does not exists" % self.pyfile.name) + self.core.log.debug("File %s not skipped, because it does not exists" % self.pyfile.name) def clean(self): """ clean everything and remove references """ diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py index 624f6c939..cad4cfa1c 100644 --- a/module/plugins/internal/SevenZip.py +++ b/module/plugins/internal/SevenZip.py @@ -5,7 +5,7 @@ import re import subprocess from module.plugins.internal.UnRar import ArchiveError, CRCError, PasswordError, UnRar, renice -from module.utils import fs_encode, save_join +from module.utils import fs_encode, save_join as fs_join class SevenZip(UnRar): @@ -126,7 +126,7 @@ class SevenZip(UnRar): result = set() for groups in self.re_filelist.findall(out): f = groups[-1].strip() - result.add(save_join(self.out, f)) + result.add(fs_join(self.out, f)) return list(result) diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 5b9f2e1c3..85e939b6a 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -8,7 +8,7 @@ from glob import glob from string import digits from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -from module.utils import fs_decode, fs_encode, save_join +from module.utils import fs_decode, fs_encode, save_join as fs_join def renice(pid, value): @@ -175,7 +175,7 @@ class UnRar(Extractor): files = [self.filename] # eventually Multipart Files - files.extend(save_join(dir, os.path.basename(file)) for file in filter(self.isMultipart, os.listdir(dir)) + files.extend(fs_join(dir, os.path.basename(file)) for file in filter(self.isMultipart, os.listdir(dir)) if re.sub(self.re_multipart,".rar",name) == re.sub(self.re_multipart,".rar",file)) return files @@ -197,13 +197,13 @@ class UnRar(Extractor): if not self.fullpath and self.VERSION.startswith('5'): # NOTE: Unrar 5 always list full path for f in fs_decode(out).splitlines(): - f = save_join(self.out, os.path.basename(f.strip())) + f = fs_join(self.out, os.path.basename(f.strip())) if os.path.isfile(f): - result.add(save_join(self.out, os.path.basename(f))) + result.add(fs_join(self.out, os.path.basename(f))) else: for f in fs_decode(out).splitlines(): f = f.strip() - result.add(save_join(self.out, f)) + result.add(fs_join(self.out, f)) return list(result) |