diff options
author | Walter Purcaro <vuolter@gmail.com> | 2015-01-31 23:19:30 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2015-01-31 23:19:30 +0100 |
commit | 7368881d2ba95cca3f47afbb0f4ef5861f2774df (patch) | |
tree | 9e34209590c03e1bb5c5897840f7250b113d9192 /module/plugins/internal | |
parent | Spare code cosmetics (diff) | |
download | pyload-7368881d2ba95cca3f47afbb0f4ef5861f2774df.tar.xz |
Extractor final fixup
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/Extractor.py | 2 | ||||
-rw-r--r-- | module/plugins/internal/SevenZip.py | 23 | ||||
-rw-r--r-- | module/plugins/internal/UnRar.py | 23 | ||||
-rw-r--r-- | module/plugins/internal/UnZip.py | 12 |
4 files changed, 26 insertions, 34 deletions
diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index 4c38760f2..719dc613c 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -50,7 +50,7 @@ class Extractor: :param files_ids: List of filepathes :return: List of targets, id tuple list """ - raise NotImplementedError + return [(fname, id) for fname, id in files_ids if cls.isArchive(fname)] def __init__(self, manager, filename, out, diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py index 476348083..126958829 100644 --- a/module/plugins/internal/SevenZip.py +++ b/module/plugins/internal/SevenZip.py @@ -52,16 +52,16 @@ class SevenZip(UnRar): file = fs_encode(self.filename) p = self.call_cmd("t", file) - p.communicate() + out, err = p.communicate() if p.returncode > 1: - raise CRCError + raise CRCError(err) p = self.call_cmd("l", "-slt", file) out, err = p.communicate() if p.returncode > 1: - raise ArchiveError("Process terminated") + raise ArchiveError(_("Process return code: %d") % p.returncode) # check if output or error macthes the 'wrong password'-Regexp if self.re_wrongpwd.search(out): @@ -69,12 +69,7 @@ class SevenZip(UnRar): # check if output matches 'Encrypted = +' if self.re_wrongcrc.search(out): - raise CRCError - - # check if archive is empty - self.files = self.list() - if not self.files: - raise ArchiveError("Empty Archive") + raise CRCError(_("Header protected")) def isPassword(self, password): @@ -118,13 +113,13 @@ class SevenZip(UnRar): raise PasswordError elif self.re_wrongcrc.search(err): - raise CRCError + raise CRCError(err) elif err.strip(): #: raise error if anything is on stderr - raise ArchiveError(err.strip()) + raise ArchiveError(err) if p.returncode > 1: - raise ArchiveError("Process terminated") + raise ArchiveError(_("Process return code: %d") % p.returncode) if not self.files: self.files = self.list(password) @@ -137,10 +132,10 @@ class SevenZip(UnRar): out, err = p.communicate() if "Can not open" in err: - raise ArchiveError("Cannot open file") + raise ArchiveError(_("Cannot open file")) if p.returncode > 1: - raise ArchiveError("Process terminated unsuccessful") + raise ArchiveError(_("Process return code: %d") % p.returncode) result = set() for groups in self.re_filelist.findall(out): diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index f92a2ddd4..fbb1c6a3e 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -71,7 +71,7 @@ class UnRar(Extractor): if not cls.isArchive(fname): continue - m = cls.re_rarpart1.match(fname) + m = cls.re_rarpart1.search(fname) if not m or int(m.group(1)) == 1: #@NOTE: only add first part file targets.append((fname, id)) @@ -86,17 +86,13 @@ class UnRar(Extractor): raise PasswordError if self.re_wrongcrc.search(err): - raise CRCError + raise CRCError(err) # output only used to check if passworded files are present for attr in self.re_filelist.findall(out): if attr[0].startswith("*"): raise PasswordError - self.files = self.list() - if not self.files: - raise ArchiveError("Empty Archive") - def isPassword(self, password): # at this point we can only verify header protected files @@ -158,13 +154,13 @@ class UnRar(Extractor): raise PasswordError elif self.re_wrongcrc.search(err): - raise CRCError + raise CRCError(err) elif err.strip(): #: raise error if anything is on stderr - raise ArchiveError(err.strip()) + raise ArchiveError(err) if p.returncode: - raise ArchiveError("Process terminated") + raise ArchiveError(_("Process return code: %d") % p.returncode) if not self.files: self.files = self.list(password) @@ -176,8 +172,11 @@ class UnRar(Extractor): for i in (1, 2): try: dir, name = os.path.split(self.filename) - part = self.getattr(self, "re_rarpart%d" % i).match(name).group(1) - file = fs_encode(os.path.join(dir, name.replace(part, '*', 1))) + + part = self.getattr(self, "re_rarpart%d" % i).search(name).group(1) + new_name = name[::-1].replace((".part%s.rar" % part)[::-1], ".part*.rar"[::-1], 1)[::-1] + file = fs_encode(os.path.join(dir, new_name) + files.extend(glob(file)) except Exception: @@ -196,7 +195,7 @@ class UnRar(Extractor): out, err = p.communicate() if "Cannot open" in err: - raise ArchiveError("Cannot open file") + raise ArchiveError(_("Cannot open file")) if err.strip(): #: only log error at this point self.manager.logError(err.strip()) diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 83ed3a233..2ab9597ef 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -27,20 +27,18 @@ class UnZip(Extractor): return sys.version_info[:2] >= (2, 6) - @classmethod - def getTargets(cls, files_ids): - return [(fname, id) for fname, id in files_ids if cls.isArchive(fname)] - - def extract(self, password=None): try: with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z: z.setpassword(self.password) - if not z.testzip(): + + badfile = z.testzip(): + + if not badfile: z.extractall(self.out) self.files = z.namelist() else: - raise CRCError + raise CRCError(badfile) except (BadZipfile, LargeZipFile), e: raise ArchiveError(e) |