From 4c63928557398891c30d3e2b7c962a07b3483315 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 26 Dec 2014 04:18:41 +0100 Subject: Rename AbstractExtractor to Extractor --- module/plugins/hooks/ExtractArchive.py | 4 +- module/plugins/internal/AbstractExtractor.py | 141 --------------------------- module/plugins/internal/Extractor.py | 140 ++++++++++++++++++++++++++ module/plugins/internal/UnRar.py | 6 +- module/plugins/internal/UnZip.py | 6 +- 5 files changed, 148 insertions(+), 149 deletions(-) delete mode 100644 module/plugins/internal/AbstractExtractor.py create mode 100644 module/plugins/internal/Extractor.py (limited to 'module/plugins') diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 8b3b4e310..af78ffc93 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -51,14 +51,14 @@ if os.name != "nt": from pwd import getpwnam from module.plugins.Hook import Hook, threaded, Expose -from module.plugins.internal.AbstractExtractor import ArchiveError, CRCError, PasswordError +from module.plugins.internal.Extractor import ArchiveError, CRCError, PasswordError from module.utils import save_join, uniqify class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "1.01" + __version__ = "1.02" __config__ = [("activated" , "bool" , "Activated" , True ), ("fullpath" , "bool" , "Extract full path" , True ), diff --git a/module/plugins/internal/AbstractExtractor.py b/module/plugins/internal/AbstractExtractor.py deleted file mode 100644 index 310897d4e..000000000 --- a/module/plugins/internal/AbstractExtractor.py +++ /dev/null @@ -1,141 +0,0 @@ -# -*- coding: utf-8 -*- - -class ArchiveError(Exception): - pass - - -class CRCError(Exception): - pass - - -class PasswordError(Exception): - pass - - -class AbtractExtractor: - __name__ = "AbtractExtractor" - __version__ = "0.12" - - __description__ = """Abtract extractor plugin""" - __license__ = "GPLv3" - __authors__ = [("RaNaN", "ranan@pyload.org"), - ("Walter Purcaro", "vuolter@gmail.com")] - - - EXTENSIONS = [] - - - @classmethod - def checkDeps(cls): - """ Check if system statisfy dependencies - :return: boolean - """ - return True - - - @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 - - - 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): - """ Initialize additional data structures """ - pass - - - def verify(self): - """Check if password if needed. Raise ArchiveError if integrity is - questionable. - - :raises ArchiveError - """ - pass - - - def isPassword(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 - - - def extract(self, progress=lambda x: None): - """Extract the archive. Raise specific errors in case of failure. - - :param progress: Progress function, call this to update status - :raises PasswordError - :raises CRCError - :raises ArchiveError - :return: - """ - self.setPassword(password) - raise NotImplementedError - - - def getDeleteFiles(self): - """Return list of files to delete, do *not* delete them here. - - :return: List with paths of files to delete - """ - raise NotImplementedError - - - def getExtractedFiles(self): - """Populate self.files at some point while extracting""" - return self.files diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py new file mode 100644 index 000000000..0b2462dac --- /dev/null +++ b/module/plugins/internal/Extractor.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- + +class ArchiveError(Exception): + pass + + +class CRCError(Exception): + pass + + +class PasswordError(Exception): + pass + + +class Extractor: + __name__ = "Extractor" + __version__ = "0.13" + + __description__ = """Base extractor plugin""" + __license__ = "GPLv3" + __authors__ = [("RaNaN", "ranan@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] + + + EXTENSIONS = [] + + + @classmethod + def checkDeps(cls): + """ Check if system statisfy dependencies + :return: boolean + """ + return True + + + @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 + + + 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): + """ Initialize additional data structures """ + pass + + + def verify(self): + """Check if password if needed. Raise ArchiveError if integrity is + questionable. + + :raises ArchiveError + """ + pass + + + def isPassword(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 + + + def extract(self, progress=lambda x: None): + """Extract the archive. Raise specific errors in case of failure. + + :param progress: Progress function, call this to update status + :raises PasswordError + :raises CRCError + :raises ArchiveError + :return: + """ + raise NotImplementedError + + + def getDeleteFiles(self): + """Return list of files to delete, do *not* delete them here. + + :return: List with paths of files to delete + """ + raise NotImplementedError + + + def getExtractedFiles(self): + """Populate self.files at some point while extracting""" + return self.files diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index b70bf3257..572fe95b9 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -8,7 +8,7 @@ from os.path import basename, dirname, join from string import digits from subprocess import Popen, PIPE -from module.plugins.internal.AbstractExtractor import AbtractExtractor, ArchiveError, CRCError, PasswordError +from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError from module.utils import save_join, decode @@ -20,9 +20,9 @@ def renice(pid, value): print "Renice failed" -class UnRar(AbtractExtractor): +class UnRar(Extractor): __name__ = "UnRar" - __version__ = "1.00" + __version__ = "1.01" __description__ = """Rar extractor plugin""" __license__ = "GPLv3" diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 875a0ec09..5ec56cbdf 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -5,12 +5,12 @@ from __future__ import with_statement import sys import zipfile -from module.plugins.internal.AbstractExtractor import AbtractExtractor, ArchiveError, CRCError, PasswordError +from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -class UnZip(AbtractExtractor): +class UnZip(Extractor): __name__ = "UnZip" - __version__ = "1.00" + __version__ = "1.01" __description__ = """Zip extractor plugin""" __license__ = "GPLv3" -- cgit v1.2.3