diff options
Diffstat (limited to 'module/plugins/internal/Extractor.py')
-rw-r--r-- | module/plugins/internal/Extractor.py | 118 |
1 files changed, 64 insertions, 54 deletions
diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index 0b2462dac..1a98060d9 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -1,5 +1,11 @@ # -*- coding: utf-8 -*- +import os +import re + +from module.PyFile import PyFile + + class ArchiveError(Exception): pass @@ -14,28 +20,36 @@ class PasswordError(Exception): class Extractor: __name__ = "Extractor" - __version__ = "0.13" + __version__ = "0.24" __description__ = """Base extractor plugin""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "ranan@pyload.org"), - ("Walter Purcaro", "vuolter@gmail.com")] + __authors__ = [("Walter Purcaro", "vuolter@gmail.com"), + ("Immenz" , "immenz@gmx.net" )] EXTENSIONS = [] + REPAIR = False + VERSION = "" @classmethod - def checkDeps(cls): - """ Check if system statisfy dependencies - :return: boolean - """ - return True + def isArchive(cls, filename): + name = os.path.basename(filename).lower() + return any(name.endswith(ext) for ext in cls.EXTENSIONS) @classmethod - def isArchive(cls, file): - raise NotImplementedError + def isMultipart(cls, filename): + return False + + + @classmethod + def isUsable(cls): + """ Check if system statisfy dependencies + :return: boolean + """ + return None @classmethod @@ -45,28 +59,29 @@ class Extractor: :return: List of targets, id tuple list """ targets = [] - - for file, id in files_ids: - if cls.isArchive(file): - targets.append((file, id)) - + processed = [] + + for fname, id, fout in files_ids: + if cls.isArchive(fname): + pname = re.sub(cls.re_multipart, '', fname) if cls.isMultipart(fname) else os.path.splitext(fname)[0] + if pname not in processed: + processed.append(pname) + targets.append((fname, id, fout)) return targets - def __init__(self, m, file, out, password, fullpath, overwrite, excludefiles, renice, delete, keepbroken): - """Initialize extractor for specific file - - :param m: ExtractArchive Hook plugin - :param file: Absolute filepath - :param out: Absolute path to destination directory - :param fullpath: extract to fullpath - :param overwrite: Overwrite existing archives - :param renice: Renice value - """ - self.m = m - self.file = file + def __init__(self, manager, filename, out, + fullpath=True, + overwrite=False, + excludefiles=[], + renice=0, + delete='No', + keepbroken=False, + fid=None): + """ Initialize extractor for specific file """ + self.manager = manager + self.filename = filename self.out = out - self.password = password self.fullpath = fullpath self.overwrite = overwrite self.excludefiles = excludefiles @@ -75,50 +90,45 @@ class Extractor: self.keepbroken = keepbroken self.files = [] #: Store extracted files here + pyfile = self.manager.core.files.getFile(fid) if fid else None + self.notifyProgress = lambda x: pyfile.setProgress(x) if pyfile else lambda x: None + def init(self): """ Initialize additional data structures """ pass - def verify(self): - """Check if password if needed. Raise ArchiveError if integrity is - questionable. + def check(self): + """Quick Check by listing content of archive. + Raises error if password is needed, integrity is questionable or else. + :raises PasswordError + :raises CRCError :raises ArchiveError """ - pass - + raise NotImplementedError - def isPassword(self, password): - """ Check if the given password is/might be correct. - If it can not be decided at this point return true. + def verify(self): + """Testing with Extractors buildt-in method + Raises error if password is needed, integrity is questionable or else. - :param password: - :return: boolean + :raises PasswordError + :raises CRCError + :raises ArchiveError """ - if isinstance(password, basestring): - return True - else: - return False - - - def setPassword(self, password): - if self.isPassword(password): - self.password = password - return True - else: - return False + raise NotImplementedError def repair(self): - return False + return None - def extract(self, progress=lambda x: None): + def extract(self, password=None): """Extract the archive. Raise specific errors in case of failure. :param progress: Progress function, call this to update status + :param password password to use :raises PasswordError :raises CRCError :raises ArchiveError @@ -132,9 +142,9 @@ class Extractor: :return: List with paths of files to delete """ - raise NotImplementedError + return [self.filename] - def getExtractedFiles(self): + def list(self, password=None): """Populate self.files at some point while extracting""" return self.files |