From 9ebc62273ec8abfc4520660597fa80fe3de40203 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 24 Jun 2011 19:41:51 +0200 Subject: Preliminary support of .tar archives --- lib/archive.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'lib/archive.py') diff --git a/lib/archive.py b/lib/archive.py index 6378cab..c8203c9 100644 --- a/lib/archive.py +++ b/lib/archive.py @@ -1,6 +1,33 @@ +import tarfile +import sys import parser +import mat class TarStripper(parser.Generic_parser): def remove_all(self): - for file in self.editor.array("file"): - print file.name + if not tarfile.is_tarfile(self.filename): + print('%s is not a valid tar file' % self.filename) + sys.exit(1) + + tarin = tarfile.open(self.filename, 'r') + tarout = tarfile.open(self.filename + parser.POSTFIX, 'w') + + for current_file in tarin.getmembers(): + tarin.extract(current_file) + if current_file.type is '0': #is current_file a regular file ? + #no backup file + class_file = mat.create_class_file(current_file.name, False) + class_file.remove_all() + tarout.add(current_file.name) + + #meta from the tar itself + tarout.mtime = None + + tarout.close() + tarin.close() + + def is_clean(self): + return False + + + -- cgit v1.3