diff options
| author | jvoisin | 2011-07-25 03:03:12 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-25 03:03:12 +0200 |
| commit | 7bec354973580216c64889b925e1f7d6a224d7dd (patch) | |
| tree | 7ddf33ae6a1ffd5c9d03522ae508f67632f638cb /lib/archive.py | |
| parent | ac248b5b4979aafa0c05f8253e2f9e1bdba305e6 (diff) | |
more abstraction, and changed the name of the outputed file
Diffstat (limited to 'lib/archive.py')
| -rw-r--r-- | lib/archive.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/archive.py b/lib/archive.py index 8a305d5..21bc5c5 100644 --- a/lib/archive.py +++ b/lib/archive.py | |||
| @@ -83,7 +83,7 @@ class ZipStripper(GenericArchiveStripper): | |||
| 83 | 83 | ||
| 84 | def _remove_all(self, method): | 84 | def _remove_all(self, method): |
| 85 | zipin = zipfile.ZipFile(self.filename, 'r') | 85 | zipin = zipfile.ZipFile(self.filename, 'r') |
| 86 | zipout = zipfile.ZipFile(self.filename + parser.POSTFIX, 'w', | 86 | zipout = zipfile.ZipFile(self.output, 'w', |
| 87 | allowZip64=True) | 87 | allowZip64=True) |
| 88 | for item in zipin.infolist(): | 88 | for item in zipin.infolist(): |
| 89 | zipin.extract(item, self.tempdir) | 89 | zipin.extract(item, self.tempdir) |
| @@ -109,6 +109,7 @@ class ZipStripper(GenericArchiveStripper): | |||
| 109 | logging.info('%s treated' % self.filename) | 109 | logging.info('%s treated' % self.filename) |
| 110 | zipin.close() | 110 | zipin.close() |
| 111 | zipout.close() | 111 | zipout.close() |
| 112 | self.do_backup() | ||
| 112 | 113 | ||
| 113 | 114 | ||
| 114 | class TarStripper(GenericArchiveStripper): | 115 | class TarStripper(GenericArchiveStripper): |
| @@ -125,8 +126,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 125 | 126 | ||
| 126 | def _remove_all(self, method): | 127 | def _remove_all(self, method): |
| 127 | tarin = tarfile.open(self.filename, 'r' + self.compression) | 128 | tarin = tarfile.open(self.filename, 'r' + self.compression) |
| 128 | tarout = tarfile.open(self.filename + parser.POSTFIX, | 129 | tarout = tarfile.open(self.output, 'w' + self.compression) |
| 129 | 'w' + self.compression) | ||
| 130 | for item in tarin.getmembers(): | 130 | for item in tarin.getmembers(): |
| 131 | tarin.extract(item, self.tempdir) | 131 | tarin.extract(item, self.tempdir) |
| 132 | name = os.path.join(self.tempdir, item.name) | 132 | name = os.path.join(self.tempdir, item.name) |
| @@ -148,10 +148,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 148 | mat.secure_remove(name) | 148 | mat.secure_remove(name) |
| 149 | tarin.close() | 149 | tarin.close() |
| 150 | tarout.close() | 150 | tarout.close() |
| 151 | 151 | self.do_backup() | |
| 152 | if self.backup is False: | ||
| 153 | mat.secure_remove(self.filename) | ||
| 154 | os.rename(self.filename + parser.POSTFIX, self.filename) | ||
| 155 | 152 | ||
| 156 | def is_file_clean(self, current_file): | 153 | def is_file_clean(self, current_file): |
| 157 | ''' | 154 | ''' |
| @@ -179,8 +176,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 179 | name = os.path.join(self.tempdir, item.name) | 176 | name = os.path.join(self.tempdir, item.name) |
| 180 | if item.type is '0': #is item a regular file ? | 177 | if item.type is '0': #is item a regular file ? |
| 181 | #no backup file | 178 | #no backup file |
| 182 | class_file = mat.create_class_file(name, False, | 179 | class_file = mat.create_class_file(name, False,self.add2archive) |
| 183 | self.add2archive) | ||
| 184 | mat.secure_remove(name) | 180 | mat.secure_remove(name) |
| 185 | if not class_file.is_clean():#if the extracted file is not clean | 181 | if not class_file.is_clean():#if the extracted file is not clean |
| 186 | return False | 182 | return False |
