diff options
| author | jvoisin | 2011-08-07 22:51:56 +0200 |
|---|---|---|
| committer | jvoisin | 2011-08-07 22:51:56 +0200 |
| commit | 74a5189408f1cd0a90dcb7b28e3a6d71e47d8b29 (patch) | |
| tree | 8b9d12e1ab5a3392569ac1151d9d9e0eab817832 /lib | |
| parent | 4526c38014b9ad346f554efd0bf95271e88e8011 (diff) | |
Lisibility improvement for tempfile suppression.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/archive.py | 11 | ||||
| -rw-r--r-- | lib/office.py | 5 |
2 files changed, 6 insertions, 10 deletions
diff --git a/lib/archive.py b/lib/archive.py index 3f16ee4..c97385b 100644 --- a/lib/archive.py +++ b/lib/archive.py | |||
| @@ -26,8 +26,13 @@ class GenericArchiveStripper(parser.GenericParser): | |||
| 26 | 26 | ||
| 27 | def __del__(self): | 27 | def __del__(self): |
| 28 | ''' | 28 | ''' |
| 29 | Remove the temp dir | 29 | Remove the files inside the temp dir, |
| 30 | then remove the temp dir | ||
| 30 | ''' | 31 | ''' |
| 32 | for root, dirs, files in os.walk(self.tempdir): | ||
| 33 | for item in files: | ||
| 34 | path_file = os.path.join(root, item) | ||
| 35 | mat.secure_remove(path_file) | ||
| 31 | shutil.rmtree(self.tempdir) | 36 | shutil.rmtree(self.tempdir) |
| 32 | 37 | ||
| 33 | def remove_all(self): | 38 | def remove_all(self): |
| @@ -101,7 +106,6 @@ harmless format' % item.filename) | |||
| 101 | if ext not in parser.NOMETA: | 106 | if ext not in parser.NOMETA: |
| 102 | if bname != 'mimetype' and bname != '.rels': | 107 | if bname != 'mimetype' and bname != '.rels': |
| 103 | return False | 108 | return False |
| 104 | mat.secure_remove(name) | ||
| 105 | zipin.close() | 109 | zipin.close() |
| 106 | return True | 110 | return True |
| 107 | 111 | ||
| @@ -152,7 +156,6 @@ harmless format' % item.filename) | |||
| 152 | _, ext = os.path.splitext(name) | 156 | _, ext = os.path.splitext(name) |
| 153 | if self.add2archive or ext in parser.NOMETA: | 157 | if self.add2archive or ext in parser.NOMETA: |
| 154 | zipout.write(name, item.filename) | 158 | zipout.write(name, item.filename) |
| 155 | mat.secure_remove(name) | ||
| 156 | zipout.comment = '' | 159 | zipout.comment = '' |
| 157 | zipin.close() | 160 | zipin.close() |
| 158 | zipout.close() | 161 | zipout.close() |
| @@ -197,7 +200,6 @@ class TarStripper(GenericArchiveStripper): | |||
| 197 | _, ext = os.path.splitext(name) | 200 | _, ext = os.path.splitext(name) |
| 198 | if self.add2archive or ext in parser.NOMETA: | 201 | if self.add2archive or ext in parser.NOMETA: |
| 199 | tarout.add(name, item.name, filter=self._remove) | 202 | tarout.add(name, item.name, filter=self._remove) |
| 200 | mat.secure_remove(name) | ||
| 201 | tarin.close() | 203 | tarin.close() |
| 202 | tarout.close() | 204 | tarout.close() |
| 203 | self.do_backup() | 205 | self.do_backup() |
| @@ -244,7 +246,6 @@ class TarStripper(GenericArchiveStripper): | |||
| 244 | if ext not in parser.NOMETA: | 246 | if ext not in parser.NOMETA: |
| 245 | tarin.close() | 247 | tarin.close() |
| 246 | return False | 248 | return False |
| 247 | mat.secure_remove(name) | ||
| 248 | tarin.close() | 249 | tarin.close() |
| 249 | return True | 250 | return True |
| 250 | 251 | ||
diff --git a/lib/office.py b/lib/office.py index 9c9d367..33af48e 100644 --- a/lib/office.py +++ b/lib/office.py | |||
| @@ -62,14 +62,12 @@ class OpenDocumentStripper(archive.GenericArchiveStripper): | |||
| 62 | if not 'meta.xml' in line: | 62 | if not 'meta.xml' in line: |
| 63 | print line | 63 | print line |
| 64 | zipout.write(name, item) | 64 | zipout.write(name, item) |
| 65 | mat.secure_remove(name) | ||
| 66 | 65 | ||
| 67 | elif ext in parser.NOMETA or item == 'mimetype': | 66 | elif ext in parser.NOMETA or item == 'mimetype': |
| 68 | #keep NOMETA files, and the "manifest" file | 67 | #keep NOMETA files, and the "manifest" file |
| 69 | if item != 'meta.xml': # contains the metadata | 68 | if item != 'meta.xml': # contains the metadata |
| 70 | zipin.extract(item, self.tempdir) | 69 | zipin.extract(item, self.tempdir) |
| 71 | zipout.write(name, item) | 70 | zipout.write(name, item) |
| 72 | mat.secure_remove(name) | ||
| 73 | 71 | ||
| 74 | else: | 72 | else: |
| 75 | zipin.extract(item, self.tempdir) | 73 | zipin.extract(item, self.tempdir) |
| @@ -88,7 +86,6 @@ class OpenDocumentStripper(archive.GenericArchiveStripper): | |||
| 88 | logging.info('%s\' fileformat is not supported' % item) | 86 | logging.info('%s\' fileformat is not supported' % item) |
| 89 | if self.add2archive: | 87 | if self.add2archive: |
| 90 | zipout.write(name, item) | 88 | zipout.write(name, item) |
| 91 | mat.secure_remove(name) | ||
| 92 | zipout.comment = '' | 89 | zipout.comment = '' |
| 93 | logging.info('%s treated' % self.filename) | 90 | logging.info('%s treated' % self.filename) |
| 94 | zipin.close() | 91 | zipin.close() |
| @@ -208,7 +205,6 @@ class OpenXmlStripper(archive.GenericArchiveStripper): | |||
| 208 | #keep parser.NOMETA files, and the file named ".rels" | 205 | #keep parser.NOMETA files, and the file named ".rels" |
| 209 | zipin.extract(item, self.tempdir) | 206 | zipin.extract(item, self.tempdir) |
| 210 | zipout.write(name, item) | 207 | zipout.write(name, item) |
| 211 | mat.secure_remove(name) | ||
| 212 | else: | 208 | else: |
| 213 | zipin.extract(item, self.tempdir) | 209 | zipin.extract(item, self.tempdir) |
| 214 | if os.path.isfile(name): # don't care about folders | 210 | if os.path.isfile(name): # don't care about folders |
| @@ -226,7 +222,6 @@ class OpenXmlStripper(archive.GenericArchiveStripper): | |||
| 226 | logging.info('%s\' fileformat is not supported' % item) | 222 | logging.info('%s\' fileformat is not supported' % item) |
| 227 | if self.add2archive: | 223 | if self.add2archive: |
| 228 | zipout.write(name, item) | 224 | zipout.write(name, item) |
| 229 | mat.secure_remove(name) | ||
| 230 | zipout.comment = '' | 225 | zipout.comment = '' |
| 231 | logging.info('%s treated' % self.filename) | 226 | logging.info('%s treated' % self.filename) |
| 232 | zipin.close() | 227 | zipin.close() |
