diff options
Diffstat (limited to 'module/plugins/internal/SevenZip.py')
-rw-r--r-- | module/plugins/internal/SevenZip.py | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py index 624f6c939..5811c28de 100644 --- a/module/plugins/internal/SevenZip.py +++ b/module/plugins/internal/SevenZip.py @@ -5,12 +5,13 @@ import re import subprocess from module.plugins.internal.UnRar import ArchiveError, CRCError, PasswordError, UnRar, renice -from module.utils import fs_encode, save_join +from module.utils import fs_encode, save_join as fs_join class SevenZip(UnRar): __name__ = "SevenZip" - __version__ = "0.11" + __version__ = "0.14" + __status__ = "testing" __description__ = """7-Zip extractor plugin""" __license__ = "GPLv3" @@ -18,9 +19,7 @@ class SevenZip(UnRar): ("Walter Purcaro", "vuolter@gmail.com")] - CMD = "7z" - VERSION = "" - + CMD = "7z" EXTENSIONS = [".7z", ".xz", ".zip", ".gz", ".gzip", ".tgz", ".bz2", ".bzip2", ".tbz2", ".tbz", ".tar", ".wim", ".swm", ".lzma", ".rar", ".cab", ".arj", ".z", ".taz", ".cpio", ".rpm", ".deb", ".lzh", ".lha", @@ -37,23 +36,27 @@ class SevenZip(UnRar): @classmethod - def isUsable(cls): - if os.name == "nt": - cls.CMD = os.path.join(pypath, "7z.exe") - p = subprocess.Popen([cls.CMD], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() - else: + def find(cls): + try: + if os.name == "nt": + cls.CMD = os.path.join(pypath, "7z.exe") + p = subprocess.Popen([cls.CMD], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - m = cls.re_version.search(out) - cls.VERSION = m.group(1) if m else '(version unknown)' + except OSError: + return False + + else: + m = cls.re_version.search(out) + if m is not None: + cls.VERSION = m.group(1) - return True + return True def verify(self, password): - # 7z can't distinguish crc and pw error in test + #: 7z can't distinguish crc and pw error in test p = self.call_cmd("l", "-slt", fs_encode(self.filename)) out, err = p.communicate() @@ -72,7 +75,7 @@ class SevenZip(UnRar): p = self.call_cmd("l", "-slt", fs_encode(self.filename)) out, err = p.communicate() - # check if output or error macthes the 'wrong password'-Regexp + #: Check if output or error macthes the 'wrong password'-Regexp if self.re_wrongpwd.search(out): raise PasswordError @@ -91,7 +94,7 @@ class SevenZip(UnRar): renice(p.pid, self.renice) - # communicate and retrieve stderr + #: Communicate and retrieve stderr self._progress(p) err = p.stderr.read().strip() @@ -102,7 +105,7 @@ class SevenZip(UnRar): elif self.re_wrongcrc.search(err): raise CRCError(err) - else: #: raise error if anything is on stderr + else: #: Raise error if anything is on stderr raise ArchiveError(err) if p.returncode > 1: @@ -126,7 +129,7 @@ class SevenZip(UnRar): result = set() for groups in self.re_filelist.findall(out): f = groups[-1].strip() - result.add(save_join(self.out, f)) + result.add(fs_join(self.out, f)) return list(result) @@ -134,20 +137,20 @@ class SevenZip(UnRar): def call_cmd(self, command, *xargs, **kwargs): args = [] - #overwrite flag + #: Overwrite flag if self.overwrite: args.append("-y") - #set a password - if "password" in kwargs and kwargs["password"]: - args.append("-p%s" % kwargs["password"]) + #: Set a password + if "password" in kwargs and kwargs['password']: + args.append("-p%s" % kwargs['password']) else: args.append("-p-") #@NOTE: return codes are not reliable, some kind of threading, cleanup whatever issue call = [self.CMD, command] + args + list(xargs) - self.manager.logDebug(" ".join(call)) + self.log_debug(" ".join(call)) p = subprocess.Popen(call, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return p |