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/Checksum.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/Checksum.py') diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index af37d69e6..8566a847e 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.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: zoidberg """ from __future__ import with_statement @@ -55,12 +53,15 @@ def computeChecksum(local_file, algorithm): class Checksum(Hook): __name__ = "Checksum" __version__ = "0.12" - __description__ = """Verify downloaded file size and checksum""" + __type__ = "hook" + __config__ = [("activated", "bool", "Activated", False), ("check_action", "fail;retry;nothing", "What to do if check fails?", "retry"), ("max_tries", "int", "Number of retries", 2), ("retry_action", "fail;nothing", "What to do if all retries fail?", "fail"), ("wait_time", "int", "Time to wait before each retry (seconds)", 1)] + + __description__ = """Verify downloaded file size and checksum""" __author_name__ = ("zoidberg", "Walter Purcaro") __author_mail__ = ("zoidberg@mujmail.cz", "vuolter@gmail.com") @@ -70,6 +71,7 @@ class Checksum(Hook): 'crc': r'filename=(?P.+)\nsize=(?P\d+)\ncrc32=(?P[0-9A-Fa-f]{8})$', 'default': r'^(?P[0-9A-Fa-f]+)\s+\*?(?P.+)$'} + def coreReady(self): if not self.config['general']['checksum']: self.logInfo("Checksum validation is disabled in general configuration") -- 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/Checksum.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'module/plugins/hooks/Checksum.py') diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index 8566a847e..a51eb4b47 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -80,7 +80,7 @@ class Checksum(Hook): self.algorithms = sorted( getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse=True) self.algorithms.extend(["crc32", "adler32"]) - self.formats = self.algorithms + ['sfv', 'crc', 'hash'] + self.formats = self.algorithms + ["sfv", "crc", "hash"] def downloadFinished(self, pyfile): """ @@ -158,15 +158,15 @@ class Checksum(Hook): download_folder = save_join(self.config['general']['download_folder'], pypack.folder, "") for link in pypack.getChildren().itervalues(): - file_type = splitext(link["name"])[1][1:].lower() + file_type = splitext(link['name'])[1][1:].lower() #self.logDebug(link, file_type) if file_type not in self.formats: continue - hash_file = fs_encode(save_join(download_folder, link["name"])) + hash_file = fs_encode(save_join(download_folder, link['name'])) if not isfile(hash_file): - self.logWarning("File not found: %s" % link["name"]) + self.logWarning("File not found: %s" % link['name']) continue with open(hash_file) as f: @@ -174,14 +174,14 @@ class Checksum(Hook): for m in re.finditer(self.regexps.get(file_type, self.regexps['default']), text): data = m.groupdict() - self.logDebug(link["name"], data) + self.logDebug(link['name'], data) - local_file = fs_encode(save_join(download_folder, data["name"])) + local_file = fs_encode(save_join(download_folder, data['name'])) algorithm = self.methods.get(file_type, file_type) checksum = computeChecksum(local_file, algorithm) - if checksum == data["hash"]: + if checksum == data['hash']: self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % - (data["name"], algorithm, checksum)) + (data['name'], algorithm, checksum)) else: self.logWarning("%s checksum for file %s does not match (%s != %s)" % - (algorithm, data["name"], checksum, data["hash"])) + (algorithm, data['name'], checksum, data['hash'])) -- 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/Checksum.py | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'module/plugins/hooks/Checksum.py') diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index a51eb4b47..0fe2ae88c 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -1,29 +1,16 @@ # -*- 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 . -""" - from __future__ import with_statement + import hashlib +import re import zlib + from os import remove from os.path import getsize, isfile, splitext -import re -from module.utils import save_join, fs_encode from module.plugins.Hook import Hook +from module.utils import save_join, fs_encode def computeChecksum(local_file, algorithm): @@ -52,8 +39,8 @@ def computeChecksum(local_file, algorithm): class Checksum(Hook): __name__ = "Checksum" - __version__ = "0.12" __type__ = "hook" + __version__ = "0.12" __config__ = [("activated", "bool", "Activated", False), ("check_action", "fail;retry;nothing", "What to do if check fails?", "retry"), -- cgit v1.2.3 From 98d4c07b6983c98fca26f99dd7a853ab36a1d696 Mon Sep 17 00:00:00 2001 From: stickell Date: Sun, 31 Aug 2014 17:55:36 +0200 Subject: [Checksum] Moved the checksum validation toggle to the plugin because the general configuration has been removed in 0.4.10 --- module/plugins/hooks/Checksum.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'module/plugins/hooks/Checksum.py') diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index 0fe2ae88c..013172899 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -40,17 +40,18 @@ def computeChecksum(local_file, algorithm): class Checksum(Hook): __name__ = "Checksum" __type__ = "hook" - __version__ = "0.12" + __version__ = "0.13" __config__ = [("activated", "bool", "Activated", False), + ("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"), ("max_tries", "int", "Number of retries", 2), ("retry_action", "fail;nothing", "What to do if all retries fail?", "fail"), ("wait_time", "int", "Time to wait before each retry (seconds)", 1)] __description__ = """Verify downloaded file size and checksum""" - __author_name__ = ("zoidberg", "Walter Purcaro") - __author_mail__ = ("zoidberg@mujmail.cz", "vuolter@gmail.com") + __author_name__ = ("zoidberg", "Walter Purcaro", "stickell") + __author_mail__ = ("zoidberg@mujmail.cz", "vuolter@gmail.com", "l.stickell@yahoo.it") methods = {'sfv': 'crc32', 'crc': 'crc32', 'hash': 'md5'} regexps = {'sfv': r'^(?P[^;].+)\s+(?P[0-9A-Fa-f]{8})$', @@ -60,8 +61,8 @@ class Checksum(Hook): def coreReady(self): - if not self.config['general']['checksum']: - self.logInfo("Checksum validation is disabled in general configuration") + if not self.getConfig("check_checksum"): + self.logInfo("Checksum validation is disabled in plugin configuration") def setup(self): self.algorithms = sorted( @@ -105,7 +106,7 @@ class Checksum(Hook): del data['size'] # validate checksum - if data and self.config['general']['checksum']: + if data and self.getConfig("check_checksum"): if "checksum" in data: data['md5'] = data['checksum'] -- cgit v1.2.3