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/ExtractArchive.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 12e53fe50..a2e7d1dac 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -59,7 +59,8 @@ class ExtractArchive(Hook): """ __name__ = "ExtractArchive" __version__ = "0.16" - __description__ = """Extract different kind of archives""" + __type__ = "hook" + __config__ = [("activated", "bool", "Activated", True), ("fullpath", "bool", "Extract full path", True), ("overwrite", "bool", "Overwrite files", True), @@ -71,11 +72,14 @@ class ExtractArchive(Hook): ("recursive", "bool", "Extract archives in archvies", True), ("queue", "bool", "Wait for all downloads to be finished", True), ("renice", "int", "CPU Priority", 0)] - __author_name__ = ("pyload Team", "AndroKev") - __author_mail__ = ("adminpyload.org", "@pyloadforum") + + __description__ = """Extract different kind of archives""" + __author_name__ = ("pyLoad Team", "AndroKev") + __author_mail__ = ("admin@pyload.org", "@pyloadforum") event_list = ["allDownloadsProcessed"] + def setup(self): self.plugins = [] self.passwords = [] -- 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/ExtractArchive.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index a2e7d1dac..c307deb8f 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -163,7 +163,7 @@ class ExtractArchive(Hook): if not exists(out): makedirs(out) - files_ids = [(save_join(dl, p.folder, x["name"]), x["id"]) for x in p.getChildren().itervalues()] + files_ids = [(save_join(dl, p.folder, x['name']), x['id']) for x in p.getChildren().itervalues()] matched = False # check as long there are unseen files @@ -307,15 +307,15 @@ class ExtractArchive(Hook): if not exists(f): continue try: - if self.config["permission"]["change_file"]: + if self.config['permission']['change_file']: if isfile(f): - chmod(f, int(self.config["permission"]["file"], 8)) + chmod(f, int(self.config['permission']['file'], 8)) elif isdir(f): - chmod(f, int(self.config["permission"]["folder"], 8)) + chmod(f, int(self.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.config['permission']['change_dl'] and os.name != "nt": + uid = getpwnam(self.config['permission']['user'])[2] + gid = getgrnam(self.config['permission']['group'])[2] chown(f, uid, gid) except Exception, e: self.logWarning(_("Setting User and Group failed"), e) -- 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/ExtractArchive.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index c307deb8f..144829459 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -1,19 +1,18 @@ # -*- coding: utf-8 -*- -import sys import os +import sys + +from copy import copy from os import remove, chmod, makedirs -from os.path import exists, basename, isfile, isdir, join +from os.path import exists, basename, isfile, isdir from traceback import print_exc -from copy import copy # monkey patch bug in python 2.6 and lower -# see http://bugs.python.org/issue6122 -# http://bugs.python.org/issue1236 -# http://bugs.python.org/issue1731717 +# http://bugs.python.org/issue6122 , http://bugs.python.org/issue1236 , http://bugs.python.org/issue1731717 if sys.version_info < (2, 7) and os.name != "nt": - from subprocess import Popen import errno + from subprocess import Popen def _eintr_retry_call(func, *args): while True: @@ -44,13 +43,13 @@ if sys.version_info < (2, 7) and os.name != "nt": Popen.wait = wait if os.name != "nt": + from grp import getgrnam from os import chown from pwd import getpwnam - from grp import getgrnam -from module.utils import save_join, fs_encode from module.plugins.Hook import Hook, threaded, Expose from module.plugins.internal.AbstractExtractor import ArchiveError, CRCError, WrongPassword +from module.utils import save_join, fs_encode class ExtractArchive(Hook): @@ -58,8 +57,8 @@ class ExtractArchive(Hook): Provides: unrarFinished (folder, filename) """ __name__ = "ExtractArchive" - __version__ = "0.16" __type__ = "hook" + __version__ = "0.16" __config__ = [("activated", "bool", "Activated", True), ("fullpath", "bool", "Extract full path", True), @@ -158,7 +157,7 @@ class ExtractArchive(Hook): #relative to package folder if destination is relative, otherwise absolute path overwrites them if self.getConfig("subfolder"): - out = join(out, fs_encode(p.folder)) + out = save_join(out, fs_encode(p.folder)) if not exists(out): makedirs(out) -- cgit v1.2.3 From 31ea85f97571cc191fe205f6b4d85b3777818240 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 25 Sep 2014 20:59:30 +0200 Subject: Extend ExtractArchive events + code optimizations https://github.com/pyload/pyload/pull/622 https://github.com/pyload/pyload/pull/726 --- module/plugins/hooks/ExtractArchive.py | 124 ++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 47 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 144829459..84f6eab25 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -53,17 +53,14 @@ from module.utils import save_join, fs_encode class ExtractArchive(Hook): - """ - Provides: unrarFinished (folder, filename) - """ __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "0.16" + __version__ = "0.17" __config__ = [("activated", "bool", "Activated", True), ("fullpath", "bool", "Extract full path", True), ("overwrite", "bool", "Overwrite files", True), - ("passwordfile", "file", "password file", "unrar_passwords.txt"), + ("passwordfile", "file", "password file", "archive_password.txt"), ("deletearchive", "bool", "Delete archives when done", False), ("subfolder", "bool", "Create subfolder for each package", False), ("destination", "folder", "Extract files to", ""), @@ -73,8 +70,8 @@ class ExtractArchive(Hook): ("renice", "int", "CPU Priority", 0)] __description__ = """Extract different kind of archives""" - __author_name__ = ("pyLoad Team", "AndroKev") - __author_mail__ = ("admin@pyload.org", "@pyloadforum") + __author_name__ = ("RaNaN", "AndroKev", "Walter Purcaro") + __author_mail__ = ("ranan@pyload.org", "@pyloadforum", "vuolter@gmail.com") event_list = ["allDownloadsProcessed"] @@ -113,33 +110,50 @@ class ExtractArchive(Hook): # queue with package ids self.queue = [] + @Expose def extractPackage(self, id): """ Extract package with given id""" self.manager.startThread(self.extract, [id]) + def packageFinished(self, pypack): + pid = pypack.id if self.getConfig("queue"): self.logInfo(_("Package %s queued for later extracting") % pypack.name) - self.queue.append(pypack.id) + self.queue.append(pid) else: - self.manager.startThread(self.extract, [pypack.id]) + self.manager.startThread(self.extract, [pid]) + @threaded def allDownloadsProcessed(self, thread): local = copy(self.queue) del self.queue[:] - self.extract(local, thread) + if self.extract(local, thread): #: check only if all gone fine, no failed reporting for now + self.manager.dispatchEvent("all_archives_extracted") + self.manager.dispatchEvent("all_archives_processed") + def extract(self, ids, thread=None): + processed = [] + extracted = [] + failed = [] + + destination = self.getConfig("destination") + subfolder = self.getConfig("subfolder") + fullpath = self.getConfig("fullpath") + overwrite = self.getConfig("overwrite") + excludefiles = self.getConfig("excludefiles") + renice = self.getConfig("renice") + recursive = self.getConfig("recursive") + # reload from txt file self.reloadPasswords() # dl folder dl = self.config['general']['download_folder'] - extracted = [] - #iterate packages -> plugins -> targets for pid in ids: p = self.core.files.getPackage(pid) @@ -148,22 +162,17 @@ class ExtractArchive(Hook): continue # determine output folder - out = save_join(dl, p.folder, "") - # force trailing slash - - if self.getConfig("destination") and self.getConfig("destination").lower() != "none": - - out = save_join(dl, p.folder, self.getConfig("destination"), "") - #relative to package folder if destination is relative, otherwise absolute path overwrites them + out = save_join(dl, p.folder, destination, "") #: force trailing slash - if self.getConfig("subfolder"): - out = save_join(out, fs_encode(p.folder)) + if subfolder: + out = save_join(out, fs_encode(p.folder)) - if not exists(out): - makedirs(out) + if not exists(out): + makedirs(out) files_ids = [(save_join(dl, p.folder, x['name']), x['id']) for x in p.getChildren().itervalues()] matched = False + success = True # check as long there are unseen files while files_ids: @@ -175,17 +184,23 @@ class ExtractArchive(Hook): self.logDebug("Targets for %s: %s" % (plugin.__name__, targets)) matched = True for target, fid in targets: - if target in extracted: + if target in processed: self.logDebug(basename(target), "skipped") continue - extracted.append(target) # prevent extracting same file twice - klass = plugin(self, target, out, self.getConfig("fullpath"), self.getConfig("overwrite"), self.getConfig("excludefiles"), - self.getConfig("renice")) - klass.init() + processed.append(target) # prevent extracting same file twice self.logInfo(basename(target), _("Extract to %s") % out) - new_files = self.startExtracting(klass, fid, p.password.strip().splitlines(), thread) + try: + klass = plugin(self, target, out, fullpath, overwrite, excludefiles, renice) + klass.init() + password = p.password.strip().splitlines() + new_files = self._extract(klass, fid, password, thread) + except Exception, e: + self.logError(basename(target), str(e)) + success = False + continue + self.logDebug("Extracted: %s" % new_files) self.setPermissions(new_files) @@ -193,18 +208,27 @@ class ExtractArchive(Hook): if not exists(file): self.logDebug("new file %s does not exists" % file) continue - if self.getConfig("recursive") and isfile(file): + if recursive and isfile(file): new_files_ids.append((file, fid)) # append as new target files_ids = new_files_ids # also check extracted files - if not matched: + if matched: + if success: + extracted.append(pid) + self.manager.dispatchEvent("package_extracted", p) + else: + failed.append(pid) + self.manager.dispatchEvent("package_extract_failed", p) + else: self.logInfo(_("No files found to extract")) - def startExtracting(self, plugin, fid, passwords, thread): + return True if not failed else False + + + def _extract(self, plugin, fid, passwords, thread): pyfile = self.core.files.getFile(fid) - if not pyfile: - return [] + deletearchive = self.getConfig("deletearchive") pyfile.setCustomStatus(_("extracting")) thread.addActive(pyfile) # keep this file until everything is done @@ -221,7 +245,7 @@ class ExtractArchive(Hook): self.logDebug("Passwords: %s" % str(passwords)) pwlist = copy(self.getPasswords()) - #remove already supplied pws from list (only local) + # remove already supplied pws from list (only local) for pw in passwords: if pw in pwlist: pwlist.remove(pw) @@ -238,13 +262,12 @@ class ExtractArchive(Hook): self.logDebug("Password was wrong") if not success: - self.logError(basename(plugin.file), _("Wrong password")) - return [] + raise Exception(_("Wrong password")) if self.core.debug: self.logDebug("Would delete: %s" % ", ".join(plugin.getDeleteFiles())) - if self.getConfig("deletearchive"): + if deletearchive: files = plugin.getDeleteFiles() self.logInfo(_("Deleting %s files") % len(files)) for f in files: @@ -254,9 +277,11 @@ class ExtractArchive(Hook): self.logDebug("%s does not exists" % f) self.logInfo(basename(plugin.file), _("Extracting finished")) - self.manager.dispatchEvent("unrarFinished", plugin.out, plugin.file) - return plugin.getExtractedFiles() + extracted_files = plugin.getExtractedFiles() + self.manager.dispatchEvent("archive_extracted", pyfile, plugin.out, plugin.file, extracted_files) + + return extracted_files except ArchiveError, e: self.logError(basename(plugin.file), _("Archive Error"), str(e)) @@ -267,40 +292,45 @@ class ExtractArchive(Hook): print_exc() self.logError(basename(plugin.file), _("Unknown Error"), str(e)) - return [] + self.manager.dispatchEvent("archive_extract_failed", pyfile) + raise Exception(_("Extract failed")) + @Expose def getPasswords(self): """ List of saved passwords """ return self.passwords + def reloadPasswords(self): - pwfile = self.getConfig("passwordfile") - if not exists(pwfile): - open(pwfile, "wb").close() + passwordfile = self.getConfig("passwordfile") + if not exists(passwordfile): + open(passwordfile, "wb").close() passwords = [] - f = open(pwfile, "rb") + f = open(passwordfile, "rb") for pw in f.read().splitlines(): passwords.append(pw) f.close() self.passwords = passwords + @Expose def addPassword(self, pw): """ Adds a password to saved list""" - pwfile = self.getConfig("passwordfile") + passwordfile = self.getConfig("passwordfile") if pw in self.passwords: self.passwords.remove(pw) self.passwords.insert(0, pw) - f = open(pwfile, "wb") + f = open(passwordfile, "wb") for pw in self.passwords: f.write(pw + "\n") f.close() + def setPermissions(self, files): for f in files: if not exists(f): -- 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/ExtractArchive.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 84f6eab25..34daf8f4f 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -93,12 +93,12 @@ class ExtractArchive(Hook): if e.errno == 2: self.logInfo(_("No %s installed") % p) else: - self.logWarning(_("Could not activate %s") % p, str(e)) + self.logWarning(_("Could not activate %s") % p, e) if self.core.debug: print_exc() except Exception, e: - self.logWarning(_("Could not activate %s") % p, str(e)) + self.logWarning(_("Could not activate %s") % p, e) if self.core.debug: print_exc() @@ -197,16 +197,16 @@ class ExtractArchive(Hook): password = p.password.strip().splitlines() new_files = self._extract(klass, fid, password, thread) except Exception, e: - self.logError(basename(target), str(e)) + self.logError(basename(target), e) success = False continue - self.logDebug("Extracted: %s" % new_files) + self.logDebug("Extracted", new_files) self.setPermissions(new_files) for file in new_files: if not exists(file): - self.logDebug("new file %s does not exists" % file) + self.logDebug("New file %s does not exists" % file) continue if recursive and isfile(file): new_files_ids.append((file, fid)) # append as new target @@ -242,7 +242,7 @@ class ExtractArchive(Hook): success = True else: self.logInfo(basename(plugin.file), _("Password protected")) - self.logDebug("Passwords: %s" % str(passwords)) + self.logDebug("Passwords", passwords) pwlist = copy(self.getPasswords()) # remove already supplied pws from list (only local) @@ -252,7 +252,7 @@ class ExtractArchive(Hook): for pw in passwords + pwlist: try: - self.logDebug("Try password: %s" % pw) + self.logDebug("Try password", pw) if plugin.checkPassword(pw): plugin.extract(progress, pw) self.addPassword(pw) @@ -265,7 +265,7 @@ class ExtractArchive(Hook): raise Exception(_("Wrong password")) if self.core.debug: - self.logDebug("Would delete: %s" % ", ".join(plugin.getDeleteFiles())) + self.logDebug("Would delete", ", ".join(plugin.getDeleteFiles())) if deletearchive: files = plugin.getDeleteFiles() @@ -284,13 +284,13 @@ class ExtractArchive(Hook): return extracted_files except ArchiveError, e: - self.logError(basename(plugin.file), _("Archive Error"), str(e)) + self.logError(basename(plugin.file), _("Archive Error"), e) except CRCError: self.logError(basename(plugin.file), _("CRC Mismatch")) except Exception, e: if self.core.debug: print_exc() - self.logError(basename(plugin.file), _("Unknown Error"), str(e)) + self.logError(basename(plugin.file), _("Unknown Error"), e) self.manager.dispatchEvent("archive_extract_failed", pyfile) raise Exception(_("Extract failed")) -- 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/ExtractArchive.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 34daf8f4f..191b3f1e8 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -70,8 +70,10 @@ class ExtractArchive(Hook): ("renice", "int", "CPU Priority", 0)] __description__ = """Extract different kind of archives""" - __author_name__ = ("RaNaN", "AndroKev", "Walter Purcaro") - __author_mail__ = ("ranan@pyload.org", "@pyloadforum", "vuolter@gmail.com") + __authors__ = [("RaNaN", "ranan@pyload.org"), + ("AndroKev", None), + ("Walter Purcaro", "vuolter@gmail.com")] + event_list = ["allDownloadsProcessed"] -- 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/ExtractArchive.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 191b3f1e8..f6958941e 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -70,6 +70,7 @@ class ExtractArchive(Hook): ("renice", "int", "CPU Priority", 0)] __description__ = """Extract different kind of archives""" + __license__ = "GPLv3" __authors__ = [("RaNaN", "ranan@pyload.org"), ("AndroKev", None), ("Walter Purcaro", "vuolter@gmail.com")] -- 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/ExtractArchive.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index f6958941e..649689f6e 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -14,6 +14,7 @@ if sys.version_info < (2, 7) and os.name != "nt": import errno from subprocess import Popen + def _eintr_retry_call(func, *args): while True: try: @@ -23,6 +24,7 @@ if sys.version_info < (2, 7) and os.name != "nt": continue raise + # unsued timeout option for older python version def wait(self, timeout=0): """Wait for child process to terminate. Returns returncode -- cgit v1.2.3 From 9f2ebe486a3e155fb6a60e07cccb77ab6a772eb2 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 26 Oct 2014 02:31:54 +0200 Subject: Extend translation support in plugins + a lot of code cosmetics and typo fixes --- module/plugins/hooks/ExtractArchive.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 649689f6e..8164b3157 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -98,12 +98,12 @@ class ExtractArchive(Hook): if e.errno == 2: self.logInfo(_("No %s installed") % p) else: - self.logWarning(_("Could not activate %s") % p, e) + self.logWarning(_("Could not activate %s") % p, repr(e)) if self.core.debug: print_exc() except Exception, e: - self.logWarning(_("Could not activate %s") % p, e) + self.logWarning(_("Could not activate %s") % p, repr(e)) if self.core.debug: print_exc() @@ -202,7 +202,7 @@ class ExtractArchive(Hook): password = p.password.strip().splitlines() new_files = self._extract(klass, fid, password, thread) except Exception, e: - self.logError(basename(target), e) + self.logError(basename(target), repr(e)) success = False continue @@ -289,13 +289,13 @@ class ExtractArchive(Hook): return extracted_files except ArchiveError, e: - self.logError(basename(plugin.file), _("Archive Error"), e) + self.logError(basename(plugin.file), _("Archive Error"), repr(e)) except CRCError: self.logError(basename(plugin.file), _("CRC Mismatch")) except Exception, e: if self.core.debug: print_exc() - self.logError(basename(plugin.file), _("Unknown Error"), e) + self.logError(basename(plugin.file), _("Unknown Error"), repr(e)) self.manager.dispatchEvent("archive_extract_failed", pyfile) raise Exception(_("Extract failed")) @@ -352,4 +352,4 @@ class ExtractArchive(Hook): gid = getgrnam(self.config['permission']['group'])[2] chown(f, uid, gid) except Exception, e: - self.logWarning(_("Setting User and Group failed"), e) + self.logWarning(_("Setting User and Group failed"), repr(e)) -- 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/ExtractArchive.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 8164b3157..4a4f2d4d8 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -98,12 +98,12 @@ class ExtractArchive(Hook): if e.errno == 2: self.logInfo(_("No %s installed") % p) else: - self.logWarning(_("Could not activate %s") % p, repr(e)) + self.logWarning(_("Could not activate %s") % p, str(e)) if self.core.debug: print_exc() except Exception, e: - self.logWarning(_("Could not activate %s") % p, repr(e)) + self.logWarning(_("Could not activate %s") % p, str(e)) if self.core.debug: print_exc() @@ -202,7 +202,7 @@ class ExtractArchive(Hook): password = p.password.strip().splitlines() new_files = self._extract(klass, fid, password, thread) except Exception, e: - self.logError(basename(target), repr(e)) + self.logError(basename(target), str(e)) success = False continue @@ -289,13 +289,13 @@ class ExtractArchive(Hook): return extracted_files except ArchiveError, e: - self.logError(basename(plugin.file), _("Archive Error"), repr(e)) + self.logError(basename(plugin.file), _("Archive Error"), str(e)) except CRCError: self.logError(basename(plugin.file), _("CRC Mismatch")) except Exception, e: if self.core.debug: print_exc() - self.logError(basename(plugin.file), _("Unknown Error"), repr(e)) + self.logError(basename(plugin.file), _("Unknown Error"), str(e)) self.manager.dispatchEvent("archive_extract_failed", pyfile) raise Exception(_("Extract failed")) @@ -352,4 +352,4 @@ class ExtractArchive(Hook): gid = getgrnam(self.config['permission']['group'])[2] chown(f, uid, gid) except Exception, e: - self.logWarning(_("Setting User and Group failed"), repr(e)) + self.logWarning(_("Setting User and Group failed"), str(e)) -- 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/ExtractArchive.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 4a4f2d4d8..3d6df5b02 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -55,8 +55,8 @@ from module.utils import save_join, fs_encode class ExtractArchive(Hook): - __name__ = "ExtractArchive" - __type__ = "hook" + __name__ = "ExtractArchive" + __type__ = "hook" __version__ = "0.17" __config__ = [("activated", "bool", "Activated", True), @@ -72,10 +72,10 @@ class ExtractArchive(Hook): ("renice", "int", "CPU Priority", 0)] __description__ = """Extract different kind of archives""" - __license__ = "GPLv3" - __authors__ = [("RaNaN", "ranan@pyload.org"), - ("AndroKev", None), - ("Walter Purcaro", "vuolter@gmail.com")] + __license__ = "GPLv3" + __authors__ = [("RaNaN", "ranan@pyload.org"), + ("AndroKev", None), + ("Walter Purcaro", "vuolter@gmail.com")] event_list = ["allDownloadsProcessed"] -- cgit v1.2.3 From bd8259220ab4d56ab419b7b32045b08cc9b0a7c8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:08:19 +0100 Subject: Use with statement instead open method when accessing fod + handle i/o error --- module/plugins/hooks/ExtractArchive.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 3d6df5b02..39da1ee7b 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -309,16 +309,18 @@ class ExtractArchive(Hook): def reloadPasswords(self): passwordfile = self.getConfig("passwordfile") - if not exists(passwordfile): - open(passwordfile, "wb").close() - - passwords = [] - f = open(passwordfile, "rb") - for pw in f.read().splitlines(): - passwords.append(pw) - f.close() - - self.passwords = passwords + + try: + passwords = [] + with open(passwordfile, "a+") as f: + for pw in f.read().splitlines(): + passwords.append(pw) + + except IOError, e: + self.logError(str(e)) + + else: + self.passwords = passwords @Expose @@ -328,12 +330,15 @@ class ExtractArchive(Hook): if pw in self.passwords: self.passwords.remove(pw) + self.passwords.insert(0, pw) - f = open(passwordfile, "wb") - for pw in self.passwords: - f.write(pw + "\n") - f.close() + try: + with open(passwordfile, "wb") as f: + for pw in self.passwords: + f.write(pw + "\n") + except IOError, e: + self.logError(str(e)) def setPermissions(self, files): -- cgit v1.2.3 From 59f72bfc5ed721c80c821bd0ca1bc8daf0d49880 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:12:41 +0100 Subject: Code cosmetics --- module/plugins/hooks/ExtractArchive.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 39da1ee7b..f5f30fc52 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -309,16 +309,16 @@ class ExtractArchive(Hook): def reloadPasswords(self): passwordfile = self.getConfig("passwordfile") - + try: passwords = [] with open(passwordfile, "a+") as f: for pw in f.read().splitlines(): passwords.append(pw) - + except IOError, e: self.logError(str(e)) - + else: self.passwords = passwords @@ -330,7 +330,7 @@ class ExtractArchive(Hook): if pw in self.passwords: self.passwords.remove(pw) - + self.passwords.insert(0, pw) try: -- cgit v1.2.3 From c9e31d875d32de31e54959b82bc35eff2b3e0f3f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 10 Nov 2014 00:19:51 +0100 Subject: Code cosmetics --- module/plugins/hooks/ExtractArchive.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index f5f30fc52..11c44a6d1 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -98,12 +98,12 @@ class ExtractArchive(Hook): if e.errno == 2: self.logInfo(_("No %s installed") % p) else: - self.logWarning(_("Could not activate %s") % p, str(e)) + self.logWarning(_("Could not activate %s") % p, e) if self.core.debug: print_exc() except Exception, e: - self.logWarning(_("Could not activate %s") % p, str(e)) + self.logWarning(_("Could not activate %s") % p, e) if self.core.debug: print_exc() @@ -202,7 +202,7 @@ class ExtractArchive(Hook): password = p.password.strip().splitlines() new_files = self._extract(klass, fid, password, thread) except Exception, e: - self.logError(basename(target), str(e)) + self.logError(basename(target), e) success = False continue @@ -289,13 +289,13 @@ class ExtractArchive(Hook): return extracted_files except ArchiveError, e: - self.logError(basename(plugin.file), _("Archive Error"), str(e)) + self.logError(basename(plugin.file), _("Archive Error"), e) except CRCError: self.logError(basename(plugin.file), _("CRC Mismatch")) except Exception, e: if self.core.debug: print_exc() - self.logError(basename(plugin.file), _("Unknown Error"), str(e)) + self.logError(basename(plugin.file), _("Unknown Error"), e) self.manager.dispatchEvent("archive_extract_failed", pyfile) raise Exception(_("Extract failed")) @@ -317,7 +317,7 @@ class ExtractArchive(Hook): passwords.append(pw) except IOError, e: - self.logError(str(e)) + self.logError(e) else: self.passwords = passwords @@ -338,7 +338,7 @@ class ExtractArchive(Hook): for pw in self.passwords: f.write(pw + "\n") except IOError, e: - self.logError(str(e)) + self.logError(e) def setPermissions(self, files): @@ -357,4 +357,4 @@ class ExtractArchive(Hook): gid = getgrnam(self.config['permission']['group'])[2] chown(f, uid, gid) except Exception, e: - self.logWarning(_("Setting User and Group failed"), str(e)) + self.logWarning(_("Setting User and Group failed"), e) -- cgit v1.2.3 From 52664e6fe8dd99fc9bb78ea8cf158c17705b6ded Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 5 Dec 2014 19:18:11 +0100 Subject: Fix with statement on old env like python 2.5 (2) --- module/plugins/hooks/ExtractArchive.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 11c44a6d1..07db13aa1 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + import os import sys @@ -57,7 +59,7 @@ from module.utils import save_join, fs_encode class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "0.17" + __version__ = "0.18" __config__ = [("activated", "bool", "Activated", True), ("fullpath", "bool", "Extract full path", True), -- 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/ExtractArchive.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'module/plugins/hooks/ExtractArchive.py') 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 = [] -- cgit v1.2.3 From 8bb189cf5495b293cf574e5049c34a64ae36ffe1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 16 Dec 2014 23:04:15 +0100 Subject: Spare code cosmetics --- module/plugins/hooks/ExtractArchive.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index fc77dbdf6..895aee51f 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -195,6 +195,7 @@ class ExtractArchive(Hook): if targets: self.logDebug("Targets for %s: %s" % (plugin.__name__, targets)) matched = True + for target, fid in targets: if target in processed: self.logDebug(basename(target), "skipped") @@ -206,8 +207,10 @@ class ExtractArchive(Hook): try: klass = plugin(self, target, out, fullpath, overwrite, excludefiles, renice) klass.init() - password = p.password.strip().splitlines() - new_files = self._extract(klass, fid, password, thread) + + passwords = p.password.strip().splitlines() + new_files = self._extract(klass, fid, passwords, thread) + except Exception, e: self.logError(basename(target), e) success = False @@ -256,13 +259,7 @@ class ExtractArchive(Hook): self.logInfo(basename(plugin.file), _("Password protected")) self.logDebug("Passwords", passwords) - pwlist = copy(self.getPasswords()) - # remove already supplied pws from list (only local) - for pw in passwords: - if pw in pwlist: - pwlist.remove(pw) - - for pw in passwords + pwlist: + for pw in set(passwords) + set(self.getPasswords()): try: self.logDebug("Try password", pw) if plugin.checkPassword(pw): @@ -270,6 +267,7 @@ class ExtractArchive(Hook): self.addPassword(pw) success = True break + except WrongPassword: self.logDebug("Password was wrong") @@ -297,8 +295,10 @@ class ExtractArchive(Hook): except ArchiveError, e: self.logError(basename(plugin.file), _("Archive Error"), e) + except CRCError: self.logError(basename(plugin.file), _("CRC Mismatch")) + except Exception, e: if self.core.debug: print_exc() -- cgit v1.2.3 From da9e6c949243613f4d5e100cac6ff192449b4718 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 18 Dec 2014 18:45:17 +0100 Subject: Update extractor plugins --- module/plugins/hooks/ExtractArchive.py | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 895aee51f..ddec8319b 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -16,7 +16,6 @@ if sys.version_info < (2, 7) and os.name != "nt": import errno from subprocess import Popen - def _eintr_retry_call(func, *args): while True: try: @@ -59,7 +58,7 @@ from module.utils import save_join, fs_encode class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "0.19" + __version__ = "0.20" __config__ = [("activated", "bool", "Activated", True), ("fullpath", "bool", "Extract full path", True), @@ -89,7 +88,7 @@ class ExtractArchive(Hook): def setup(self): - self.plugins = [] + self.plugins = [] self.passwords = [] names = [] @@ -141,24 +140,27 @@ class ExtractArchive(Hook): @threaded def allDownloadsProcessed(self, thread): local = copy(self.queue) + del self.queue[:] + if self.extract(local, thread): #: check only if all gone fine, no failed reporting for now self.manager.dispatchEvent("all_archives_extracted") + self.manager.dispatchEvent("all_archives_processed") def extract(self, ids, thread=None): processed = [] extracted = [] - failed = [] + failed = [] - destination = self.getConfig("destination") - subfolder = self.getConfig("subfolder") - fullpath = self.getConfig("fullpath") - overwrite = self.getConfig("overwrite") + destination = self.getConfig("destination") + subfolder = self.getConfig("subfolder") + fullpath = self.getConfig("fullpath") + overwrite = self.getConfig("overwrite") excludefiles = self.getConfig("excludefiles") - renice = self.getConfig("renice") - recursive = self.getConfig("recursive") + renice = self.getConfig("renice") + recursive = self.getConfig("recursive") # reload from txt file self.reloadPasswords() @@ -208,8 +210,7 @@ class ExtractArchive(Hook): klass = plugin(self, target, out, fullpath, overwrite, excludefiles, renice) klass.init() - passwords = p.password.strip().splitlines() - new_files = self._extract(klass, fid, passwords, thread) + new_files = self._extract(klass, fid, [p.password.strip()], thread) except Exception, e: self.logError(basename(target), e) @@ -253,15 +254,15 @@ class ExtractArchive(Hook): success = False if not plugin.checkArchive(): - plugin.extract(progress) + plugin.extract(progress, pw) success = True else: self.logInfo(basename(plugin.file), _("Password protected")) - self.logDebug("Passwords", passwords) + self.logDebug("Passwords: %s" % passwords if passwords else "No password provided") - for pw in set(passwords) + set(self.getPasswords()): + for pw in set(passwords) | set(self.getPasswords()): try: - self.logDebug("Try password", pw) + self.logDebug("Try password: %s" % pw) if plugin.checkPassword(pw): plugin.extract(progress, pw) self.addPassword(pw) @@ -305,6 +306,7 @@ class ExtractArchive(Hook): self.logError(basename(plugin.file), _("Unknown Error"), e) self.manager.dispatchEvent("archive_extract_failed", pyfile) + raise Exception(_("Extract failed")) @@ -344,6 +346,7 @@ class ExtractArchive(Hook): with open(passwordfile, "wb") as f: for pw in self.passwords: f.write(pw + "\n") + except IOError, e: self.logError(e) @@ -352,6 +355,7 @@ class ExtractArchive(Hook): for f in files: if not exists(f): continue + try: if self.config['permission']['change_file']: if isfile(f): @@ -363,5 +367,6 @@ class ExtractArchive(Hook): uid = getpwnam(self.config['permission']['user'])[2] gid = getgrnam(self.config['permission']['group'])[2] chown(f, uid, gid) + except Exception, e: self.logWarning(_("Setting User and Group failed"), e) -- cgit v1.2.3 From 29df1397bbbe80eced4674b6fa39e16540c80901 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 24 Dec 2014 01:11:44 +0100 Subject: Extractor rewritten --- module/plugins/hooks/ExtractArchive.py | 168 ++++++++++++++++++++++----------- 1 file changed, 115 insertions(+), 53 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index ddec8319b..16942bef0 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -51,32 +51,33 @@ if os.name != "nt": from pwd import getpwnam from module.plugins.Hook import Hook, threaded, Expose -from module.plugins.internal.AbstractExtractor import ArchiveError, CRCError, WrongPassword -from module.utils import save_join, fs_encode +from module.plugins.internal.AbstractExtractor import ArchiveError, CRCError, PasswordError +from module.utils import save_join, uniqify class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "0.20" - - __config__ = [("activated", "bool", "Activated", True), - ("fullpath", "bool", "Extract full path", True), - ("overwrite", "bool", "Overwrite files", True), - ("passwordfile", "file", "password file", "archive_password.txt"), - ("deletearchive", "bool", "Delete archives when done", False), - ("subfolder", "bool", "Create subfolder for each package", False), - ("destination", "folder", "Extract files to", ""), - ("excludefiles", "str", "Exclude files from unpacking (seperated by ;)", ""), - ("recursive", "bool", "Extract archives in archvies", True), - ("queue", "bool", "Wait for all downloads to be finished", True), - ("renice", "int", "CPU Priority", 0)] + __version__ = "1.00" + + __config__ = [("activated" , "bool" , "Activated" , True ), + ("fullpath" , "bool" , "Extract full path" , True ), + ("overwrite" , "bool" , "Overwrite files" , False ), + ("keepbroken" , "bool" , "Extract broken archives" , False ), + ("repair" , "bool" , "Repair broken archives" , True ), + ("passwordfile" , "file" , "Store passwords in file" , "archive_password.txt" ), + ("delete" , "bool" , "Delete archive when successfully extracted", False ), + ("subfolder" , "bool" , "Create subfolder for each package" , False ), + ("destination" , "folder", "Extract files to" , "" ), + ("extensions" , "str" , "Extract the following extensions" , "7z,bz2,bzip2,gz,gzip,lha,lzh,lzma,rar,tar,taz,tbz,tbz2,tgz,xar,xz,z,zip"), + ("excludefiles" , "str" , "Don't extract the following files" , "*.nfo,*.DS_Store,index.dat,thumb.db" ), + ("recursive" , "bool" , "Extract archives in archives" , True ), + ("queue" , "bool" , "Wait for all downloads to be finished" , True ), + ("renice" , "int" , "CPU Priority" , 0 )] __description__ = """Extract different kind of archives""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "ranan@pyload.org"), - ("AndroKev", None), - ("Walter Purcaro", "vuolter@gmail.com")] + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] event_list = ["allDownloadsProcessed"] @@ -92,7 +93,7 @@ class ExtractArchive(Hook): self.passwords = [] names = [] - for p in ("UnRar", "UnZip"): + for p in ("UnRar", "SevenZip", "UnZip"): try: module = self.core.pluginManager.loadModule("internal", p) klass = getattr(module, p) @@ -154,13 +155,21 @@ class ExtractArchive(Hook): extracted = [] failed = [] + clearlist = lambda string: [x.lstrip('.') for x in string.replace(' ', '').replace(',', '|').replace(';', '|').split('|')] + destination = self.getConfig("destination") subfolder = self.getConfig("subfolder") fullpath = self.getConfig("fullpath") overwrite = self.getConfig("overwrite") - excludefiles = self.getConfig("excludefiles") + extensions = clearlist(self.getConfig("extensions")) + excludefiles = clearlist(self.getConfig("excludefiles")) renice = self.getConfig("renice") recursive = self.getConfig("recursive") + delete = self.getConfig("delete") + keepbroken = self.getConfig("keepbroken") + + if extensions: + self.logDebug("Extensions allowed: %s" % "|.".join(extensions)) # reload from txt file self.reloadPasswords() @@ -171,7 +180,7 @@ class ExtractArchive(Hook): #iterate packages -> plugins -> targets for pid in ids: p = self.core.files.getPackage(pid) - self.logInfo(_("Check package %s") % p.name) + self.logInfo(_("Check package: %s") % p.name) if not p: continue @@ -179,21 +188,25 @@ class ExtractArchive(Hook): out = save_join(dl, p.folder, destination, "") #: force trailing slash if subfolder: - out = save_join(out, fs_encode(p.folder)) + out = save_join(out, p.folder) if not exists(out): makedirs(out) files_ids = [(save_join(dl, p.folder, x['name']), x['id']) for x in p.getChildren().itervalues()] - matched = False - success = True + matched = False + success = True # check as long there are unseen files while files_ids: new_files_ids = [] + if extensions: + files_ids = [(file, id) for file, id in files_ids if filter(lambda ext: file.endswith(ext), extensions)] + for plugin in self.plugins: targets = plugin.getTargets(files_ids) + if targets: self.logDebug("Targets for %s: %s" % (plugin.__name__, targets)) matched = True @@ -205,19 +218,31 @@ class ExtractArchive(Hook): processed.append(target) # prevent extracting same file twice - self.logInfo(basename(target), _("Extract to %s") % out) + self.logInfo(basename(target), _("Extract to: %s") % out) try: - klass = plugin(self, target, out, fullpath, overwrite, excludefiles, renice) + klass = plugin(self, + target, + out, + p.password, + fullpath, + overwrite, + excludefiles, + renice, + delete, + keepbroken) klass.init() - new_files = self._extract(klass, fid, [p.password.strip()], thread) + new_files = self._extract(klass, fid, thread) except Exception, e: self.logError(basename(target), e) + new_files = None + + if new_files is None: success = False continue - self.logDebug("Extracted", new_files) + self.logDebug("Extracted files: %s" % new_files) self.setPermissions(new_files) for file in new_files: @@ -242,43 +267,78 @@ class ExtractArchive(Hook): return True if not failed else False - def _extract(self, plugin, fid, passwords, thread): + def _extract(self, plugin, fid, thread): pyfile = self.core.files.getFile(fid) - deletearchive = self.getConfig("deletearchive") pyfile.setCustomStatus(_("extracting")) thread.addActive(pyfile) # keep this file until everything is done try: - progress = lambda x: pyfile.setProgress(x) - success = False + progress = lambda x: pyfile.setProgress(x) + encrypted = False + passwords = self.getPasswords() + + try: + self.logInfo(basename(plugin.file), "Verifying...") + + tmp_password = plugin.password + plugin.password = "" #: Force verifying without password + + plugin.verify() + + except PasswordError: + encrypted = True + + except CRCError: + self.logWarning(basename(plugin.file), _("Archive damaged")) + + if not self.getConfig("repair"): + raise CRCError + + elif plugin.repair(): + self.logInfo(basename(plugin.file), _("Successfully repaired")) + + elif not self.getConfig("keepbroken"): + raise ArchiveError(_("Broken archive")) + + else: + self.logInfo(basename(plugin.file), _("All OK")) + + plugin.password = tmp_password + + if not encrypted: + plugin.extract(progress) - if not plugin.checkArchive(): - plugin.extract(progress, pw) - success = True else: self.logInfo(basename(plugin.file), _("Password protected")) - self.logDebug("Passwords: %s" % passwords if passwords else "No password provided") - for pw in set(passwords) | set(self.getPasswords()): + if plugin.password: + passwords.insert(0, plugin.password) + passwords = uniqify(self.passwords) + self.logDebug("Password: %s" % plugin.password) + else: + self.logDebug("No package password provided") + + for pw in passwords: try: self.logDebug("Try password: %s" % pw) - if plugin.checkPassword(pw): - plugin.extract(progress, pw) + + if plugin.setPassword(pw): + plugin.extract(progress) self.addPassword(pw) - success = True break + else: + raise PasswordError - except WrongPassword: + except PasswordError: self.logDebug("Password was wrong") - - if not success: - raise Exception(_("Wrong password")) + else: + raise PasswordError if self.core.debug: - self.logDebug("Would delete", ", ".join(plugin.getDeleteFiles())) + self.logDebug("Would delete: %s" % ", ".join(plugin.getDeleteFiles())) - if deletearchive: + if self.getConfig("delete"): files = plugin.getDeleteFiles() self.logInfo(_("Deleting %s files") % len(files)) for f in files: @@ -294,12 +354,16 @@ class ExtractArchive(Hook): return extracted_files - except ArchiveError, e: - self.logError(basename(plugin.file), _("Archive Error"), e) + except PasswordError: + self.logError(basename(plugin.file), _("Wrong password" if passwords else "No password found")) + plugin.password = "" except CRCError: self.logError(basename(plugin.file), _("CRC Mismatch")) + except ArchiveError, e: + self.logError(basename(plugin.file), _("Archive Error"), e) + except Exception, e: if self.core.debug: print_exc() @@ -307,7 +371,7 @@ class ExtractArchive(Hook): self.manager.dispatchEvent("archive_extract_failed", pyfile) - raise Exception(_("Extract failed")) + self.logError(basename(plugin.file), _("Extract failed")) @Expose @@ -337,15 +401,13 @@ class ExtractArchive(Hook): """ Adds a password to saved list""" passwordfile = self.getConfig("passwordfile") - if pw in self.passwords: - self.passwords.remove(pw) - self.passwords.insert(0, pw) + self.passwords = uniqify(self.passwords) try: with open(passwordfile, "wb") as f: for pw in self.passwords: - f.write(pw + "\n") + f.write(pw + '\n') except IOError, e: self.logError(e) -- cgit v1.2.3 From f71c1ef70a199e42e8a519364d9924e138ffd37c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 24 Dec 2014 15:48:08 +0100 Subject: [ExtractArchive] Remove empty directory --- module/plugins/hooks/ExtractArchive.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 16942bef0..8b3b4e310 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -58,7 +58,7 @@ from module.utils import save_join, uniqify class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "1.00" + __version__ = "1.01" __config__ = [("activated" , "bool" , "Activated" , True ), ("fullpath" , "bool" , "Extract full path" , True ), @@ -135,7 +135,7 @@ class ExtractArchive(Hook): self.logInfo(_("Package %s queued for later extracting") % pypack.name) self.queue.append(pid) else: - self.manager.startThread(self.extract, [pid]) + self.extractPackage(pid) @threaded @@ -239,6 +239,7 @@ class ExtractArchive(Hook): new_files = None if new_files is None: + self.logWarning(basename(target), _("No files extracted")) success = False continue @@ -264,6 +265,12 @@ class ExtractArchive(Hook): else: self.logInfo(_("No files found to extract")) + if not matched or not success and subfolder: + try: + os.rmdir(out) + except OSError: + pass + return True if not failed else False -- cgit v1.2.3 From 4c63928557398891c30d3e2b7c962a07b3483315 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 26 Dec 2014 04:18:41 +0100 Subject: Rename AbstractExtractor to Extractor --- module/plugins/hooks/ExtractArchive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/ExtractArchive.py') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 8b3b4e310..af78ffc93 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -51,14 +51,14 @@ if os.name != "nt": from pwd import getpwnam from module.plugins.Hook import Hook, threaded, Expose -from module.plugins.internal.AbstractExtractor import ArchiveError, CRCError, PasswordError +from module.plugins.internal.Extractor import ArchiveError, CRCError, PasswordError from module.utils import save_join, uniqify class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "1.01" + __version__ = "1.02" __config__ = [("activated" , "bool" , "Activated" , True ), ("fullpath" , "bool" , "Extract full path" , True ), -- cgit v1.2.3