From c6a54414f340efe1d649c72786ec25c505e94172 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 8 Dec 2014 19:03:23 +0100 Subject: [RestartSlow] New fixed version re-added --- module/plugins/hooks/RestartSlow.py | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 module/plugins/hooks/RestartSlow.py (limited to 'module/plugins/hooks') diff --git a/module/plugins/hooks/RestartSlow.py b/module/plugins/hooks/RestartSlow.py new file mode 100644 index 000000000..587799235 --- /dev/null +++ b/module/plugins/hooks/RestartSlow.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- + +import pycurl + +from module.plugins.Hook import Hook + + +class RestartSlow(Hook): + __name__ = "RestartSlow" + __type__ = "hook" + __version__ = "0.02" + + __config__ = [("free_limit" , "int" , "Transfer speed threshold in kilobytes" , 100 ), + ("free_time" , "int" , "Sample interval in minutes" , 5 ), + ("premium_limit", "int" , "Transfer speed threshold for premium download in kilobytes", 300 ), + ("premium_time" , "int" , "Sample interval for premium download in minutes" , 2 ), + ("safe_mode" , "bool", "Don't restart if download is not resumable" , True)] + + __description__ = """Restart slow downloads""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + event_list = ["downloadStarts"] + + + def setup(self): + self.info = {'chunk': {}} + + + def initPeriodical(self): + pass + + + def periodical(self): + if not self.pyfile.req.dl: + return + + if self.getConfig("safe_mode") and not self.pyfile.plugin.resumeDownload: + time = 30 + limit = 5 + else: + type = "premium" if self.pyfile.plugin.premium else "free" + time = max(30, self.getConfig("%s_time" % type) * 60) + limit = max(5, self.getConfig("%s_limit" % type) * 1024) + + chunks = [chunk for chunk in self.pyfile.req.dl.chunks \ + if chunk.id not in self.info['chunk'] or self.info['chunk'][chunk.id] not is (time, limit)] + + for chunk in chunks: + chunk.c.setopt(pycurl.LOW_SPEED_TIME , time) + chunk.c.setopt(pycurl.LOW_SPEED_LIMIT, limit) + + self.info['chunk'][chunk.id] = (time, limit) + + + def downloadStarts(self, pyfile, url, filename): + if self.cb or (self.getConfig("safe_mode") and not pyfile.plugin.resumeDownload): + return + + super(RestartSlow, self).initPeriodical() -- cgit v1.2.3 From 78e26bfd3b940034748256e4d0237e0ae5d33d60 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 8 Dec 2014 23:19:08 +0100 Subject: [SkipRev] Update (2) --- module/plugins/hooks/SkipRev.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'module/plugins/hooks') diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index 76a48a255..f3edcc9dc 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- -import re - from urllib import unquote -from urlparse import urljoin, urlparse +from urlparse import urlparse from module.plugins.Hook import Hook from module.plugins.Plugin import SkipDownload @@ -12,11 +10,9 @@ from module.plugins.Plugin import SkipDownload class SkipRev(Hook): __name__ = "SkipRev" __type__ = "hook" - __version__ = "0.13" + __version__ = "0.14" - __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)] + __config__ = [("tokeep", "int", "Number of rev files to keep for package (-1 to auto)", -1)] __description__ = """Skip files ending with extension rev""" __license__ = "GPLv3" @@ -55,11 +51,11 @@ class SkipRev(Hook): tokeep = self.getConfig("tokeep") - if tokeep > 0: + if tokeep: saved = [True for link in pyfile.package().getChildren() \ if link.name.endswith(".rev") and (link.hasStatus("finished") or link.hasStatus("downloading"))].count(True) - if saved < tokeep: + if not saved or saved < tokeep: #: keep one rev at least in auto mode return pyfile.setCustomStatus("SkipRev", "skipped") @@ -67,15 +63,15 @@ class SkipRev(Hook): def downloadFailed(self, pyfile): - if self.getConfig("auto") is False: - - if self.getConfig("unskip") is False: - return + tokeep = self.getConfig("tokeep") - if not pyfile.name.endswith(".rev"): - return + if not tokeep: + return for link in pyfile.package().getChildren(): if link.hasStatus("skipped") and link.name.endswith(".rev"): - link.setCustomStatus("unskipped", "queued") + if tokeep > -1 or pyfile.name.endswith(".rev"): + link.setStatus("queued") + else: + link.setCustomStatus("unskipped", "queued") return -- cgit v1.2.3 From e4c9e4ffc9e3f6bd6b16ce83796dc3d275d544f7 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 9 Dec 2014 01:13:05 +0100 Subject: Don't start unused periodical in some addons --- module/plugins/hooks/BypassCaptcha.py | 7 ++++++- module/plugins/hooks/Captcha9kw.py | 7 ++++++- module/plugins/hooks/CaptchaBrotherhood.py | 7 ++++++- module/plugins/hooks/Checksum.py | 7 ++++++- module/plugins/hooks/ClickAndLoad.py | 7 ++++++- module/plugins/hooks/DeathByCaptcha.py | 7 ++++++- module/plugins/hooks/DownloadScheduler.py | 7 ++++++- module/plugins/hooks/ExpertDecoders.py | 7 ++++++- module/plugins/hooks/ExternalScripts.py | 7 ++++++- module/plugins/hooks/ExtractArchive.py | 7 ++++++- module/plugins/hooks/IRCInterface.py | 7 ++++++- module/plugins/hooks/ImageTyperz.py | 7 ++++++- module/plugins/hooks/LinkdecrypterCom.py | 7 ++++++- module/plugins/hooks/MergeFiles.py | 7 ++++++- module/plugins/hooks/MultiHome.py | 7 ++++++- module/plugins/hooks/SkipRev.py | 5 +++++ module/plugins/hooks/UnSkipOnFail.py | 7 ++++++- module/plugins/hooks/WindowsPhoneToastNotify.py | 7 ++++++- module/plugins/hooks/XFileSharingPro.py | 7 ++++++- 19 files changed, 113 insertions(+), 18 deletions(-) (limited to 'module/plugins/hooks') diff --git a/module/plugins/hooks/BypassCaptcha.py b/module/plugins/hooks/BypassCaptcha.py index 7e1ea6424..a32de7f42 100644 --- a/module/plugins/hooks/BypassCaptcha.py +++ b/module/plugins/hooks/BypassCaptcha.py @@ -29,7 +29,7 @@ class BypassCaptchaException(Exception): class BypassCaptcha(Hook): __name__ = "BypassCaptcha" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.05" __config__ = [("force", "bool", "Force BC even if client is connected", False), ("passkey", "password", "Passkey", "")] @@ -48,6 +48,11 @@ class BypassCaptcha(Hook): GETCREDITS_URL = "http://bypasscaptcha.com/ex_left.php" + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.info = {} #@TODO: Remove in 0.4.10 diff --git a/module/plugins/hooks/Captcha9kw.py b/module/plugins/hooks/Captcha9kw.py index ead8aec9a..33ad00c49 100755 --- a/module/plugins/hooks/Captcha9kw.py +++ b/module/plugins/hooks/Captcha9kw.py @@ -17,7 +17,7 @@ from module.plugins.Hook import Hook class Captcha9kw(Hook): __name__ = "Captcha9kw" __type__ = "hook" - __version__ = "0.25" + __version__ = "0.26" __config__ = [("activated" , "bool" , "Activated" , True ), ("ssl" , "bool" , "Use HTTPS" , True ), @@ -41,6 +41,11 @@ class Captcha9kw(Hook): API_URL = "http://www.9kw.eu/index.cgi" + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.info = {} #@TODO: Remove in 0.4.10 if self.getConfig("ssl"): diff --git a/module/plugins/hooks/CaptchaBrotherhood.py b/module/plugins/hooks/CaptchaBrotherhood.py index 2ebeb1734..b6e38d8bb 100644 --- a/module/plugins/hooks/CaptchaBrotherhood.py +++ b/module/plugins/hooks/CaptchaBrotherhood.py @@ -39,7 +39,7 @@ class CaptchaBrotherhoodException(Exception): class CaptchaBrotherhood(Hook): __name__ = "CaptchaBrotherhood" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" __config__ = [("username", "str", "Username", ""), ("force", "bool", "Force CT even if client is connected", False), @@ -54,6 +54,11 @@ class CaptchaBrotherhood(Hook): API_URL = "http://www.captchabrotherhood.com/" + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.info = {} #@TODO: Remove in 0.4.10 diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index eeda2d849..18036e020 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -40,7 +40,7 @@ def computeChecksum(local_file, algorithm): class Checksum(Hook): __name__ = "Checksum" __type__ = "hook" - __version__ = "0.14" + __version__ = "0.15" __config__ = [("check_checksum", "bool", "Check checksum? (If False only size will be verified)", True), ("check_action", "fail;retry;nothing", "What to do if check fails?", "retry"), @@ -62,6 +62,11 @@ class Checksum(Hook): 'default': r'^(?P[0-9A-Fa-f]+)\s+\*?(?P.+)$'} + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def coreReady(self): if not self.getConfig("check_checksum"): self.logInfo(_("Checksum validation is disabled in plugin configuration")) diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py index c9c0f60c0..27d99c71c 100644 --- a/module/plugins/hooks/ClickAndLoad.py +++ b/module/plugins/hooks/ClickAndLoad.py @@ -52,7 +52,7 @@ def forward(source, destination): class ClickAndLoad(Hook): __name__ = "ClickAndLoad" __type__ = "hook" - __version__ = "0.22" + __version__ = "0.23" __config__ = [("activated", "bool", "Activated", True), ("extern", "bool", "Allow external link adding", False)] @@ -63,6 +63,11 @@ class ClickAndLoad(Hook): ("mkaay", "mkaay@mkaay.de")] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def coreReady(self): self.port = int(self.config['webinterface']['port']) if self.config['webinterface']['activated']: diff --git a/module/plugins/hooks/DeathByCaptcha.py b/module/plugins/hooks/DeathByCaptcha.py index df09769ce..f03ac4567 100644 --- a/module/plugins/hooks/DeathByCaptcha.py +++ b/module/plugins/hooks/DeathByCaptcha.py @@ -52,7 +52,7 @@ class DeathByCaptchaException(Exception): class DeathByCaptcha(Hook): __name__ = "DeathByCaptcha" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" __config__ = [("username", "str", "Username", ""), ("passkey", "password", "Password", ""), @@ -67,6 +67,11 @@ class DeathByCaptcha(Hook): API_URL = "http://api.dbcapi.me/api/" + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.info = {} #@TODO: Remove in 0.4.10 diff --git a/module/plugins/hooks/DownloadScheduler.py b/module/plugins/hooks/DownloadScheduler.py index 14884426f..4996e212d 100644 --- a/module/plugins/hooks/DownloadScheduler.py +++ b/module/plugins/hooks/DownloadScheduler.py @@ -10,7 +10,7 @@ from module.plugins.Hook import Hook class DownloadScheduler(Hook): __name__ = "DownloadScheduler" __type__ = "hook" - __version__ = "0.21" + __version__ = "0.22" __config__ = [("timetable", "str", "List time periods as hh:mm full or number(kB/s)", "0:00 full, 7:00 250, 10:00 0, 17:00 150"), @@ -22,6 +22,11 @@ class DownloadScheduler(Hook): ("stickell", "l.stickell@yahoo.it")] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.cb = None # callback to scheduler job; will be by removed hookmanager when hook unloaded diff --git a/module/plugins/hooks/ExpertDecoders.py b/module/plugins/hooks/ExpertDecoders.py index 1b9459eb6..1784a270c 100644 --- a/module/plugins/hooks/ExpertDecoders.py +++ b/module/plugins/hooks/ExpertDecoders.py @@ -15,7 +15,7 @@ from module.plugins.Hook import Hook class ExpertDecoders(Hook): __name__ = "ExpertDecoders" __type__ = "hook" - __version__ = "0.01" + __version__ = "0.02" __config__ = [("force", "bool", "Force CT even if client is connected", False), ("passkey", "password", "Access key", "")] @@ -29,6 +29,11 @@ class ExpertDecoders(Hook): API_URL = "http://www.fasttypers.org/imagepost.ashx" + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.info = {} #@TODO: Remove in 0.4.10 diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py index 5db2037fa..a35e47c03 100644 --- a/module/plugins/hooks/ExternalScripts.py +++ b/module/plugins/hooks/ExternalScripts.py @@ -13,7 +13,7 @@ from module.utils import save_join class ExternalScripts(Hook): __name__ = "ExternalScripts" __type__ = "hook" - __version__ = "0.24" + __version__ = "0.25" __config__ = [("activated", "bool", "Activated", True)] @@ -29,6 +29,11 @@ class ExternalScripts(Hook): "allDownloadsFinished", "allDownloadsProcessed"] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.scripts = {} diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 07db13aa1..fc77dbdf6 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -59,7 +59,7 @@ from module.utils import save_join, fs_encode class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "0.18" + __version__ = "0.19" __config__ = [("activated", "bool", "Activated", True), ("fullpath", "bool", "Extract full path", True), @@ -83,6 +83,11 @@ class ExtractArchive(Hook): event_list = ["allDownloadsProcessed"] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.plugins = [] self.passwords = [] diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index 98edc2f7f..efd4e411d 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -20,7 +20,7 @@ from module.utils import formatSize class IRCInterface(Thread, Hook): __name__ = "IRCInterface" __type__ = "hook" - __version__ = "0.12" + __version__ = "0.13" __config__ = [("host", "str", "IRC-Server Address", "Enter your server here!"), ("port", "int", "IRC-Server Port", 6667), @@ -44,6 +44,11 @@ class IRCInterface(Thread, Hook): self.setDaemon(True) + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def coreReady(self): self.abort = False self.more = [] diff --git a/module/plugins/hooks/ImageTyperz.py b/module/plugins/hooks/ImageTyperz.py index b00c5118f..f89d64c37 100644 --- a/module/plugins/hooks/ImageTyperz.py +++ b/module/plugins/hooks/ImageTyperz.py @@ -33,7 +33,7 @@ class ImageTyperzException(Exception): class ImageTyperz(Hook): __name__ = "ImageTyperz" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.05" __config__ = [("username", "str", "Username", ""), ("passkey", "password", "Password", ""), @@ -50,6 +50,11 @@ class ImageTyperz(Hook): GETCREDITS_URL = "http://captchatypers.com/Forms/RequestBalance.ashx" + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.info = {} #@TODO: Remove in 0.4.10 diff --git a/module/plugins/hooks/LinkdecrypterCom.py b/module/plugins/hooks/LinkdecrypterCom.py index 0c5f6e754..b0ce335d0 100644 --- a/module/plugins/hooks/LinkdecrypterCom.py +++ b/module/plugins/hooks/LinkdecrypterCom.py @@ -10,13 +10,18 @@ from module.utils import remove_chars class LinkdecrypterCom(Hook): __name__ = "LinkdecrypterCom" __type__ = "hook" - __version__ = "0.20" + __version__ = "0.21" __description__ = """Linkdecrypter.com hook plugin""" __license__ = "GPLv3" __authors__ = [("zoidberg", "zoidberg@mujmail.cz")] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def coreReady(self): try: self.loadPatterns() diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index e6f8bb26f..767209d21 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -12,7 +12,7 @@ from module.utils import save_join, fs_encode class MergeFiles(Hook): __name__ = "MergeFiles" __type__ = "hook" - __version__ = "0.12" + __version__ = "0.13" __config__ = [("activated", "bool", "Activated", True)] @@ -24,6 +24,11 @@ class MergeFiles(Hook): BUFFER_SIZE = 4096 + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): # nothing to do pass diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py index 228e6027d..105a42abd 100644 --- a/module/plugins/hooks/MultiHome.py +++ b/module/plugins/hooks/MultiHome.py @@ -8,7 +8,7 @@ from module.plugins.Hook import Hook class MultiHome(Hook): __name__ = "MultiHome" __type__ = "hook" - __version__ = "0.11" + __version__ = "0.12" __config__ = [("interfaces", "str", "Interfaces", "None")] @@ -17,6 +17,11 @@ class MultiHome(Hook): __authors__ = [("mkaay", "mkaay@mkaay.de")] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.register = {} self.interfaces = [] diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py index f3edcc9dc..609bb4197 100644 --- a/module/plugins/hooks/SkipRev.py +++ b/module/plugins/hooks/SkipRev.py @@ -19,6 +19,11 @@ class SkipRev(Hook): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def _setup(self): super(self.pyfile.plugin, self).setup() if self.pyfile.hasStatus("skipped"): diff --git a/module/plugins/hooks/UnSkipOnFail.py b/module/plugins/hooks/UnSkipOnFail.py index f97d12431..d3baccfc2 100644 --- a/module/plugins/hooks/UnSkipOnFail.py +++ b/module/plugins/hooks/UnSkipOnFail.py @@ -10,7 +10,7 @@ from module.utils import fs_encode class UnSkipOnFail(Hook): __name__ = "UnSkipOnFail" __type__ = "hook" - __version__ = "0.01" + __version__ = "0.02" __config__ = [("activated", "bool", "Activated", True)] @@ -19,6 +19,11 @@ class UnSkipOnFail(Hook): __authors__ = [("hagg", None)] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def downloadFailed(self, pyfile): pyfile_name = basename(pyfile.name) pid = pyfile.package().id diff --git a/module/plugins/hooks/WindowsPhoneToastNotify.py b/module/plugins/hooks/WindowsPhoneToastNotify.py index 053ea47d0..ed305778c 100644 --- a/module/plugins/hooks/WindowsPhoneToastNotify.py +++ b/module/plugins/hooks/WindowsPhoneToastNotify.py @@ -9,7 +9,7 @@ from module.plugins.Hook import Hook class WindowsPhoneToastNotify(Hook): __name__ = "WindowsPhoneToastNotify" __type__ = "hook" - __version__ = "0.02" + __version__ = "0.03" __config__ = [("force", "bool", "Force even if client is connected", False), ("pushId", "str", "pushId", ""), @@ -21,6 +21,11 @@ class WindowsPhoneToastNotify(Hook): __authors__ = [("Andy Voigt", "phone-support@hotmail.de")] + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def setup(self): self.info = {} #@TODO: Remove in 0.4.10 diff --git a/module/plugins/hooks/XFileSharingPro.py b/module/plugins/hooks/XFileSharingPro.py index fe955beb9..e9b1b454e 100644 --- a/module/plugins/hooks/XFileSharingPro.py +++ b/module/plugins/hooks/XFileSharingPro.py @@ -8,7 +8,7 @@ from module.plugins.Hook import Hook class XFileSharingPro(Hook): __name__ = "XFileSharingPro" __type__ = "hook" - __version__ = "0.25" + __version__ = "0.26" __config__ = [("activated", "bool", "Activated", True), ("use_hoster_list", "bool", "Load listed hosters only", True), @@ -44,6 +44,11 @@ class XFileSharingPro(Hook): # self.loadPattern() + #@TODO: Remove in 0.4.10 + def initPeriodical(self): + pass + + def coreReady(self): self.loadPattern() -- cgit v1.2.3 From 6151e81fa0b325dffda3da4228d5821e73db3ef3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 9 Dec 2014 01:19:46 +0100 Subject: Fix __version__ format in some plugins --- module/plugins/hooks/RPNetBiz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks') diff --git a/module/plugins/hooks/RPNetBiz.py b/module/plugins/hooks/RPNetBiz.py index e38aa8ea0..917cd02de 100644 --- a/module/plugins/hooks/RPNetBiz.py +++ b/module/plugins/hooks/RPNetBiz.py @@ -8,7 +8,7 @@ from module.plugins.internal.MultiHoster import MultiHoster class RPNetBiz(MultiHoster): __name__ = "RPNetBiz" __type__ = "hook" - __version__ = "0.1" + __version__ = "0.10" __config__ = [("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported):", "all"), ("hosterList", "str", "Hoster list (comma separated)", ""), -- cgit v1.2.3 From 4d578cb15f3d6edd036e438e504739b97660f93e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 9 Dec 2014 16:58:35 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/MergeFiles.py | 61 +++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'module/plugins/hooks') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 767209d21..4de45f958 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + import os import re @@ -53,32 +55,35 @@ class MergeFiles(Hook): for name, file_list in files.iteritems(): self.logInfo(_("Starting merging of"), name) - final_file = open(save_join(download_folder, name), "wb") - - for splitted_file in file_list: - self.logDebug("Merging part", splitted_file) - pyfile = self.core.files.getFile(fid_dict[splitted_file]) - pyfile.setStatus("processing") - try: - s_file = open(os.path.join(download_folder, splitted_file), "rb") - size_written = 0 - s_file_size = int(os.path.getsize(os.path.join(download_folder, splitted_file))) - while True: - f_buffer = s_file.read(self.BUFFER_SIZE) - if f_buffer: - final_file.write(f_buffer) - size_written += self.BUFFER_SIZE - pyfile.setProgress((size_written * 100) / s_file_size) - else: - break - s_file.close() - self.logDebug("Finished merging part", splitted_file) - except Exception, e: - print_exc() - finally: - pyfile.setProgress(100) - pyfile.setStatus("finished") - pyfile.release() - - final_file.close() + + with open(save_join(download_folder, name), "wb") as final_file: + for splitted_file in file_list: + self.logDebug("Merging part", splitted_file) + + pyfile = self.core.files.getFile(fid_dict[splitted_file]) + + pyfile.setStatus("processing") + + try: + with open(os.path.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: + f_buffer = s_file.read(self.BUFFER_SIZE) + if f_buffer: + final_file.write(f_buffer) + size_written += self.BUFFER_SIZE + pyfile.setProgress((size_written * 100) / s_file_size) + else: + break + self.logDebug("Finished merging part", splitted_file) + + except Exception, e: + print_exc() + + finally: + pyfile.setProgress(100) + pyfile.setStatus("finished") + pyfile.release() + self.logInfo(_("Finished merging of"), name) -- cgit v1.2.3