diff options
| author | jvoisin | 2011-06-27 16:52:11 +0200 |
|---|---|---|
| committer | jvoisin | 2011-06-27 16:52:11 +0200 |
| commit | 7c05c4edef20cc7438a8a90f2e9f1b507e82c132 (patch) | |
| tree | da6dd5fcd682ddef7ebeba73e32c668c56a6c09d /lib | |
| parent | d39caff87bab6d86da10781f2d70066058876872 (diff) | |
Add support for tar.bz2 and tar.gz archives
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/archive.py | 17 | ||||
| -rw-r--r-- | lib/mat.py | 4 |
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/archive.py b/lib/archive.py index f7649d5..89425cf 100644 --- a/lib/archive.py +++ b/lib/archive.py | |||
| @@ -5,13 +5,18 @@ import mat | |||
| 5 | import shutil | 5 | import shutil |
| 6 | 6 | ||
| 7 | class TarStripper(parser.Generic_parser): | 7 | class TarStripper(parser.Generic_parser): |
| 8 | def compression_type(self): | ||
| 9 | self.compression = '' | ||
| 10 | |||
| 8 | def remove_all(self): | 11 | def remove_all(self): |
| 12 | self.compression_type() | ||
| 9 | if not tarfile.is_tarfile(self.filename): | 13 | if not tarfile.is_tarfile(self.filename): |
| 10 | print('%s is not a valid tar file' % self.filename) | 14 | print('%s is not a valid tar file' % self.filename) |
| 11 | sys.exit(1) | 15 | sys.exit(1) |
| 12 | 16 | ||
| 13 | tarin = tarfile.open(self.filename, 'r') | 17 | tarin = tarfile.open(self.filename, 'r' + self.compression) |
| 14 | tarout = tarfile.open(self.filename + parser.POSTFIX, 'w') | 18 | tarout = tarfile.open(self.filename + parser.POSTFIX, |
| 19 | 'w' + self.compression) | ||
| 15 | folder_list = [] | 20 | folder_list = [] |
| 16 | 21 | ||
| 17 | for current_file in tarin.getmembers(): | 22 | for current_file in tarin.getmembers(): |
| @@ -36,3 +41,11 @@ class TarStripper(parser.Generic_parser): | |||
| 36 | 41 | ||
| 37 | def is_clean(self): | 42 | def is_clean(self): |
| 38 | return False | 43 | return False |
| 44 | |||
| 45 | class GzipStripper(TarStripper): | ||
| 46 | def compression_type(self): | ||
| 47 | self.compression = ':gz' | ||
| 48 | |||
| 49 | class Bzip2Stripper(TarStripper): | ||
| 50 | def compression_type(self): | ||
| 51 | self.compression = ':bz2' | ||
| @@ -25,6 +25,8 @@ strippers = { | |||
| 25 | hachoir_parser.audio.MpegAudioFile: audio.MpegAudioStripper, | 25 | hachoir_parser.audio.MpegAudioFile: audio.MpegAudioStripper, |
| 26 | hachoir_parser.misc.PDFDocument: misc.PdfStripper, | 26 | hachoir_parser.misc.PDFDocument: misc.PdfStripper, |
| 27 | hachoir_parser.archive.TarFile: archive.TarStripper, | 27 | hachoir_parser.archive.TarFile: archive.TarStripper, |
| 28 | hachoir_parser.archive.gzip_parser.GzipParser: archive.GzipStripper, | ||
| 29 | hachoir_parser.archive.bzip2_parser.Bzip2Parser: archive.Bzip2Stripper, | ||
| 28 | } | 30 | } |
| 29 | 31 | ||
| 30 | def is_secure(filename): | 32 | def is_secure(filename): |
| @@ -33,7 +35,7 @@ def is_secure(filename): | |||
| 33 | ''' | 35 | ''' |
| 34 | 36 | ||
| 35 | if not(os.path.isfile(filename)): #check if the file exist | 37 | if not(os.path.isfile(filename)): #check if the file exist |
| 36 | print("Error: %s is not a valid file" % name) | 38 | print("Error: %s is not a valid file" % filename) |
| 37 | sys.exit(1) | 39 | sys.exit(1) |
| 38 | 40 | ||
| 39 | def create_class_file(name, backup): | 41 | def create_class_file(name, backup): |
