summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/Checksum.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-07 01:23:55 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-07 01:23:55 +0200
commitb1759bc440cd6013837697eb8de540914f693ffd (patch)
treed170caf63d7f65e44d23ea2d91a65759a1665928 /module/plugins/hooks/Checksum.py
parent[Plugin] Fix decoding in load method (diff)
downloadpyload-b1759bc440cd6013837697eb8de540914f693ffd.tar.xz
No camelCase style anymore
Diffstat (limited to 'module/plugins/hooks/Checksum.py')
-rw-r--r--module/plugins/hooks/Checksum.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py
index 409387c39..7f42347df 100644
--- a/module/plugins/hooks/Checksum.py
+++ b/module/plugins/hooks/Checksum.py
@@ -11,7 +11,7 @@ from module.plugins.internal.Hook import Hook
from module.utils import save_join as fs_join, fs_encode
-def computeChecksum(local_file, algorithm):
+def compute_checksum(local_file, algorithm):
if algorithm in getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")):
h = getattr(hashlib, algorithm)()
@@ -38,7 +38,7 @@ def computeChecksum(local_file, algorithm):
class Checksum(Hook):
__name__ = "Checksum"
__type__ = "hook"
- __version__ = "0.17"
+ __version__ = "0.18"
__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"),
@@ -64,8 +64,8 @@ class Checksum(Hook):
def activate(self):
- if not self.getConfig('check_checksum'):
- self.logInfo(_("Checksum validation is disabled in plugin configuration"))
+ if not self.get_config('check_checksum'):
+ self.log_info(_("Checksum validation is disabled in plugin configuration"))
def setup(self):
@@ -98,17 +98,17 @@ class Checksum(Hook):
else:
return
- self.logDebug(data)
+ self.log_debug(data)
if not pyfile.plugin.lastDownload:
- self.checkFailed(pyfile, None, "No file downloaded")
+ self.check_failed(pyfile, None, "No file downloaded")
local_file = fs_encode(pyfile.plugin.lastDownload)
- #download_folder = self.core.config.get("general", "download_folder")
- #local_file = fs_encode(fs_join(download_folder, pyfile.package().folder, pyfile.name))
+ # download_folder = self.core.config.get("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")
+ self.check_failed(pyfile, None, "File does not exist")
#: validate file size
if "size" in data:
@@ -116,13 +116,13 @@ class Checksum(Hook):
file_size = os.path.getsize(local_file)
if api_size != file_size:
- self.logWarning(_("File %s has incorrect size: %d B (%d expected)") % (pyfile.name, file_size, api_size))
- self.checkFailed(pyfile, local_file, "Incorrect file size")
+ self.log_warning(_("File %s has incorrect size: %d B (%d expected)") % (pyfile.name, file_size, api_size))
+ self.check_failed(pyfile, local_file, "Incorrect file size")
data.pop('size', None)
#: validate checksum
- if data and self.getConfig('check_checksum'):
+ if data and self.get_config('check_checksum'):
if not 'md5' in data:
for type in ("checksum", "hashsum", "hash"):
@@ -135,28 +135,28 @@ class Checksum(Hook):
checksum = computeChecksum(local_file, key.replace("-", "").lower())
if checksum:
if checksum == data[key].lower():
- self.logInfo(_('File integrity of "%s" verified by %s checksum (%s)') %
+ self.log_info(_('File integrity of "%s" verified by %s checksum (%s)') %
(pyfile.name, key.upper(), checksum))
break
else:
- self.logWarning(_("%s checksum for file %s does not match (%s != %s)") %
+ self.log_warning(_("%s checksum for file %s does not match (%s != %s)") %
(key.upper(), pyfile.name, checksum, data[key]))
- self.checkFailed(pyfile, local_file, "Checksums do not match")
+ self.check_failed(pyfile, local_file, "Checksums do not match")
else:
- self.logWarning(_("Unsupported hashing algorithm"), key.upper())
+ self.log_warning(_("Unsupported hashing algorithm"), key.upper())
else:
- self.logWarning(_("Unable to validate checksum for file: ") + pyfile.name)
+ self.log_warning(_("Unable to validate checksum for file: ") + pyfile.name)
- def checkFailed(self, pyfile, local_file, msg):
- check_action = self.getConfig('check_action')
+ def check_failed(self, pyfile, local_file, msg):
+ check_action = self.get_config('check_action')
if check_action == "retry":
- max_tries = self.getConfig('max_tries')
- retry_action = self.getConfig('retry_action')
+ max_tries = self.get_config('max_tries')
+ retry_action = self.get_config('retry_action')
if pyfile.plugin.retries < max_tries:
if local_file:
os.remove(local_file)
- pyfile.plugin.retry(max_tries, self.getConfig('wait_time'), msg)
+ pyfile.plugin.retry(max_tries, self.get_config('wait_time'), msg)
elif retry_action == "nothing":
return
elif check_action == "nothing":
@@ -175,7 +175,7 @@ class Checksum(Hook):
hash_file = fs_encode(fs_join(download_folder, link['name']))
if not os.path.isfile(hash_file):
- self.logWarning(_("File not found"), link['name'])
+ self.log_warning(_("File not found"), link['name'])
continue
with open(hash_file) as f:
@@ -183,14 +183,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.log_debug(link['name'], data)
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']:
- self.logInfo(_('File integrity of "%s" verified by %s checksum (%s)') %
+ self.log_info(_('File integrity of "%s" verified by %s checksum (%s)') %
(data['NAME'], algorithm, checksum))
else:
- self.logWarning(_("%s checksum for file %s does not match (%s != %s)") %
+ self.log_warning(_("%s checksum for file %s does not match (%s != %s)") %
(algorithm, data['NAME'], checksum, data['HASH']))