From 411d8031c3ce4547b9f165761f74f0067bea7e7b Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 8 Jun 2016 08:26:04 +0200 Subject: [ExtractArchive] Fix --- module/plugins/hooks/ExtractArchive.py | 23 +++++++++++------------ module/plugins/internal/Extractor.py | 13 +++++++------ module/plugins/internal/UnRar.py | 5 ++++- module/plugins/internal/UnTar.py | 5 ++++- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 6d559bfcb..b9e6842cf 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -277,15 +277,15 @@ class ExtractArchive(Addon): matched = False success = True - files_ids = dict((fdata['name'], ((fsjoin(dl_folder, pypack.folder, fdata['name'])), fid, out)) for fid, fdata \ - in sorted(pypack.getChildren().values(), key=lambda k: k['name'])).items() #: Remove duplicates + files_ids = dict((fdata['name'], (fdata['id'], (fsjoin(dl_folder, pypack.folder, fdata['name'])), out)) for fdata \ + in pypack.getChildren().values()).values() #: Remove duplicates #: Check as long there are unseen files while files_ids: new_files_ids = [] if extensions: - files_ids = [(fname, fid, fout) for fname, fid, fout in files_ids \ + files_ids = [(fid, fname, fout) for fid, fname, fout in files_ids \ if filter(lambda ext: fname.lower().endswith(ext), extensions)] for Extractor in self.extractors: @@ -294,7 +294,7 @@ class ExtractArchive(Addon): self.log_debug("Targets for %s: %s" % (Extractor.__name__, targets)) matched = True - for fname, fid, fout in targets: + for fid, fname, fout in targets: name = os.path.basename(fname) if not exists(fname): @@ -304,15 +304,14 @@ class ExtractArchive(Addon): self.log_info(name, _("Extract to: %s") % fout) try: pyfile = self.pyload.files.getFile(fid) - archive = Extractor(self, + archive = Extractor(pyfile, fname, fout, fullpath, overwrite, excludefiles, priority, - keepbroken, - fid) + keepbroken) thread.addActive(pyfile) archive.init() @@ -330,12 +329,12 @@ class ExtractArchive(Addon): continue #: Remove processed file and related multiparts from list - files_ids = [(fname, fid, fout) for fname, fid, fout in files_ids \ + files_ids = [(fid, fname, fout) for fid, fname, fout in files_ids \ if fname not in archive.items()] self.log_debug("Extracted files: %s" % new_files) - for file in new_files: - self.set_permissions(file) + for filename in new_files: + self.set_permissions(filename) for filename in new_files: file = encode(fsjoin(os.path.dirname(archive.filename), filename)) @@ -344,7 +343,7 @@ class ExtractArchive(Addon): continue if recursive and os.path.isfile(file): - new_files_ids.append((filename, fid, os.path.dirname(filename))) #: Append as new target + new_files_ids.append((fid, filename, os.path.dirname(filename))) #: Append as new target self.manager.dispatchEvent("archive_extracted", pyfile, archive) @@ -447,7 +446,7 @@ class ExtractArchive(Addon): pyfile.setProgress(100) pyfile.setStatus("processing") - delfiles = archive.items() + delfiles = archive.chunks() self.log_debug("Would delete: " + ", ".join(delfiles)) if self.config.get('delete'): diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index 8a16cdd38..3c9af376a 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -104,7 +104,7 @@ class Extractor(Plugin): self.excludefiles = excludefiles self.priority = priority self.keepbroken = keepbroken - self.progress = lambda x: pyfile.setProgress(int(x)) + self.files = None self.init() @@ -119,11 +119,6 @@ class Extractor(Plugin): return encode(self.out) - def _log(self, level, plugintype, pluginname, messages): - messages = (self.__name__,) + messages - return self.pyfile.plugin._log(level, plugintype, self.pyfile.plugin.__name__, messages) - - def verify(self, password=None): """ Testing with Extractors built-in method @@ -156,3 +151,9 @@ class Extractor(Plugin): Return list of archive files """ raise NotImplementedError + + def progress(self, x): + """ + Set extraction progress + """ + return self.pyfile.setProgress(int(x)) diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 3b1d7b290..b91f2455b 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -123,7 +123,7 @@ class UnRar(Extractor): break #: Reading a percentage sign -> set progress and restart if c == "%": - self.notifyprogress(int(s)) + self.pyfile.setProgress(int(s)) s = "" #: Not reading a digit -> therefore restart elif c not in string.digits: @@ -155,6 +155,9 @@ class UnRar(Extractor): if p.returncode: raise ArchiveError(_("Process return code: %d") % p.returncode) + self.files = self.list(password) + return self.files + def chunks(self): dir, name = os.path.split(self.filename) diff --git a/module/plugins/internal/UnTar.py b/module/plugins/internal/UnTar.py index f2a140ca7..7cc8516ae 100644 --- a/module/plugins/internal/UnTar.py +++ b/module/plugins/internal/UnTar.py @@ -25,7 +25,10 @@ class UnTar(Extractor): @classmethod def isarchive(cls, filename): - return tarfile.is_tarfile(encode(filename)) + try: + return tarfile.is_tarfile(encode(filename)) + except: + return False @classmethod -- cgit v1.2.3 From 8d550644b7547114327752aa840f032352a661f1 Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 8 Jun 2016 08:37:39 +0200 Subject: [ExtractArchive] Maintain archive.files property --- module/plugins/internal/UnRar.py | 6 +++--- module/plugins/internal/UnTar.py | 7 +++++-- module/plugins/internal/UnZip.py | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index b91f2455b..1d2e79d58 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -155,8 +155,7 @@ class UnRar(Extractor): if p.returncode: raise ArchiveError(_("Process return code: %d") % p.returncode) - self.files = self.list(password) - return self.files + return self.list(password) def chunks(self): @@ -195,7 +194,8 @@ class UnRar(Extractor): for f in decode(out).splitlines(): result.add(fsjoin(self.dest, f.strip())) - return list(result) + self.files = list(result) + return self.files def call_cmd(self, command, *xargs, **kwargs): diff --git a/module/plugins/internal/UnTar.py b/module/plugins/internal/UnTar.py index 7cc8516ae..4e498c223 100644 --- a/module/plugins/internal/UnTar.py +++ b/module/plugins/internal/UnTar.py @@ -38,7 +38,8 @@ class UnTar(Extractor): def list(self, password=None): with tarfile.open(self.target) as t: - return t.getnames() + self.files = t.getnames() + return self.files def verify(self, password=None): @@ -56,11 +57,13 @@ class UnTar(Extractor): def extract(self, password=None): - self.verify() + self.verify(password) try: with tarfile.open(self.target, errorlevel=2) as t: t.extractall(self.dest) + self.files = t.getnames() + return self.files except tarfile.ExtractError, e: self.log_warning(e) diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 50ab80da3..2870dc4eb 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -36,7 +36,8 @@ class UnZip(Extractor): def list(self, password=None): with zipfile.ZipFile(self.target, 'r') as z: z.setpassword(password) - return z.namelist() + self.files = z.namelist() + return self.files def verify(self, password=None): @@ -63,6 +64,8 @@ class UnZip(Extractor): with zipfile.ZipFile(self.target, 'r') as z: z.setpassword(password) z.extractall(self.dest) + self.files = z.namelist() + return self.files except RuntimeError, e: raise ArchiveError(e) -- cgit v1.2.3 From 1552f73ab2a59c17344604396443fb7a5f370f71 Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 10 Jun 2016 08:20:32 +0200 Subject: Fix forget archive.items in favor of chunks --- module/plugins/hooks/ExtractArchive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index b9e6842cf..690abab25 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -330,7 +330,7 @@ class ExtractArchive(Addon): #: Remove processed file and related multiparts from list files_ids = [(fid, fname, fout) for fid, fname, fout in files_ids \ - if fname not in archive.items()] + if fname not in archive.chunks()] self.log_debug("Extracted files: %s" % new_files) for filename in new_files: -- cgit v1.2.3 From 78e1af94a999dc007f80749cf550654c8f625a23 Mon Sep 17 00:00:00 2001 From: Olivier Date: Sat, 11 Jun 2016 21:09:29 +0200 Subject: Increment version number --- module/plugins/hooks/ExtractArchive.py | 4 ++-- module/plugins/internal/Extractor.py | 2 +- module/plugins/internal/UnRar.py | 2 +- module/plugins/internal/UnTar.py | 2 +- module/plugins/internal/UnZip.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 690abab25..fed9a62b9 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -98,8 +98,8 @@ class ArchiveQueue(object): class ExtractArchive(Addon): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "1.57" - __status__ = "broken" + __version__ = "1.58" + __status__ = "testing" __config__ = [("activated" , "bool" , "Activated" , True ), ("fullpath" , "bool" , "Extract with full paths" , True ), diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index 3c9af376a..a912843a1 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -23,7 +23,7 @@ class PasswordError(Exception): class Extractor(Plugin): __name__ = "Extractor" __type__ = "extractor" - __version__ = "0.42" + __version__ = "0.43" __status__ = "stable" __description__ = """Base extractor plugin""" diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 1d2e79d58..e22120e94 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -12,7 +12,7 @@ from module.plugins.internal.misc import decode, encode, fsjoin, renice class UnRar(Extractor): __name__ = "UnRar" __type__ = "extractor" - __version__ = "1.31" + __version__ = "1.32" __status__ = "testing" __description__ = """RAR extractor plugin""" diff --git a/module/plugins/internal/UnTar.py b/module/plugins/internal/UnTar.py index 4e498c223..13a233634 100644 --- a/module/plugins/internal/UnTar.py +++ b/module/plugins/internal/UnTar.py @@ -12,7 +12,7 @@ from module.plugins.internal.misc import encode class UnTar(Extractor): __name__ = "UnTar" __type__ = "extractor" - __version__ = "0.01" + __version__ = "0.02" __status__ = "stable" __description__ = """TAR extractor plugin""" diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 2870dc4eb..4a05ea155 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -12,7 +12,7 @@ from module.plugins.internal.misc import encode class UnZip(Extractor): __name__ = "UnZip" __type__ = "extractor" - __version__ = "1.21" + __version__ = "1.22" __status__ = "stable" __description__ = """ZIP extractor plugin""" -- cgit v1.2.3 From 9049742ba685fba578eb7e63bfea39c318bdc2b2 Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 15 Jun 2016 08:31:10 +0200 Subject: UnRar FIX file exclusion not working --- module/plugins/internal/UnRar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index e22120e94..18416a4fe 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -209,7 +209,7 @@ class UnRar(Extractor): args.append("-or") for word in self.excludefiles: - args.append("-x'%s'" % word.strip()) + args.append("-x%s" % word.strip()) #: Assume yes on all queries args.append("-y") -- cgit v1.2.3