diff options
Diffstat (limited to 'module/plugins/internal/Extractor.py')
| -rw-r--r-- | module/plugins/internal/Extractor.py | 99 | 
1 files changed, 44 insertions, 55 deletions
diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index 0b2462dac..ddf0f8a85 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -1,5 +1,11 @@  # -*- coding: utf-8 -*- +import os + +from module.PyFile import PyFile +from module.utils import fs_encode + +  class ArchiveError(Exception):      pass @@ -14,7 +20,7 @@ class PasswordError(Exception):  class Extractor:      __name__    = "Extractor" -    __version__ = "0.13" +    __version__ = "0.15"      __description__ = """Base extractor plugin"""      __license__     = "GPLv3" @@ -26,6 +32,12 @@ class Extractor:      @classmethod +    def isArchive(cls, filename): +        name = os.path.basename(filename).lower() +        return any(name.endswith(ext) for ext in cls.EXTENSIONS) + + +    @classmethod      def checkDeps(cls):          """ Check if system statisfy dependencies          :return: boolean @@ -34,46 +46,36 @@ class Extractor:      @classmethod -    def isArchive(cls, file): -        raise NotImplementedError - - -    @classmethod      def getTargets(cls, files_ids):          """ Filter suited targets from list of filename id tuple list          :param files_ids: List of filepathes          :return: List of targets, id tuple list          """ -        targets = [] - -        for file, id in files_ids: -            if cls.isArchive(file): -                targets.append((file, id)) - -        return targets - +        raise NotImplementedError -    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 -        self.out          = out -        self.password     = password -        self.fullpath     = fullpath -        self.overwrite    = overwrite -        self.excludefiles = excludefiles -        self.renice       = renice -        self.delete       = delete -        self.keepbroken   = keepbroken -        self.files        = []  #: Store extracted files here +    def __init__(self, manager, filename, out, +                 fullpath=True, +                 overwrite=False, +                 excludefiles=[], +                 renice=0, +                 delete=False, +                 keepbroken=False, +                 fid=None): +        """ Initialize extractor for specific file """ +        self.manager        = manager +        self.target         = fs_encode(filename) +        self.out            = out +        self.fullpath       = fullpath +        self.overwrite      = overwrite +        self.excludefiles   = excludefiles +        self.renice         = renice +        self.delete         = delete +        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): @@ -81,44 +83,31 @@ class Extractor:          pass -    def verify(self): +    def checkArchive(self):          """Check if password if needed. Raise ArchiveError if integrity is          questionable. +        :return: boolean          :raises ArchiveError          """ -        pass +        return False -    def isPassword(self, password): +    def checkPassword(self, password):          """ Check if the given password is/might be correct.          If it can not be decided at this point return true.          :param password:          :return: boolean          """ -        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 - - -    def repair(self): -        return False +        return True -    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,7 +121,7 @@ class Extractor:          :return: List with paths of files to delete          """ -        raise NotImplementedError +        return [self.target]      def getExtractedFiles(self):  | 
