diff options
| -rw-r--r-- | libmat/archive.py | 5 | ||||
| -rw-r--r-- | libmat/mat.py | 4 | ||||
| -rwxr-xr-x | mat | 6 | ||||
| -rwxr-xr-x | mat-gui | 24 | ||||
| -rw-r--r-- | nautilus/nautilus-mat.py | 11 | ||||
| -rwxr-xr-x | setup.py | 1 | ||||
| -rw-r--r-- | test/clitest.py | 4 | ||||
| -rw-r--r-- | test/test.py | 21 |
8 files changed, 51 insertions, 25 deletions
diff --git a/libmat/archive.py b/libmat/archive.py index 61028ef..a662e61 100644 --- a/libmat/archive.py +++ b/libmat/archive.py | |||
| @@ -47,6 +47,11 @@ class GenericArchiveStripper(parser.GenericParser): | |||
| 47 | """ | 47 | """ |
| 48 | return self.is_clean(list_unsupported=True) | 48 | return self.is_clean(list_unsupported=True) |
| 49 | 49 | ||
| 50 | def remove_all(self): | ||
| 51 | """ Virtual method to remove all compromising fields | ||
| 52 | """ | ||
| 53 | raise NotImplementedError | ||
| 54 | |||
| 50 | 55 | ||
| 51 | class ZipStripper(GenericArchiveStripper): | 56 | class ZipStripper(GenericArchiveStripper): |
| 52 | """ Represent a zip file | 57 | """ Represent a zip file |
diff --git a/libmat/mat.py b/libmat/mat.py index e84c717..d397334 100644 --- a/libmat/mat.py +++ b/libmat/mat.py | |||
| @@ -84,6 +84,8 @@ class XMLParser(xml.sax.handler.ContentHandler): # pragma: no cover | |||
| 84 | 84 | ||
| 85 | def startElement(self, name, attrs): | 85 | def startElement(self, name, attrs): |
| 86 | """ Called when entering into xml tag | 86 | """ Called when entering into xml tag |
| 87 | :param attrs: Attributes of the `nam` xml tag | ||
| 88 | :param name: Name of the xml tag | ||
| 87 | """ | 89 | """ |
| 88 | self.between = True | 90 | self.between = True |
| 89 | self.key = name | 91 | self.key = name |
| @@ -91,6 +93,7 @@ class XMLParser(xml.sax.handler.ContentHandler): # pragma: no cover | |||
| 91 | 93 | ||
| 92 | def endElement(self, name): | 94 | def endElement(self, name): |
| 93 | """ Called when exiting a xml tag | 95 | """ Called when exiting a xml tag |
| 96 | :param name: name of the element | ||
| 94 | """ | 97 | """ |
| 95 | if name == 'format': # leaving a fileformat section | 98 | if name == 'format': # leaving a fileformat section |
| 96 | self.list.append(self.dict.copy()) | 99 | self.list.append(self.dict.copy()) |
| @@ -102,6 +105,7 @@ class XMLParser(xml.sax.handler.ContentHandler): # pragma: no cover | |||
| 102 | 105 | ||
| 103 | def characters(self, characters): | 106 | def characters(self, characters): |
| 104 | """ Concatenate the content between opening and closing tags | 107 | """ Concatenate the content between opening and closing tags |
| 108 | :param characters: content of the tag | ||
| 105 | """ | 109 | """ |
| 106 | if self.between: | 110 | if self.between: |
| 107 | self.content += characters | 111 | self.content += characters |
| @@ -117,9 +117,9 @@ def main(): | |||
| 117 | argparser = create_arg_parser() | 117 | argparser = create_arg_parser() |
| 118 | args = argparser.parse_args() | 118 | args = argparser.parse_args() |
| 119 | 119 | ||
| 120 | #show help if: neiter list nor file argument given; no argument at | 120 | # show help if: neither list nor file argument given; no argument at |
| 121 | #all given or the list argument mixed with some other argument given | 121 | # all given or the list argument mixed with some other argument given |
| 122 | if (not args.list and not args.files) or (not len(sys.argv) > 1) or (args.list and len(sys.argv) > 2): | 122 | if not (args.list or args.files) or (not sys.argv) or (args.list and len(sys.argv) > 2): |
| 123 | argparser.print_help() | 123 | argparser.print_help() |
| 124 | sys.exit(2) | 124 | sys.exit(2) |
| 125 | 125 | ||
| @@ -31,7 +31,7 @@ class CFile(GObject.Object): | |||
| 31 | """ | 31 | """ |
| 32 | 32 | ||
| 33 | def __init__(self, filename, **kwargs): | 33 | def __init__(self, filename, **kwargs): |
| 34 | self.file = mat.create_class_file(filename, 0, **kwargs) | 34 | self.file = mat.create_class_file(filename, False, **kwargs) |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | class GUI(object): | 37 | class GUI(object): |
| @@ -160,15 +160,15 @@ class GUI(object): | |||
| 160 | """ Popup that display on double-click | 160 | """ Popup that display on double-click |
| 161 | metadata from a file | 161 | metadata from a file |
| 162 | """ | 162 | """ |
| 163 | metadataPopupListStore = self.builder.get_object('MetadataPopupListStore') | 163 | metadatapopupliststore = self.builder.get_object('MetadataPopupListStore') |
| 164 | metadataPopupListStore.clear() | 164 | metadatapopupliststore.clear() |
| 165 | if self.liststore[row][0].file.is_clean(): | 165 | if self.liststore[row][0].file.is_clean(): |
| 166 | self.liststore[row][2] = _('Clean') | 166 | self.liststore[row][2] = _('Clean') |
| 167 | metadataPopupListStore.append([_('No metadata found'), '']) | 167 | metadatapopupliststore.append([_('No metadata found'), '']) |
| 168 | else: | 168 | else: |
| 169 | self.liststore[row][2] = _('Dirty') | 169 | self.liststore[row][2] = _('Dirty') |
| 170 | for i, j in self.liststore[row][0].file.get_meta().iteritems(): | 170 | for i, j in self.liststore[row][0].file.get_meta().iteritems(): |
| 171 | metadataPopupListStore.append([i, j]) | 171 | metadatapopupliststore.append([i, j]) |
| 172 | 172 | ||
| 173 | popup_metadata = self.builder.get_object('MetadataPopup') | 173 | popup_metadata = self.builder.get_object('MetadataPopup') |
| 174 | title = self.liststore[row][0].file.basename | 174 | title = self.liststore[row][0].file.basename |
| @@ -284,8 +284,8 @@ non-anonymised) file to output archive')) | |||
| 284 | iterator = self.treeview.get_selection().get_selected_rows()[1] | 284 | iterator = self.treeview.get_selection().get_selected_rows()[1] |
| 285 | if not iterator: # if nothing is selected : select everything | 285 | if not iterator: # if nothing is selected : select everything |
| 286 | iterator = range(len(self.liststore)) | 286 | iterator = range(len(self.liststore)) |
| 287 | task = func(iterator) # launch func() in an asynchronous way | 287 | sync_task = func(iterator) # launch func() in an asynchronous way |
| 288 | GLib.idle_add(task.next) | 288 | GLib.idle_add(sync_task.next) |
| 289 | 289 | ||
| 290 | def __invert(self, button, name): | 290 | def __invert(self, button, name): |
| 291 | """ Invert a preference state """ | 291 | """ Invert a preference state """ |
| @@ -295,7 +295,9 @@ non-anonymised) file to output archive')) | |||
| 295 | self.add2archive = not self.add2archive | 295 | self.add2archive = not self.add2archive |
| 296 | 296 | ||
| 297 | def populate(self, filenames): | 297 | def populate(self, filenames): |
| 298 | """ Append selected files by add_file to the self.liststore """ | 298 | """ Append selected files by add_file to the self.liststore |
| 299 | :param filenames: selected files | ||
| 300 | """ | ||
| 299 | not_supported = [] | 301 | not_supported = [] |
| 300 | for filename in filenames: # filenames : all selected files/folders | 302 | for filename in filenames: # filenames : all selected files/folders |
| 301 | if os.path.isdir(filename): # if "filename" is a directory | 303 | if os.path.isdir(filename): # if "filename" is a directory |
| @@ -343,10 +345,10 @@ non-anonymised) file to output archive')) | |||
| 343 | vbox.pack_start(treeview, True, True, 0) | 345 | vbox.pack_start(treeview, True, True, 0) |
| 344 | 346 | ||
| 345 | # Create columns | 347 | # Create columns |
| 346 | rendererText = Gtk.CellRendererText() | 348 | renderertext = Gtk.CellRendererText() |
| 347 | column = Gtk.TreeViewColumn(_('Filename'), rendererText, text=0) | 349 | column = Gtk.TreeViewColumn(_('Filename'), renderertext, text=0) |
| 348 | treeview.append_column(column) | 350 | treeview.append_column(column) |
| 349 | column = Gtk.TreeViewColumn(_('Reason'), rendererText, text=1) | 351 | column = Gtk.TreeViewColumn(_('Reason'), renderertext, text=1) |
| 350 | treeview.append_column(column) | 352 | treeview.append_column(column) |
| 351 | 353 | ||
| 352 | dialog.show_all() | 354 | dialog.show_all() |
diff --git a/nautilus/nautilus-mat.py b/nautilus/nautilus-mat.py index 938e692..0974bef 100644 --- a/nautilus/nautilus-mat.py +++ b/nautilus/nautilus-mat.py | |||
| @@ -24,6 +24,7 @@ import libmat.strippers | |||
| 24 | 24 | ||
| 25 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): | 25 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): |
| 26 | """ A nautilus extension, acting as a frontend to MAT, to clean metadata.""" | 26 | """ A nautilus extension, acting as a frontend to MAT, to clean metadata.""" |
| 27 | |||
| 27 | def __init__(self): | 28 | def __init__(self): |
| 28 | logging.debug("nautilus-mat: initialising") | 29 | logging.debug("nautilus-mat: initialising") |
| 29 | 30 | ||
| @@ -58,7 +59,10 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): | |||
| 58 | 59 | ||
| 59 | @staticmethod | 60 | @staticmethod |
| 60 | def show_message(message, msg_type=Gtk.MessageType.INFO): | 61 | def show_message(message, msg_type=Gtk.MessageType.INFO): |
| 61 | """ Helper function to show a message in a popup """ | 62 | """ Helper function to show a message in a popup |
| 63 | :param msg_type: Type of the message to display | ||
| 64 | :param message: Message to display | ||
| 65 | """ | ||
| 62 | dialog = Gtk.MessageDialog(parent=None, | 66 | dialog = Gtk.MessageDialog(parent=None, |
| 63 | flags=Gtk.DialogFlags.MODAL, | 67 | flags=Gtk.DialogFlags.MODAL, |
| 64 | type=msg_type, | 68 | type=msg_type, |
| @@ -69,7 +73,10 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): | |||
| 69 | return ret | 73 | return ret |
| 70 | 74 | ||
| 71 | def menu_activate_cb(self, menu, current_file): | 75 | def menu_activate_cb(self, menu, current_file): |
| 72 | """ Callback function, used to clean the file """ | 76 | """ Callback function, used to clean the file |
| 77 | :param current_file: Name of the selected file | ||
| 78 | :param menu: Menu id from which the callback was activated. Unused. | ||
| 79 | """ | ||
| 73 | if file.is_gone(): | 80 | if file.is_gone(): |
| 74 | return | 81 | return |
| 75 | 82 | ||
| @@ -16,6 +16,7 @@ if os.path.exists('MANIFEST'): | |||
| 16 | 16 | ||
| 17 | class PyTest(Command): | 17 | class PyTest(Command): |
| 18 | user_options = [] | 18 | user_options = [] |
| 19 | |||
| 19 | def initialize_options(self): | 20 | def initialize_options(self): |
| 20 | pass | 21 | pass |
| 21 | 22 | ||
diff --git a/test/clitest.py b/test/clitest.py index e186531..884655f 100644 --- a/test/clitest.py +++ b/test/clitest.py | |||
| @@ -136,10 +136,11 @@ class TestUnsupported(test.MATTest): | |||
| 136 | tar.close() | 136 | tar.close() |
| 137 | proc = subprocess.Popen(['mat', tarpath], stdout=subprocess.PIPE) | 137 | proc = subprocess.Popen(['mat', tarpath], stdout=subprocess.PIPE) |
| 138 | stdout, _ = proc.communicate() | 138 | stdout, _ = proc.communicate() |
| 139 | self.assertTrue('It contains unsupported filetypes:' \ | 139 | self.assertTrue('It contains unsupported filetypes:' |
| 140 | '\n- libtest.py\n- test.py\n- clitest.py\n' | 140 | '\n- libtest.py\n- test.py\n- clitest.py\n' |
| 141 | in str(stdout)) | 141 | in str(stdout)) |
| 142 | 142 | ||
| 143 | |||
| 143 | class TestHelp(test.MATTest): | 144 | class TestHelp(test.MATTest): |
| 144 | """ Test the different ways to trigger help """ | 145 | """ Test the different ways to trigger help """ |
| 145 | def test_dash_h(self): | 146 | def test_dash_h(self): |
| @@ -164,6 +165,7 @@ class TestHelp(test.MATTest): | |||
| 164 | _, stderr = proc.communicate() | 165 | _, stderr = proc.communicate() |
| 165 | self.assertTrue(('usage: mat [-h]' and ' error: unrecognized arguments:') in stderr) | 166 | self.assertTrue(('usage: mat [-h]' and ' error: unrecognized arguments:') in stderr) |
| 166 | 167 | ||
| 168 | |||
| 167 | def get_tests(): | 169 | def get_tests(): |
| 168 | """ Return every clitests""" | 170 | """ Return every clitests""" |
| 169 | suite = unittest.TestSuite() | 171 | suite = unittest.TestSuite() |
diff --git a/test/test.py b/test/test.py index fbbdcf4..6886c1f 100644 --- a/test/test.py +++ b/test/test.py | |||
| @@ -14,6 +14,7 @@ import glob | |||
| 14 | import sys | 14 | import sys |
| 15 | import tempfile | 15 | import tempfile |
| 16 | import unittest | 16 | import unittest |
| 17 | import subprocess | ||
| 17 | 18 | ||
| 18 | VERBOSITY = 15 | 19 | VERBOSITY = 15 |
| 19 | 20 | ||
| @@ -27,6 +28,7 @@ FILE_LIST = zip(clean, dirty) | |||
| 27 | try: # PDF render processing | 28 | try: # PDF render processing |
| 28 | import cairo | 29 | import cairo |
| 29 | import gi | 30 | import gi |
| 31 | |||
| 30 | gi.require_version('Poppler', '0.18') | 32 | gi.require_version('Poppler', '0.18') |
| 31 | from gi.repository import Poppler | 33 | from gi.repository import Poppler |
| 32 | import pdfrw | 34 | import pdfrw |
| @@ -42,9 +44,10 @@ except ImportError: | |||
| 42 | 44 | ||
| 43 | try: # exiftool | 45 | try: # exiftool |
| 44 | subprocess.check_output(['exiftool', '-ver']) | 46 | subprocess.check_output(['exiftool', '-ver']) |
| 45 | except: | 47 | except OSError: |
| 46 | FILE_LIST.remove(('clean é.tif', 'dirty é.tif')) | 48 | FILE_LIST.remove(('clean é.tif', 'dirty é.tif')) |
| 47 | 49 | ||
| 50 | |||
| 48 | class MATTest(unittest.TestCase): | 51 | class MATTest(unittest.TestCase): |
| 49 | """ | 52 | """ |
| 50 | Parent class of all test-functions | 53 | Parent class of all test-functions |
| @@ -84,26 +87,28 @@ def run_all_tests(): | |||
| 84 | """ | 87 | """ |
| 85 | import clitest | 88 | import clitest |
| 86 | import libtest | 89 | import libtest |
| 87 | SUITE = unittest.TestSuite() | 90 | suite = unittest.TestSuite() |
| 88 | SUITE.addTests(clitest.get_tests()) | 91 | suite.addTests(clitest.get_tests()) |
| 89 | SUITE.addTests(libtest.get_tests()) | 92 | suite.addTests(libtest.get_tests()) |
| 93 | |||
| 94 | return unittest.TextTestRunner(verbosity=VERBOSITY).run(suite).wasSuccessful() | ||
| 90 | 95 | ||
| 91 | return unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE).wasSuccessful() | ||
| 92 | 96 | ||
| 93 | def set_local(): | 97 | def set_local(): |
| 94 | ''' Monkey patch pathes to run the testsuite on the _local_ | 98 | """ Monkey patch pathes to run the testsuite on the _local_ |
| 95 | version of MAT. See `run_all_tests` for more information about | 99 | version of MAT. See `run_all_tests` for more information about |
| 96 | what pathes we're changing and why. | 100 | what pathes we're changing and why. |
| 97 | ''' | 101 | """ |
| 98 | os.environ['PATH'] = '..:' + os.environ['PATH'] | 102 | os.environ['PATH'] = '..:' + os.environ['PATH'] |
| 99 | sys.path.append('..') | 103 | sys.path.append('..') |
| 100 | 104 | ||
| 105 | |||
| 101 | if __name__ == '__main__': | 106 | if __name__ == '__main__': |
| 102 | import argparse | 107 | import argparse |
| 103 | 108 | ||
| 104 | parser = argparse.ArgumentParser(description='MAT testsuite') | 109 | parser = argparse.ArgumentParser(description='MAT testsuite') |
| 105 | parser.add_argument('-s', '--system', action='store_true', | 110 | parser.add_argument('-s', '--system', action='store_true', |
| 106 | help='Test the system-wide version of mat') | 111 | help='Test the system-wide version of mat') |
| 107 | 112 | ||
| 108 | if parser.parse_args().system is False: | 113 | if parser.parse_args().system is False: |
| 109 | set_local() | 114 | set_local() |
