From 48c0c42fd6faffc56432d5f037cd575979f180cc Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 14 Jul 2014 02:23:37 +0200 Subject: Removed all @author flags + key attributes cleanup for internal & hooks plugins --- module/plugins/hooks/MergeFiles.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 99b0aafc6..e7bd63d17 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -13,8 +13,6 @@ You should have received a copy of the GNU General Public License along with this program; if not, see . - - @author: and9000 """ import os @@ -23,7 +21,7 @@ import traceback from os.path import join from module.utils import save_join, fs_encode -from module.plugins.Hook import Hook +from module.plugins.Hook import Hook, threaded BUFFER_SIZE = 4096 @@ -31,16 +29,20 @@ BUFFER_SIZE = 4096 class MergeFiles(Hook): __name__ = "MergeFiles" __version__ = "0.12" - __description__ = """Merges parts splitted with hjsplit""" + __type__ = "hook" + __config__ = [("activated", "bool", "Activated", False)] - __threaded__ = ["packageFinished"] + + __description__ = """Merges parts splitted with hjsplit""" __author_name__ = "and9000" __author_mail__ = "me@has-no-mail.com" + def setup(self): # nothing to do pass + @threaded def packageFinished(self, pack): files = {} fid_dict = {} -- cgit v1.2.3 From 7b8c458cca7d21a029620f98e453f746fce69cd1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 14 Jul 2014 16:10:01 +0200 Subject: Prefer single quote for dict key name --- module/plugins/hooks/MergeFiles.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index e7bd63d17..5d6c208a7 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -47,12 +47,12 @@ class MergeFiles(Hook): files = {} fid_dict = {} for fid, data in pack.getChildren().iteritems(): - if re.search("\.[0-9]{3}$", data["name"]): - if data["name"][:-4] not in files: - files[data["name"][:-4]] = [] - files[data["name"][:-4]].append(data["name"]) - files[data["name"][:-4]].sort() - fid_dict[data["name"]] = fid + if re.search("\.[0-9]{3}$", data['name']): + if data['name'][:-4] not in files: + files[data['name'][:-4]] = [] + files[data['name'][:-4]].append(data['name']) + files[data['name'][:-4]].sort() + fid_dict[data['name']] = fid download_folder = self.config['general']['download_folder'] -- cgit v1.2.3 From ba916633f2bedb04c7358000b91aed69f52e8e43 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 1 Aug 2014 19:35:59 +0200 Subject: Remove trailing whitespaces + remove license headers + import urllib methods directly + sort and fix key attributes + use save_join instead join + sort some import declarations + other minor code cosmetics --- module/plugins/hooks/MergeFiles.py | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 5d6c208a7..a859092fb 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -1,35 +1,17 @@ # -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . -""" - import os import re import traceback -from os.path import join -from module.utils import save_join, fs_encode from module.plugins.Hook import Hook, threaded - -BUFFER_SIZE = 4096 +from module.utils import save_join, fs_encode class MergeFiles(Hook): __name__ = "MergeFiles" - __version__ = "0.12" __type__ = "hook" + __version__ = "0.12" __config__ = [("activated", "bool", "Activated", False)] @@ -37,6 +19,8 @@ class MergeFiles(Hook): __author_name__ = "and9000" __author_mail__ = "me@has-no-mail.com" + BUFFER_SIZE = 4096 + def setup(self): # nothing to do @@ -61,7 +45,7 @@ class MergeFiles(Hook): for name, file_list in files.iteritems(): self.logInfo("Starting merging of %s" % name) - final_file = open(join(download_folder, fs_encode(name)), "wb") + final_file = open(save_join(download_folder, name), "wb") for splitted_file in file_list: self.logDebug("Merging part %s" % splitted_file) @@ -72,10 +56,10 @@ class MergeFiles(Hook): size_written = 0 s_file_size = int(os.path.getsize(os.path.join(download_folder, splitted_file))) while True: - f_buffer = s_file.read(BUFFER_SIZE) + f_buffer = s_file.read(self.BUFFER_SIZE) if f_buffer: final_file.write(f_buffer) - size_written += BUFFER_SIZE + size_written += self.BUFFER_SIZE pyfile.setProgress((size_written * 100) / s_file_size) else: break -- cgit v1.2.3 From 0d220d634e512d89bda540f91c643b361c82ea8a Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 27 Sep 2014 01:38:32 +0200 Subject: Logging string cosmetics --- module/plugins/hooks/MergeFiles.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index a859092fb..dc8092d0a 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -44,11 +44,11 @@ class MergeFiles(Hook): download_folder = save_join(download_folder, pack.folder) for name, file_list in files.iteritems(): - self.logInfo("Starting merging of %s" % name) + 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 %s" % splitted_file) + self.logDebug("Merging part", splitted_file) pyfile = self.core.files.getFile(fid_dict[splitted_file]) pyfile.setStatus("processing") try: @@ -64,7 +64,7 @@ class MergeFiles(Hook): else: break s_file.close() - self.logDebug("Finished merging part %s" % splitted_file) + self.logDebug("Finished merging part", splitted_file) except Exception, e: print traceback.print_exc() finally: @@ -73,4 +73,4 @@ class MergeFiles(Hook): pyfile.release() final_file.close() - self.logInfo("Finished merging of %s" % name) + self.logInfo(_("Finished merging of"), name) -- cgit v1.2.3 From b0868ae6446078bacf1635dde5e4ab316b4a94cb Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 7 Oct 2014 18:57:59 +0200 Subject: New __authors__ key replaces __author_name__ and __author_mail__ + Whitespaces and EOF fixup --- module/plugins/hooks/MergeFiles.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index dc8092d0a..61cef415e 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -16,8 +16,8 @@ class MergeFiles(Hook): __config__ = [("activated", "bool", "Activated", False)] __description__ = """Merges parts splitted with hjsplit""" - __author_name__ = "and9000" - __author_mail__ = "me@has-no-mail.com" + __authors__ = [("and9000", "me@has-no-mail.com")] + BUFFER_SIZE = 4096 -- cgit v1.2.3 From ae7a7e66981456e5bbe2b54006d79b6f907be7a4 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 8 Oct 2014 20:18:13 +0200 Subject: Add __license__ key attribute to plugins --- module/plugins/hooks/MergeFiles.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 61cef415e..627a9ec3c 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -16,6 +16,7 @@ class MergeFiles(Hook): __config__ = [("activated", "bool", "Activated", False)] __description__ = """Merges parts splitted with hjsplit""" + __license__ = "GPLv3" __authors__ = [("and9000", "me@has-no-mail.com")] -- cgit v1.2.3 From f76e5c2336718dca9da8033ba22cd83c72c7b3b3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 11 Oct 2014 15:14:28 +0200 Subject: Pattern update 1 --- module/plugins/hooks/MergeFiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 627a9ec3c..5a23ff862 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -32,7 +32,7 @@ class MergeFiles(Hook): files = {} fid_dict = {} for fid, data in pack.getChildren().iteritems(): - if re.search("\.[0-9]{3}$", data['name']): + if re.search("\.\d{3}$", data['name']): if data['name'][:-4] not in files: files[data['name'][:-4]] = [] files[data['name'][:-4]].append(data['name']) -- cgit v1.2.3 From 0eb6e7ec4a1144dcca824d8add049787d3da1762 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 22 Oct 2014 19:44:59 +0200 Subject: Two space before function declaration --- module/plugins/hooks/MergeFiles.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 5a23ff862..0eab0037c 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -27,6 +27,7 @@ class MergeFiles(Hook): # nothing to do pass + @threaded def packageFinished(self, pack): files = {} -- cgit v1.2.3 From 146fe1e309c33ab149bfaf58ad86c0dd4fb9b156 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 27 Oct 2014 01:18:45 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/MergeFiles.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 0eab0037c..7562df2a8 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -2,7 +2,8 @@ import os import re -import traceback + +from traceback import print_exc from module.plugins.Hook import Hook, threaded from module.utils import save_join, fs_encode @@ -68,7 +69,7 @@ class MergeFiles(Hook): s_file.close() self.logDebug("Finished merging part", splitted_file) except Exception, e: - print traceback.print_exc() + print_exc() finally: pyfile.setProgress(100) pyfile.setStatus("finished") -- cgit v1.2.3 From 885f8ed782e64d9e73367905e642a84d0a8999f1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Oct 2014 04:01:38 +0100 Subject: Update __config__ --- module/plugins/hooks/MergeFiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index 7562df2a8..b61857189 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -14,7 +14,7 @@ class MergeFiles(Hook): __type__ = "hook" __version__ = "0.12" - __config__ = [("activated", "bool", "Activated", False)] + __config__ = [("activated", "bool", "Activated", True)] __description__ = """Merges parts splitted with hjsplit""" __license__ = "GPLv3" -- cgit v1.2.3 From 34984dae733c3f3d47b41a0acfba3724d53c65a1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 28 Oct 2014 16:52:10 +0100 Subject: Code cosmetics: plugin class attributes --- module/plugins/hooks/MergeFiles.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/MergeFiles.py') diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py index b61857189..e6f8bb26f 100644 --- a/module/plugins/hooks/MergeFiles.py +++ b/module/plugins/hooks/MergeFiles.py @@ -10,15 +10,15 @@ from module.utils import save_join, fs_encode class MergeFiles(Hook): - __name__ = "MergeFiles" - __type__ = "hook" + __name__ = "MergeFiles" + __type__ = "hook" __version__ = "0.12" __config__ = [("activated", "bool", "Activated", True)] __description__ = """Merges parts splitted with hjsplit""" - __license__ = "GPLv3" - __authors__ = [("and9000", "me@has-no-mail.com")] + __license__ = "GPLv3" + __authors__ = [("and9000", "me@has-no-mail.com")] BUFFER_SIZE = 4096 -- 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/MergeFiles.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'module/plugins/hooks/MergeFiles.py') 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 -- 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/MergeFiles.py') 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