diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-14 02:47:50 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 20:50:05 +0100 |
commit | f2e066dbdbb1b6598cc9f7b3069650d7ce966739 (patch) | |
tree | bb6192e16070eb81f9f8615b6a4f20a5ea58afb2 /module/plugins/internal | |
parent | Merge pull request #2223 from GammaC0de/safe_format (diff) | |
download | pyload-f2e066dbdbb1b6598cc9f7b3069650d7ce966739.tar.xz |
New extractor: UnTar
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/UnTar.py | 69 |
1 files changed, 69 insertions, 0 deletions
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) |