summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/SevenZip.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/internal/SevenZip.py')
-rw-r--r--module/plugins/internal/SevenZip.py51
1 files changed, 24 insertions, 27 deletions
diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py
index bf33332ea..87a2fa433 100644
--- a/module/plugins/internal/SevenZip.py
+++ b/module/plugins/internal/SevenZip.py
@@ -5,13 +5,13 @@ import re
import subprocess
from module.plugins.internal.UnRar import UnRar, ArchiveError, CRCError, PasswordError
-from module.plugins.internal.utils import fs_join, renice
+from module.plugins.internal.misc import encode, fsjoin, renice
class SevenZip(UnRar):
__name__ = "SevenZip"
__type__ = "extractor"
- __version__ = "0.18"
+ __version__ = "0.19"
__status__ = "testing"
__description__ = """7-Zip extractor plugin"""
@@ -20,19 +20,18 @@ class SevenZip(UnRar):
("Michael Nowak" , None )]
- 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",
- ".chm", ".chw", ".hxs", ".iso", ".msi", ".doc", ".xls", ".ppt",
- ".dmg", ".xar", ".hfs", ".exe", ".ntfs", ".fat", ".vhd", ".mbr",
- ".squashfs", ".cramfs", ".scap"]
+ 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", "chm", "chw", "hxs",
+ "iso", "msi", "doc", "xls", "ppt", "dmg", "xar", "hfs", "exe",
+ "ntfs", "fat", "vhd", "mbr", "squashfs", "cramfs", "scap"]
#@NOTE: there are some more uncovered 7z formats
- re_filelist = re.compile(r'([\d\:]+)\s+([\d\:]+)\s+([\w\.]+)\s+(\d+)\s+(\d+)\s+(.+)')
- re_wrongpwd = re.compile(r'(Can not open encrypted archive|Wrong password|Encrypted\s+\=\s+\+)', re.I)
- re_wrongcrc = re.compile(r'CRC Failed|Can not open file', re.I)
- re_version = re.compile(r'7-Zip\s(?:\[64\]\s)?(\d+\.\d+)', re.I)
+ _RE_FILES = re.compile(r'([\d\:]+)\s+([\d\:]+)\s+([\w\.]+)\s+(\d+)\s+(\d+)\s+(.+)')
+ _RE_BADPWD = re.compile(r'(Can not open encrypted archive|Wrong password|Encrypted\s+\=\s+\+)', re.I)
+ _RE_BADCRC = re.compile(r'CRC Failed|Can not open file', re.I)
+ _RE_VERSION = re.compile(r'7-Zip\s(?:\[64\]\s)?(\d+\.\d+)', re.I)
@classmethod
@@ -48,7 +47,7 @@ class SevenZip(UnRar):
return False
else:
- m = cls.re_version.search(out)
+ m = cls._RE_VERSION.search(out)
if m is not None:
cls.VERSION = m.group(1)
@@ -60,33 +59,33 @@ class SevenZip(UnRar):
p = self.call_cmd("l", "-slt", self.target)
out, err = p.communicate()
- if self.re_wrongpwd.search(out):
+ if self._RE_BADPWD.search(out):
raise PasswordError
- elif self.re_wrongpwd.search(err):
+ elif self._RE_BADPWD.search(err):
raise PasswordError
- elif self.re_wrongcrc.search(out):
+ elif self._RE_BADCRC.search(out):
raise CRCError(_("Header protected"))
- elif self.re_wrongcrc.search(err):
+ elif self._RE_BADCRC.search(err):
raise CRCError(err)
def extract(self, password=None):
command = "x" if self.fullpath else "e"
- p = self.call_cmd(command, '-o' + self.out, self.target, password=password)
+ p = self.call_cmd(command, '-o' + self.dest, self.target, password=password)
#: Communicate and retrieve stderr
- self._progress(p)
+ self.progress(p)
err = p.stderr.read().strip()
if err:
- if self.re_wrongpwd.search(err):
+ if self._RE_BADPWD.search(err):
raise PasswordError
- elif self.re_wrongcrc.search(err):
+ elif self._RE_BADCRC.search(err):
raise CRCError(err)
else: #: Raise error if anything is on stderr
@@ -95,8 +94,6 @@ class SevenZip(UnRar):
if p.returncode > 1:
raise ArchiveError(_("Process return code: %d") % p.returncode)
- self.files = self.list(password)
-
def list(self, password=None):
command = "l" if self.fullpath else "l"
@@ -111,9 +108,9 @@ class SevenZip(UnRar):
raise ArchiveError(_("Process return code: %d") % p.returncode)
result = set()
- for groups in self.re_filelist.findall(out):
+ for groups in self._RE_FILES.findall(out):
f = groups[-1].strip()
- result.add(fs_join(self.out, f))
+ result.add(fsjoin(self.dest, f))
return list(result)
@@ -133,8 +130,8 @@ class SevenZip(UnRar):
#@NOTE: return codes are not reliable, some kind of threading, cleanup whatever issue
call = [self.CMD, command] + args + list(xargs)
-
self.log_debug(" ".join(call))
+ call = map(encode, call)
p = subprocess.Popen(call, stdout=subprocess.PIPE, stderr=subprocess.PIPE)