diff options
| author | jvoisin | 2011-10-29 20:57:12 +0200 |
|---|---|---|
| committer | jvoisin | 2011-10-29 20:57:12 +0200 |
| commit | 4dcdf721d8ab5b7c8925ac9ad55f4dedd2c8e7df (patch) | |
| tree | 5c801aef555b3bf7567f51375a2a41e4ff5805ba | |
| parent | 5aeb4cf1975315c5d47dbb1a3a98bf86803b8d82 (diff) | |
Take care about the return value of external utils
| -rw-r--r-- | TODO | 5 | ||||
| -rwxr-xr-x | mat-cli | 7 | ||||
| -rwxr-xr-x | mat-gui | 8 | ||||
| -rw-r--r-- | mat/archive.py | 6 | ||||
| -rw-r--r-- | mat/audio.py | 2 | ||||
| -rw-r--r-- | mat/exiftool.py | 22 | ||||
| -rw-r--r-- | mat/misc.py | 1 | ||||
| -rw-r--r-- | mat/office.py | 53 | ||||
| -rw-r--r-- | mat/parser.py | 16 |
9 files changed, 66 insertions, 54 deletions
| @@ -3,12 +3,7 @@ GENERAL: | |||
| 3 | the ultimate goal is to remove | 3 | the ultimate goal is to remove |
| 4 | all "harmful meta" stuff | 4 | all "harmful meta" stuff |
| 5 | - Fix the ugly function get_sharedir | 5 | - Fix the ugly function get_sharedir |
| 6 | - What is wrong with the testsuite ? | ||
| 7 | - Handle exotic characters in filenames | 6 | - Handle exotic characters in filenames |
| 8 | - use the return code of external apps used by mat | ||
| 9 | to check that everything went right | ||
| 10 | - proper handling of pdf with exiftool | ||
| 11 | - enhance the exiftool's presence test | ||
| 12 | 7 | ||
| 13 | GUI: | 8 | GUI: |
| 14 | - Drag and Drop | 9 | - Drag and Drop |
| @@ -93,9 +93,10 @@ def clean_meta(class_file, filename, force): | |||
| 93 | if force is False and class_file.is_clean(): | 93 | if force is False and class_file.is_clean(): |
| 94 | print('%s is already clean' % filename) | 94 | print('%s is already clean' % filename) |
| 95 | else: | 95 | else: |
| 96 | class_file.remove_all() | 96 | if class_file.remove_all(): |
| 97 | print('%s cleaned !' % filename) | 97 | print('%s cleaned !' % filename) |
| 98 | 98 | else: | |
| 99 | print('Unable to clean %s', filename) | ||
| 99 | 100 | ||
| 100 | def clean_meta_ugly(class_file, filename, force): | 101 | def clean_meta_ugly(class_file, filename, force): |
| 101 | ''' | 102 | ''' |
| @@ -485,10 +485,10 @@ non-anonymised) file to output archive')) | |||
| 485 | self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1]) | 485 | self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1]) |
| 486 | if self.liststore[line][3] != _('Clean (strict)'): | 486 | if self.liststore[line][3] != _('Clean (strict)'): |
| 487 | if self.force or not self.liststore[line][0].file.is_clean(): | 487 | if self.force or not self.liststore[line][0].file.is_clean(): |
| 488 | self.liststore[line][0].file.remove_all() | 488 | if self.liststore[line][0].file.remove_all(): |
| 489 | self.liststore[line][3] = _('Clean (lossless)') | ||
| 489 | if self.backup: # the backup copy state | 490 | if self.backup: # the backup copy state |
| 490 | self.liststore[line][4] = self.liststore[line][0].file.output | 491 | self.liststore[line][4] = self.liststore[line][0].file.output |
| 491 | self.liststore[line][3] = _('Clean (lossless)') | ||
| 492 | yield True | 492 | yield True |
| 493 | self.statusbar.push(0, _('Ready')) | 493 | self.statusbar.push(0, _('Ready')) |
| 494 | yield False | 494 | yield False |
| @@ -502,10 +502,10 @@ non-anonymised) file to output archive')) | |||
| 502 | self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1]) | 502 | self.statusbar.push(0, _('Cleaning %s...') % self.liststore[line][1]) |
| 503 | if self.liststore[line][3] != _('Clean (strict)'): | 503 | if self.liststore[line][3] != _('Clean (strict)'): |
| 504 | if self.force or not self.liststore[line][0].file.is_clean(): | 504 | if self.force or not self.liststore[line][0].file.is_clean(): |
| 505 | self.liststore[line][0].file.remove_all_ugly() | 505 | if self.liststore[line][0].file.remove_all_ugly(): |
| 506 | self.liststore[line][3] = _('Clean (strict)') | ||
| 506 | if self.backup: # the backup copy state | 507 | if self.backup: # the backup copy state |
| 507 | self.liststore[line][4] = self.liststore[line][0].file.output | 508 | self.liststore[line][4] = self.liststore[line][0].file.output |
| 508 | self.liststore[line][3] = _('Clean (strict)') | ||
| 509 | yield True | 509 | yield True |
| 510 | self.statusbar.push(0, _('Ready')) | 510 | self.statusbar.push(0, _('Ready')) |
| 511 | yield False | 511 | yield False |
diff --git a/mat/archive.py b/mat/archive.py index 77db71c..65527d2 100644 --- a/mat/archive.py +++ b/mat/archive.py | |||
| @@ -39,13 +39,13 @@ class GenericArchiveStripper(parser.GenericParser): | |||
| 39 | ''' | 39 | ''' |
| 40 | Call _remove_all() with in argument : "normal" | 40 | Call _remove_all() with in argument : "normal" |
| 41 | ''' | 41 | ''' |
| 42 | self._remove_all('normal') | 42 | return self._remove_all('normal') |
| 43 | 43 | ||
| 44 | def remove_all_ugly(self): | 44 | def remove_all_ugly(self): |
| 45 | ''' | 45 | ''' |
| 46 | call remove_all() with in argument : "ugly" | 46 | call remove_all() with in argument : "ugly" |
| 47 | ''' | 47 | ''' |
| 48 | self._remove_all('ugly') | 48 | return self._remove_all('ugly') |
| 49 | 49 | ||
| 50 | def _remove_all(self, method): | 50 | def _remove_all(self, method): |
| 51 | ''' | 51 | ''' |
| @@ -161,6 +161,7 @@ harmless format' % item.filename) | |||
| 161 | zipout.close() | 161 | zipout.close() |
| 162 | logging.info('%s treated' % self.filename) | 162 | logging.info('%s treated' % self.filename) |
| 163 | self.do_backup() | 163 | self.do_backup() |
| 164 | return True | ||
| 164 | 165 | ||
| 165 | 166 | ||
| 166 | class TarStripper(GenericArchiveStripper): | 167 | class TarStripper(GenericArchiveStripper): |
| @@ -203,6 +204,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 203 | tarin.close() | 204 | tarin.close() |
| 204 | tarout.close() | 205 | tarout.close() |
| 205 | self.do_backup() | 206 | self.do_backup() |
| 207 | return True | ||
| 206 | 208 | ||
| 207 | def is_file_clean(self, current_file): | 209 | def is_file_clean(self, current_file): |
| 208 | ''' | 210 | ''' |
diff --git a/mat/audio.py b/mat/audio.py index 21a94be..ed849ee 100644 --- a/mat/audio.py +++ b/mat/audio.py | |||
| @@ -35,6 +35,7 @@ class OggStripper(parser.GenericParser): | |||
| 35 | mfile = OggVorbis(self.filename) | 35 | mfile = OggVorbis(self.filename) |
| 36 | mfile.delete() | 36 | mfile.delete() |
| 37 | mfile.save() | 37 | mfile.save() |
| 38 | return True | ||
| 38 | 39 | ||
| 39 | def is_clean(self): | 40 | def is_clean(self): |
| 40 | ''' | 41 | ''' |
| @@ -73,6 +74,7 @@ class FlacStripper(parser.GenericParser): | |||
| 73 | mfile.delete() | 74 | mfile.delete() |
| 74 | mfile.clear_pictures() | 75 | mfile.clear_pictures() |
| 75 | mfile.save() | 76 | mfile.save() |
| 77 | return True | ||
| 76 | 78 | ||
| 77 | def is_clean(self): | 79 | def is_clean(self): |
| 78 | ''' | 80 | ''' |
diff --git a/mat/exiftool.py b/mat/exiftool.py index 5a4ecc9..1d2d116 100644 --- a/mat/exiftool.py +++ b/mat/exiftool.py | |||
| @@ -30,15 +30,19 @@ class ExiftoolStripper(parser.GenericParser): | |||
| 30 | ''' | 30 | ''' |
| 31 | Remove all metadata with help of exiftool | 31 | Remove all metadata with help of exiftool |
| 32 | ''' | 32 | ''' |
| 33 | if self.backup: | 33 | try: |
| 34 | process = subprocess.Popen(['exiftool', '-All=', | 34 | if self.backup: |
| 35 | '-out', self.output, self.filename], | 35 | process = subprocess.Popen(['exiftool', '-All=', |
| 36 | stdout=open('/dev/null')) | 36 | '-out', self.output, self.filename], |
| 37 | process.wait() | 37 | stdout=open('/dev/null')) |
| 38 | else: | 38 | process.wait() |
| 39 | process = subprocess.Popen(['exiftool', '-overwrite_original', | 39 | else: |
| 40 | '-All=', self.filename], stdout=open('/dev/null')) | 40 | process = subprocess.Popen(['exiftool', '-overwrite_original', |
| 41 | process.wait() | 41 | '-All=', self.filename], stdout=open('/dev/null')) |
| 42 | process.wait() | ||
| 43 | return True | ||
| 44 | except: | ||
| 45 | return False | ||
| 42 | 46 | ||
| 43 | def is_clean(self): | 47 | def is_clean(self): |
| 44 | ''' | 48 | ''' |
diff --git a/mat/misc.py b/mat/misc.py index f7b256f..d084861 100644 --- a/mat/misc.py +++ b/mat/misc.py | |||
| @@ -60,3 +60,4 @@ class TorrentStripper(parser.GenericParser): | |||
| 60 | with open(self.output, 'w') as f: # encode the decoded torrent | 60 | with open(self.output, 'w') as f: # encode the decoded torrent |
| 61 | f.write(bencode.bencode(decoded)) # and write it in self.output | 61 | f.write(bencode.bencode(decoded)) # and write it in self.output |
| 62 | self.do_backup() | 62 | self.do_backup() |
| 63 | return True | ||
diff --git a/mat/office.py b/mat/office.py index 2d7e9e6..2782318 100644 --- a/mat/office.py +++ b/mat/office.py | |||
| @@ -91,6 +91,7 @@ class OpenDocumentStripper(archive.GenericArchiveStripper): | |||
| 91 | zipin.close() | 91 | zipin.close() |
| 92 | zipout.close() | 92 | zipout.close() |
| 93 | self.do_backup() | 93 | self.do_backup() |
| 94 | return True | ||
| 94 | 95 | ||
| 95 | def is_clean(self): | 96 | def is_clean(self): |
| 96 | ''' | 97 | ''' |
| @@ -128,8 +129,8 @@ class PdfStripper(parser.GenericParser): | |||
| 128 | ''' | 129 | ''' |
| 129 | for key in self.meta_list: | 130 | for key in self.meta_list: |
| 130 | if self.document.get_property(key) is not None and \ | 131 | if self.document.get_property(key) is not None and \ |
| 131 | self.document.get_property(key) != '': | 132 | self.document.get_property(key) != '': |
| 132 | return False | 133 | return False |
| 133 | return True | 134 | return True |
| 134 | 135 | ||
| 135 | 136 | ||
| @@ -137,7 +138,7 @@ class PdfStripper(parser.GenericParser): | |||
| 137 | ''' | 138 | ''' |
| 138 | Remove supperficial | 139 | Remove supperficial |
| 139 | ''' | 140 | ''' |
| 140 | self._remove_meta() | 141 | return self._remove_meta() |
| 141 | 142 | ||
| 142 | 143 | ||
| 143 | def remove_all_ugly(self): | 144 | def remove_all_ugly(self): |
| @@ -159,7 +160,7 @@ class PdfStripper(parser.GenericParser): | |||
| 159 | page.render(context) # render the page on context | 160 | page.render(context) # render the page on context |
| 160 | context.show_page() # draw context on surface | 161 | context.show_page() # draw context on surface |
| 161 | surface.finish() | 162 | surface.finish() |
| 162 | self._remove_meta() | 163 | return self._remove_meta() |
| 163 | 164 | ||
| 164 | def _remove_meta(self): | 165 | def _remove_meta(self): |
| 165 | ''' | 166 | ''' |
| @@ -167,39 +168,40 @@ class PdfStripper(parser.GenericParser): | |||
| 167 | from a pdf file, using exiftool, | 168 | from a pdf file, using exiftool, |
| 168 | of pdfrw if exiftool is not installed | 169 | of pdfrw if exiftool is not installed |
| 169 | ''' | 170 | ''' |
| 170 | processed = False | 171 | processed = False |
| 171 | try: # try with pdfrw | 172 | try:# try with pdfrw |
| 172 | import pdfrw | 173 | import pdfrw |
| 173 | #For now, poppler cannot write meta, so we must use pdfrw | 174 | #For now, poppler cannot write meta, so we must use pdfrw |
| 174 | logging.debug('Removing %s\'s superficial metadata' % self.filename) | 175 | logging.debug('Removing %s\'s superficial metadata' % self.filename) |
| 175 | trailer = pdfrw.PdfReader(self.output) | 176 | trailer = pdfrw.PdfReader(self.output) |
| 176 | trailer.Info.Producer = trailer.Author = trailer.Info.Creator = None | 177 | trailer.Info.Producer = trailer.Author = trailer.Info.Creator = None |
| 177 | writer = pdfrw.PdfWriter() | 178 | writer = pdfrw.PdfWriter() |
| 178 | writer.trailer = trailer | 179 | writer.trailer = trailer |
| 179 | writer.write(self.output) | 180 | writer.write(self.output) |
| 180 | self.do_backup() | 181 | self.do_backup() |
| 181 | processed = True | 182 | processed = True |
| 182 | except: | 183 | except: |
| 183 | pass | 184 | pass |
| 184 | 185 | ||
| 185 | try: # try with exiftool | 186 | try: # try with exiftool |
| 186 | subprocess.Popen('exiftool', stdout=open('/dev/null')) | 187 | subprocess.Popen('exiftool', stdout=open('/dev/null')) |
| 187 | import exiftool | 188 | import exiftool |
| 188 | if self.backup: | 189 | if self.backup: |
| 189 | process = subprocess.Popen(['exiftool', '-All=', | 190 | process = subprocess.Popen(['exiftool', '-All=', |
| 190 | '-out', self.output, self.filename], | 191 | '-out', self.output, self.filename], stdout=open('/dev/null')) |
| 191 | stdout=open('/dev/null')) | ||
| 192 | process.wait() | 192 | process.wait() |
| 193 | else: | 193 | else: |
| 194 | process = subprocess.Popen(['exiftool', '-overwrite_original', | 194 | process = subprocess.Popen(['exiftool', '-overwrite_original', |
| 195 | '-All=', self.filename], stdout=open('/dev/null')) | 195 | '-All=', self.filename], stdout=open('/dev/null')) |
| 196 | process.wait() | 196 | process.wait() |
| 197 | processed = True | 197 | processed = True |
| 198 | except: | 198 | except: |
| 199 | pass | 199 | pass |
| 200 | 200 | ||
| 201 | if processed is False: | 201 | if processed is False: |
| 202 | logging.error('Please install either pdfrw, or exiftool') | 202 | logging.error('Please install either pdfrw, or exiftool to\ |
| 203 | fully handle pdf files') | ||
| 204 | return processed | ||
| 203 | 205 | ||
| 204 | def get_meta(self): | 206 | def get_meta(self): |
| 205 | ''' | 207 | ''' |
| @@ -260,6 +262,7 @@ class OpenXmlStripper(archive.GenericArchiveStripper): | |||
| 260 | zipin.close() | 262 | zipin.close() |
| 261 | zipout.close() | 263 | zipout.close() |
| 262 | self.do_backup() | 264 | self.do_backup() |
| 265 | return True | ||
| 263 | 266 | ||
| 264 | def is_clean(self): | 267 | def is_clean(self): |
| 265 | ''' | 268 | ''' |
diff --git a/mat/parser.py b/mat/parser.py index c7c606c..ebab297 100644 --- a/mat/parser.py +++ b/mat/parser.py | |||
| @@ -66,12 +66,16 @@ class GenericParser(object): | |||
| 66 | self.do_backup() | 66 | self.do_backup() |
| 67 | 67 | ||
| 68 | def _remove_all(self, fieldset): | 68 | def _remove_all(self, fieldset): |
| 69 | for field in fieldset: | 69 | try: |
| 70 | remove = self._should_remove(field) | 70 | for field in fieldset: |
| 71 | if remove is True: | 71 | remove = self._should_remove(field) |
| 72 | self._remove(fieldset, field.name) | 72 | if remove is True: |
| 73 | if remove is FIELD: | 73 | self._remove(fieldset, field.name) |
| 74 | self._remove_all(field) | 74 | if remove is FIELD: |
| 75 | self._remove_all(field) | ||
| 76 | return True | ||
| 77 | except: | ||
| 78 | return False | ||
| 75 | 79 | ||
| 76 | def remove_all_ugly(self): | 80 | def remove_all_ugly(self): |
| 77 | ''' | 81 | ''' |
