diff options
| -rwxr-xr-x | cli.py | 1 | ||||
| -rw-r--r-- | gui.py | 27 | ||||
| -rw-r--r-- | lib/archive.py | 8 | ||||
| -rw-r--r-- | lib/office.py | 4 | ||||
| -rw-r--r-- | lib/parser.py | 1 | ||||
| -rw-r--r-- | test/test.py | 7 |
6 files changed, 23 insertions, 25 deletions
| @@ -123,6 +123,7 @@ def list_supported(): | |||
| 123 | print('\n') | 123 | print('\n') |
| 124 | sys.exit(0) | 124 | sys.exit(0) |
| 125 | 125 | ||
| 126 | |||
| 126 | def main(): | 127 | def main(): |
| 127 | ''' | 128 | ''' |
| 128 | main function : get args, and launch the appropriate function | 129 | main function : get args, and launch the appropriate function |
| @@ -196,15 +196,15 @@ class ListStoreApp: | |||
| 196 | chooser.set_default_response(0) | 196 | chooser.set_default_response(0) |
| 197 | chooser.set_select_multiple(True) | 197 | chooser.set_select_multiple(True) |
| 198 | 198 | ||
| 199 | filter = gtk.FileFilter() | 199 | all_filter = gtk.FileFilter() |
| 200 | filter.set_name('All files') | 200 | all_filter.set_name('All files') |
| 201 | filter.add_pattern('*') | 201 | all_filter.add_pattern('*') |
| 202 | chooser.add_filter(filter) | 202 | chooser.add_filter(all_filter) |
| 203 | 203 | ||
| 204 | filter = gtk.FileFilter() | 204 | supported_filter = gtk.FileFilter() |
| 205 | [filter.add_mime_type(i) for i in mat.STRIPPERS.keys()] | 205 | [supported_filter.add_mime_type(i) for i in mat.STRIPPERS.keys()] |
| 206 | filter.set_name('Supported files') | 206 | supported_filter.set_name('Supported files') |
| 207 | chooser.add_filter(filter) | 207 | chooser.add_filter(supported_filter) |
| 208 | 208 | ||
| 209 | response = chooser.run() | 209 | response = chooser.run() |
| 210 | 210 | ||
| @@ -239,7 +239,7 @@ class ListStoreApp: | |||
| 239 | w.set_comments('This software was coded during the GSoC 2011') | 239 | w.set_comments('This software was coded during the GSoC 2011') |
| 240 | w.set_website('https://gitweb.torproject.org/user/jvoisin/mat.git') | 240 | w.set_website('https://gitweb.torproject.org/user/jvoisin/mat.git') |
| 241 | w.set_website_label('Website') | 241 | w.set_website_label('Website') |
| 242 | w.set_authors(['Julien (jvoisin) Voisin',]) | 242 | w.set_authors(['Julien (jvoisin) Voisin', ]) |
| 243 | w.set_program_name('Metadata Anonymistion Toolkit') | 243 | w.set_program_name('Metadata Anonymistion Toolkit') |
| 244 | click = w.run() | 244 | click = w.run() |
| 245 | if click: | 245 | if click: |
| @@ -262,17 +262,16 @@ class ListStoreApp: | |||
| 262 | handler = mat.XMLParser() | 262 | handler = mat.XMLParser() |
| 263 | parser = xml.sax.make_parser() | 263 | parser = xml.sax.make_parser() |
| 264 | parser.setContentHandler(handler) | 264 | parser.setContentHandler(handler) |
| 265 | with open('FORMATS', 'r') as f: | 265 | with open('FORMATS', 'r') as xmlfile: |
| 266 | parser.parse(f) | 266 | parser.parse(xmlfile) |
| 267 | 267 | ||
| 268 | for item in handler.list: # list of dict : one pict per format | 268 | for item in handler.list: # list of dict : one dict per format |
| 269 | #create one expander per format | 269 | #create one expander per format |
| 270 | title = '%s (%s)' % (item['name'], item['extension']) | 270 | title = '%s (%s)' % (item['name'], item['extension']) |
| 271 | support = '\t<b>support</b> : ' + item['support'] | 271 | support = '\t<b>support</b> : ' + item['support'] |
| 272 | metadata = '\n\t<b>metadata</b> : ' + item['metadata'] | 272 | metadata = '\n\t<b>metadata</b> : ' + item['metadata'] |
| 273 | method = '\n\t<b>method</b> : ' + item['method'] | 273 | method = '\n\t<b>method</b> : ' + item['method'] |
| 274 | content = support + metadata + method | 274 | content = support + metadata + method |
| 275 | |||
| 276 | if item['support'] == 'partial': | 275 | if item['support'] == 'partial': |
| 277 | content += '\n\t<b>remaining</b> : ' + item['remaining'] | 276 | content += '\n\t<b>remaining</b> : ' + item['remaining'] |
| 278 | 277 | ||
diff --git a/lib/archive.py b/lib/archive.py index 108134c..5956a1e 100644 --- a/lib/archive.py +++ b/lib/archive.py | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | ''' | 1 | ''' |
| 2 | Take care of archives formats | 2 | Take care of archives formats |
| 3 | ''' | 3 | ''' |
| 4 | import tarfile | ||
| 5 | import zipfile | ||
| 6 | 4 | ||
| 5 | import zipfile | ||
| 7 | import shutil | 6 | import shutil |
| 8 | import os | 7 | import os |
| 9 | import logging | 8 | import logging |
| @@ -11,7 +10,7 @@ import tempfile | |||
| 11 | 10 | ||
| 12 | import parser | 11 | import parser |
| 13 | import mat | 12 | import mat |
| 14 | 13 | import tarfile | |
| 15 | 14 | ||
| 16 | class GenericArchiveStripper(parser.GenericParser): | 15 | class GenericArchiveStripper(parser.GenericParser): |
| 17 | ''' | 16 | ''' |
| @@ -224,6 +223,7 @@ class TarStripper(GenericArchiveStripper): | |||
| 224 | tarin = tarfile.open(self.filename, 'r' + self.compression) | 223 | tarin = tarfile.open(self.filename, 'r' + self.compression) |
| 225 | for item in tarin.getmembers(): | 224 | for item in tarin.getmembers(): |
| 226 | if not self.is_file_clean(item): | 225 | if not self.is_file_clean(item): |
| 226 | tarin.close() | ||
| 227 | return False | 227 | return False |
| 228 | tarin.extract(item, self.tempdir) | 228 | tarin.extract(item, self.tempdir) |
| 229 | name = os.path.join(self.tempdir, item.name) | 229 | name = os.path.join(self.tempdir, item.name) |
| @@ -233,12 +233,14 @@ class TarStripper(GenericArchiveStripper): | |||
| 233 | class_file = mat.create_class_file(name, | 233 | class_file = mat.create_class_file(name, |
| 234 | False, self.add2archive) | 234 | False, self.add2archive) |
| 235 | if not class_file.is_clean(): | 235 | if not class_file.is_clean(): |
| 236 | tarin.close() | ||
| 236 | return False | 237 | return False |
| 237 | except: | 238 | except: |
| 238 | #best solution I have found | 239 | #best solution I have found |
| 239 | logging.error('%s is not supported' % item.filename) | 240 | logging.error('%s is not supported' % item.filename) |
| 240 | _, ext = os.path.splitext(name) | 241 | _, ext = os.path.splitext(name) |
| 241 | if ext not in parser.NOMETA: | 242 | if ext not in parser.NOMETA: |
| 243 | tarin.close() | ||
| 242 | return False | 244 | return False |
| 243 | mat.secure_remove(name) | 245 | mat.secure_remove(name) |
| 244 | tarin.close() | 246 | tarin.close() |
diff --git a/lib/office.py b/lib/office.py index e21805a..f236d09 100644 --- a/lib/office.py +++ b/lib/office.py | |||
| @@ -103,9 +103,7 @@ class OpenDocumentStripper(archive.GenericArchiveStripper): | |||
| 103 | zipin.close() | 103 | zipin.close() |
| 104 | czf = archive.ZipStripper(self.filename, self.parser, | 104 | czf = archive.ZipStripper(self.filename, self.parser, |
| 105 | 'application/zip', self.backup, self.add2archive) | 105 | 'application/zip', self.backup, self.add2archive) |
| 106 | if czf.is_clean(): | 106 | if not czf.is_clean(): |
| 107 | return True | ||
| 108 | else: | ||
| 109 | return False | 107 | return False |
| 110 | return True | 108 | return True |
| 111 | 109 | ||
diff --git a/lib/parser.py b/lib/parser.py index 044ef0a..1bdca57 100644 --- a/lib/parser.py +++ b/lib/parser.py | |||
| @@ -31,7 +31,6 @@ class GenericParser(object): | |||
| 31 | self.output = basename + '.cleaned' + ext | 31 | self.output = basename + '.cleaned' + ext |
| 32 | self.basename = os.path.basename(filename) # only filename | 32 | self.basename = os.path.basename(filename) # only filename |
| 33 | 33 | ||
| 34 | |||
| 35 | def is_clean(self): | 34 | def is_clean(self): |
| 36 | ''' | 35 | ''' |
| 37 | Check if the file is clean from harmful metadatas | 36 | Check if the file is clean from harmful metadatas |
diff --git a/test/test.py b/test/test.py index 681a956..9b99ecc 100644 --- a/test/test.py +++ b/test/test.py | |||
| @@ -1,14 +1,13 @@ | |||
| 1 | ''' | 1 | ''' |
| 2 | Class for the testing suite : | 2 | Class for the testing suite : |
| 3 | - get the list of all test files | 3 | - get the list of all test files |
| 4 | - create a copy of them on start | 4 | - create a copy of them on start |
| 5 | - remove the copy on end | 5 | - remove the copy on end |
| 6 | ''' | 6 | ''' |
| 7 | 7 | ||
| 8 | import shutil | 8 | import shutil |
| 9 | import os | 9 | import os |
| 10 | import glob | 10 | import glob |
| 11 | import sys | ||
| 12 | import tempfile | 11 | import tempfile |
| 13 | import unittest | 12 | import unittest |
| 14 | 13 | ||
