diff options
-rw-r--r-- | module/plugins/hooks/ExtractArchive.py | 37 | ||||
-rw-r--r-- | module/plugins/internal/Extractor.py | 2 | ||||
-rw-r--r-- | module/plugins/internal/SevenZip.py | 14 | ||||
-rw-r--r-- | module/plugins/internal/UnRar.py | 18 | ||||
-rw-r--r-- | module/plugins/internal/UnZip.py | 7 |
5 files changed, 41 insertions, 37 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index c9e43eaaf..6a25602e8 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -33,6 +33,7 @@ if sys.version_info < (2, 7) and os.name != "nt": if self.returncode is None: try: pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0) + except OSError, e: if e.errno != errno.ECHILD: raise @@ -93,10 +94,13 @@ class ArchiveQueue(object): queue = self.get() try: queue.remove(item) + except ValueError: pass + if queue == []: return self.delete() + return self.set(queue) @@ -106,22 +110,22 @@ class ExtractArchive(Hook): __type__ = "hook" __version__ = "1.32" - __config__ = [("activated" , "bool" , "Activated" , True ), - ("fullpath" , "bool" , "Extract with full paths" , True ), - ("overwrite" , "bool" , "Overwrite files" , False ), - ("keepbroken" , "bool" , "Try to extract broken archives" , False ), - ("repair" , "bool" , "Repair broken archives (rar required)" , False ), - ("test" , "bool" , "Test archive before extracting" , False ), - ("usepasswordfile" , "bool" , "Use password file" , True ), - ("passwordfile" , "file" , "Password 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 folder" , "" ), - ("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 ), - ("waitall" , "bool" , "Wait for all downloads to be finished" , False ), - ("renice" , "int" , "CPU priority" , 0 )] + __config__ = [("activated" , "bool" , "Activated" , True ), + ("fullpath" , "bool" , "Extract with full paths" , True ), + ("overwrite" , "bool" , "Overwrite files" , False ), + ("keepbroken" , "bool" , "Try to extract broken archives" , False ), + ("repair" , "bool" , "Repair broken archives (rar required)" , False ), + ("test" , "bool" , "Test archive before extracting" , False ), + ("usepasswordfile", "bool" , "Use password file" , True ), + ("passwordfile" , "file" , "Password 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 folder" , "" ), + ("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 ), + ("waitall" , "bool" , "Wait for all downloads to be finished" , False ), + ("renice" , "int" , "CPU priority" , 0 )] __description__ = """Extract different kind of archives""" __license__ = "GPLv3" @@ -175,6 +179,7 @@ class ExtractArchive(Hook): else: self.logInfo(_("No Extract plugins activated")) + @threaded def extractQueued(self,thread): packages = self.queue.get() diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index ee62ebcb7..bc8e67c6d 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -3,6 +3,7 @@ import os from module.PyFile import PyFile +from module.utils import fs_encode class ArchiveError(Exception): @@ -71,6 +72,7 @@ class Extractor: fid=None): """ Initialize extractor for specific file """ self.manager = manager + self.target = "'%s'" % fs_encode(filename) self.filename = filename self.out = out self.fullpath = fullpath diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py index a3df52559..5280338dc 100644 --- a/module/plugins/internal/SevenZip.py +++ b/module/plugins/internal/SevenZip.py @@ -6,7 +6,7 @@ import re from subprocess import Popen, PIPE from module.plugins.internal.UnRar import ArchiveError, CRCError, PasswordError, UnRar, renice -from module.utils import fs_encode, save_join +from module.utils import save_join class SevenZip(UnRar): @@ -54,10 +54,8 @@ class SevenZip(UnRar): def test(self, password): - file = fs_encode(self.filename) - # 7z can't distinguish crc and pw error in test - p = self.call_cmd("l", "-slt", file) + p = self.call_cmd("l", "-slt", self.target) out, err = p.communicate() if self.re_wrongpwd.search(out): @@ -72,9 +70,7 @@ class SevenZip(UnRar): def check(self, password): - file = fs_encode(self.filename) - - p = self.call_cmd("l", "-slt", file) + p = self.call_cmd("l", "-slt", self.target) out, err = p.communicate() # check if output or error macthes the 'wrong password'-Regexp @@ -92,7 +88,7 @@ class SevenZip(UnRar): def extract(self, password=None): command = "x" if self.fullpath else "e" - p = self.call_cmd(command, '-o' + self.out, fs_encode(self.filename), password=password) + p = self.call_cmd(command, '-o' + self.out, self.target, password=password) renice(p.pid, self.renice) @@ -119,7 +115,7 @@ class SevenZip(UnRar): def list(self, password=None): command = "l" if self.fullpath else "l" - p = self.call_cmd(command, fs_encode(self.filename), password=password) + p = self.call_cmd(command, self.target, password=password) out, err = p.communicate() if "Can not open" in err: diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index eb969bb60..188fc88bb 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -8,7 +8,7 @@ from string import digits from subprocess import Popen, PIPE from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -from module.utils import decode, fs_encode, save_join +from module.utils import fs_decode, save_join def renice(pid, value): @@ -56,6 +56,7 @@ class UnRar(Extractor): out, err = p.communicate() cls.__name__ = "RAR" cls.REPAIR = True + except OSError: cls.CMD = os.path.join(pypath, "UnRAR.exe") p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) @@ -66,6 +67,7 @@ class UnRar(Extractor): out, err = p.communicate() cls.__name__ = "RAR" cls.REPAIR = True + except OSError: #: fallback to unrar p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) out, err = p.communicate() @@ -87,7 +89,7 @@ class UnRar(Extractor): def test(self, password): - p = self.call_cmd("t", "-v", fs_encode(self.filename), password=password) + p = self.call_cmd("t", "-v", self.target, password=password) self._progress(p) err = p.stderr.read().strip() @@ -99,7 +101,7 @@ class UnRar(Extractor): def check(self, password): - p = self.call_cmd("l", "-v", fs_encode(self.filename), password=password) + p = self.call_cmd("l", "-v", self.target, password=password) out, err = p.communicate() if self.re_wrongpwd.search(err): @@ -115,7 +117,7 @@ class UnRar(Extractor): def repair(self): - p = self.call_cmd("rc", fs_encode(self.filename)) + p = self.call_cmd("rc", self.target) # communicate and retrieve stderr self._progress(p) @@ -147,7 +149,7 @@ class UnRar(Extractor): def extract(self, password=None): command = "x" if self.fullpath else "e" - p = self.call_cmd(command, fs_encode(self.filename), self.out, password=password) + p = self.call_cmd(command, self.target, self.out, password=password) renice(p.pid, self.renice) @@ -187,7 +189,7 @@ class UnRar(Extractor): def list(self, password=None): command = "vb" if self.fullpath else "lb" - p = self.call_cmd(command, "-v", fs_encode(self.filename), password=password) + p = self.call_cmd(command, "-v", self.target, password=password) out, err = p.communicate() if "Cannot open" in err: @@ -199,12 +201,12 @@ class UnRar(Extractor): result = set() if not self.fullpath and self.VERSION.startswith('5'): # NOTE: Unrar 5 always list full path - for f in decode(out).splitlines(): + for f in fs_decode(out).splitlines(): f = save_join(self.out, os.path.basename(f.strip())) if os.path.isfile(f): result.add(save_join(self.out, os.path.basename(f))) else: - for f in decode(out).splitlines(): + for f in fs_decode(out).splitlines(): f = f.strip() result.add(save_join(self.out, f)) diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index d95afbc70..dd57a54a7 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -7,7 +7,6 @@ import sys import zipfile from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -from module.utils import fs_encode class UnZip(Extractor): @@ -29,7 +28,7 @@ class UnZip(Extractor): def list(self, password=None): - with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z: + with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z: z.setpassword(password) return z.namelist() @@ -39,7 +38,7 @@ class UnZip(Extractor): def test(self): - with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z: + with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z: badfile = z.testzip() if badfile: @@ -50,7 +49,7 @@ class UnZip(Extractor): def extract(self, password=None): try: - with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z: + with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z: z.setpassword(password) badfile = z.testzip() |