From f2e066dbdbb1b6598cc9f7b3069650d7ce966739 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 14 Dec 2015 02:47:50 +0100 Subject: New extractor: UnTar --- module/plugins/internal/UnTar.py | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 module/plugins/internal/UnTar.py (limited to 'module') diff --git a/module/plugins/internal/UnTar.py b/module/plugins/internal/UnTar.py new file mode 100644 index 000000000..f2a140ca7 --- /dev/null +++ b/module/plugins/internal/UnTar.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +from __future__ import with_statement + +import sys +import tarfile + +from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError +from module.plugins.internal.misc import encode + + +class UnTar(Extractor): + __name__ = "UnTar" + __type__ = "extractor" + __version__ = "0.01" + __status__ = "stable" + + __description__ = """TAR extractor plugin""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + VERSION = "%s.%s.%s" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]) + + + @classmethod + def isarchive(cls, filename): + return tarfile.is_tarfile(encode(filename)) + + + @classmethod + def find(cls): + return sys.version_info[:2] >= (2, 5) + + + def list(self, password=None): + with tarfile.open(self.target) as t: + return t.getnames() + + + def verify(self, password=None): + try: + t = tarfile.open(self.target, errorlevel=1) + + except tarfile.CompressionError, e: + raise CRCError(e) + + except (OSError, tarfile.TarError), e: + raise ArchiveError(e) + + else: + t.close() + + + def extract(self, password=None): + self.verify() + + try: + with tarfile.open(self.target, errorlevel=2) as t: + t.extractall(self.dest) + + except tarfile.ExtractError, e: + self.log_warning(e) + + except tarfile.CompressionError, e: + raise CRCError(e) + + except (OSError, tarfile.TarError), e: + raise ArchiveError(e) -- cgit v1.2.3