diff options
| -rw-r--r-- | MAT/images.py | 6 | ||||
| -rw-r--r-- | MAT/mat.py | 8 | ||||
| -rw-r--r-- | MAT/misc.py | 8 | ||||
| -rw-r--r-- | MAT/parser.py | 10 | ||||
| -rw-r--r-- | nautilus/nautilus-mat.py | 12 | ||||
| -rw-r--r-- | test/libtest.py | 1 | ||||
| -rw-r--r-- | test/test.py | 3 |
7 files changed, 26 insertions, 22 deletions
diff --git a/MAT/images.py b/MAT/images.py index dc96e6a..67c710f 100644 --- a/MAT/images.py +++ b/MAT/images.py | |||
| @@ -42,9 +42,9 @@ class PngStripper(parser.GenericParser): | |||
| 42 | ''' | 42 | ''' |
| 43 | field_list = frozenset([ | 43 | field_list = frozenset([ |
| 44 | 'id', | 44 | 'id', |
| 45 | 'header', # PNG header | 45 | 'header', # PNG header |
| 46 | 'physical', # the intended pixel size or aspect ratio | 46 | 'physical', # the intended pixel size or aspect ratio |
| 47 | 'end']) # end of the image | 47 | 'end']) # end of the image |
| 48 | if field.name in field_list: | 48 | if field.name in field_list: |
| 49 | return False | 49 | return False |
| 50 | if field.name.startswith('data['): # data | 50 | if field.name.startswith('data['): # data |
| @@ -31,6 +31,7 @@ logging.basicConfig(filename=fname, level=LOGGING_LEVEL) | |||
| 31 | 31 | ||
| 32 | import strippers # this is loaded here because we need LOGGING_LEVEL | 32 | import strippers # this is loaded here because we need LOGGING_LEVEL |
| 33 | 33 | ||
| 34 | |||
| 34 | def get_logo(): | 35 | def get_logo(): |
| 35 | ''' Return the path to the logo | 36 | ''' Return the path to the logo |
| 36 | ''' | 37 | ''' |
| @@ -41,6 +42,7 @@ def get_logo(): | |||
| 41 | elif os.path.isfile('/usr/local/share/pixmaps/mat.png'): | 42 | elif os.path.isfile('/usr/local/share/pixmaps/mat.png'): |
| 42 | return '/usr/local/share/pixmaps/mat.png' | 43 | return '/usr/local/share/pixmaps/mat.png' |
| 43 | 44 | ||
| 45 | |||
| 44 | def get_datadir(): | 46 | def get_datadir(): |
| 45 | ''' Return the path to the data directory | 47 | ''' Return the path to the data directory |
| 46 | ''' | 48 | ''' |
| @@ -51,6 +53,7 @@ def get_datadir(): | |||
| 51 | elif os.path.isdir('/usr/share/mat/'): | 53 | elif os.path.isdir('/usr/share/mat/'): |
| 52 | return '/usr/share/mat/' | 54 | return '/usr/share/mat/' |
| 53 | 55 | ||
| 56 | |||
| 54 | def list_supported_formats(): | 57 | def list_supported_formats(): |
| 55 | ''' Return a list of all locally supported fileformat. | 58 | ''' Return a list of all locally supported fileformat. |
| 56 | It parses that FORMATS file, and removes locally | 59 | It parses that FORMATS file, and removes locally |
| @@ -70,6 +73,7 @@ def list_supported_formats(): | |||
| 70 | 73 | ||
| 71 | return localy_supported | 74 | return localy_supported |
| 72 | 75 | ||
| 76 | |||
| 73 | class XMLParser(xml.sax.handler.ContentHandler): | 77 | class XMLParser(xml.sax.handler.ContentHandler): |
| 74 | ''' Parse the supported format xml, and return a corresponding | 78 | ''' Parse the supported format xml, and return a corresponding |
| 75 | list of dict | 79 | list of dict |
| @@ -132,7 +136,7 @@ def create_class_file(name, backup, **kwargs): | |||
| 132 | logging.error('%s is not a valid file' % name) | 136 | logging.error('%s is not a valid file' % name) |
| 133 | return None | 137 | return None |
| 134 | 138 | ||
| 135 | if not os.access(name, os.R_OK): #check read permissions | 139 | if not os.access(name, os.R_OK): # check read permissions |
| 136 | logging.error('%s is is not readable' % name) | 140 | logging.error('%s is is not readable' % name) |
| 137 | return None | 141 | return None |
| 138 | 142 | ||
| @@ -156,7 +160,7 @@ def create_class_file(name, backup, **kwargs): | |||
| 156 | 160 | ||
| 157 | if mime == 'application/zip': # some formats are zipped stuff | 161 | if mime == 'application/zip': # some formats are zipped stuff |
| 158 | if mimetypes.guess_type(name)[0]: | 162 | if mimetypes.guess_type(name)[0]: |
| 159 | mime = mimetypes.guess_type(name)[0] | 163 | mime = mimetypes.guess_type(name)[0] |
| 160 | 164 | ||
| 161 | if mime.startswith('application/vnd.oasis.opendocument'): | 165 | if mime.startswith('application/vnd.oasis.opendocument'): |
| 162 | mime = 'application/opendocument' # opendocument fileformat | 166 | mime = 'application/opendocument' # opendocument fileformat |
diff --git a/MAT/misc.py b/MAT/misc.py index 3f24ece..450f381 100644 --- a/MAT/misc.py +++ b/MAT/misc.py | |||
| @@ -19,7 +19,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 19 | ''' Get recursively all keys from a dict and | 19 | ''' Get recursively all keys from a dict and |
| 20 | its subdicts | 20 | its subdicts |
| 21 | ''' | 21 | ''' |
| 22 | for (i,j) in list(dictionary.items()): | 22 | for i, j in list(dictionary.items()): |
| 23 | if isinstance(j, dict): | 23 | if isinstance(j, dict): |
| 24 | return set([i]).union(self.__get_key_recursively(j)) | 24 | return set([i]).union(self.__get_key_recursively(j)) |
| 25 | return set([i]) | 25 | return set([i]) |
| @@ -35,7 +35,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 35 | ''' Get recursively all harmful metadata | 35 | ''' Get recursively all harmful metadata |
| 36 | ''' | 36 | ''' |
| 37 | d = dict() | 37 | d = dict() |
| 38 | for(i,j) in list(dictionary.items()): | 38 | for i, j in list(dictionary.items()): |
| 39 | if i not in self.fields: | 39 | if i not in self.fields: |
| 40 | d[i] = j | 40 | d[i] = j |
| 41 | elif isinstance(j, dict): | 41 | elif isinstance(j, dict): |
| @@ -53,7 +53,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 53 | ''' Remove recursively all compromizing fields | 53 | ''' Remove recursively all compromizing fields |
| 54 | ''' | 54 | ''' |
| 55 | d = dict() | 55 | d = dict() |
| 56 | for (i,j) in [i for i in list(dictionary.items()) if i in self.fields]: | 56 | for i, j in [i for i in list(dictionary.items()) if i in self.fields]: |
| 57 | if isinstance(j, dict): | 57 | if isinstance(j, dict): |
| 58 | d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) | 58 | d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) |
| 59 | else: | 59 | else: |
| @@ -67,7 +67,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 67 | with open(self.filename, 'r') as f: | 67 | with open(self.filename, 'r') as f: |
| 68 | decoded = bencode.bdecode(f.read()) | 68 | decoded = bencode.bdecode(f.read()) |
| 69 | 69 | ||
| 70 | cleaned = {i:j for i,j in list(decoded.items()) if i in self.fields} | 70 | cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields} |
| 71 | 71 | ||
| 72 | with open(self.output, 'w') as f: # encode the decoded torrent | 72 | with open(self.output, 'w') as f: # encode the decoded torrent |
| 73 | f.write(bencode.bencode(cleaned)) # and write it in self.output | 73 | f.write(bencode.bencode(cleaned)) # and write it in self.output |
diff --git a/MAT/parser.py b/MAT/parser.py index 8ef5aba..1765da8 100644 --- a/MAT/parser.py +++ b/MAT/parser.py | |||
| @@ -11,11 +11,11 @@ import hachoir_editor | |||
| 11 | import mat | 11 | import mat |
| 12 | 12 | ||
| 13 | NOMETA = frozenset(( | 13 | NOMETA = frozenset(( |
| 14 | '.bmp', # "raw" image | 14 | '.bmp', # "raw" image |
| 15 | '.rdf', # text | 15 | '.rdf', # text |
| 16 | '.txt', # plain text | 16 | '.txt', # plain text |
| 17 | '.xml', # formated text (XML) | 17 | '.xml', # formated text (XML) |
| 18 | '.rels', # openXML formated text | 18 | '.rels', # openXML formated text |
| 19 | )) | 19 | )) |
| 20 | 20 | ||
| 21 | FIELD = object() | 21 | FIELD = object() |
diff --git a/nautilus/nautilus-mat.py b/nautilus/nautilus-mat.py index 2a84600..19b601e 100644 --- a/nautilus/nautilus-mat.py +++ b/nautilus/nautilus-mat.py | |||
| @@ -1,12 +1,11 @@ | |||
| 1 | #! /usr/bin/python | 1 | #! /usr/bin/python |
| 2 | 2 | ||
| 3 | ''' This file is an extension for the Nautilus | 3 | ''' This file is an extension for the Nautilus |
| 4 | file manager, to provide a contextual menu to | 4 | file manager, to provide a contextual menu to |
| 5 | clean metadata | 5 | clean metadata |
| 6 | ''' | 6 | ''' |
| 7 | 7 | ||
| 8 | import logging | 8 | import logging |
| 9 | import os | ||
| 10 | import urllib | 9 | import urllib |
| 11 | try: | 10 | try: |
| 12 | import gettext | 11 | import gettext |
| @@ -15,13 +14,12 @@ except: | |||
| 15 | logging.warning("Failed to initialise gettext") | 14 | logging.warning("Failed to initialise gettext") |
| 16 | _ = lambda x: x | 15 | _ = lambda x: x |
| 17 | 16 | ||
| 18 | import xml.sax | ||
| 19 | |||
| 20 | from gi.repository import Nautilus, GObject, Gtk | 17 | from gi.repository import Nautilus, GObject, Gtk |
| 21 | 18 | ||
| 22 | import MAT.mat | 19 | import MAT.mat |
| 23 | import MAT.strippers | 20 | import MAT.strippers |
| 24 | 21 | ||
| 22 | |||
| 25 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): | 23 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): |
| 26 | def __init__(self): | 24 | def __init__(self): |
| 27 | logging.debug("nautilus-mat: initialising") | 25 | logging.debug("nautilus-mat: initialising") |
| @@ -44,7 +42,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): | |||
| 44 | logging.debug("%s files not supported by MAT" % file.get_uri_scheme()) | 42 | logging.debug("%s files not supported by MAT" % file.get_uri_scheme()) |
| 45 | return | 43 | return |
| 46 | 44 | ||
| 47 | # MAT can not clean non-writable files | 45 | # MAT can not clean non-writable files |
| 48 | if not file.can_write(): | 46 | if not file.can_write(): |
| 49 | logging.debug("%s is not writable by MAT" % file.get_uri_scheme()) | 47 | logging.debug("%s is not writable by MAT" % file.get_uri_scheme()) |
| 50 | return | 48 | return |
| @@ -56,7 +54,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): | |||
| 56 | item.connect('activate', self.menu_activate_cb, file) | 54 | item.connect('activate', self.menu_activate_cb, file) |
| 57 | return item, | 55 | return item, |
| 58 | 56 | ||
| 59 | def show_message(self, message, type = Gtk.MessageType.INFO): | 57 | def show_message(self, message, type=Gtk.MessageType.INFO): |
| 60 | dialog = Gtk.MessageDialog(parent=None, | 58 | dialog = Gtk.MessageDialog(parent=None, |
| 61 | flags=Gtk.DialogFlags.MODAL, | 59 | flags=Gtk.DialogFlags.MODAL, |
| 62 | type=type, | 60 | type=type, |
diff --git a/test/libtest.py b/test/libtest.py index acf8659..f92d933 100644 --- a/test/libtest.py +++ b/test/libtest.py | |||
| @@ -84,6 +84,7 @@ class TestFileAttributes(unittest.TestCase): | |||
| 84 | ''' test MAT's behaviour on empty file''' | 84 | ''' test MAT's behaviour on empty file''' |
| 85 | self.assertFalse(MAT.mat.create_class_file('empty_file', False, add2archive=True)) | 85 | self.assertFalse(MAT.mat.create_class_file('empty_file', False, add2archive=True)) |
| 86 | 86 | ||
| 87 | |||
| 87 | class TestSecureRemove(unittest.TestCase): | 88 | class TestSecureRemove(unittest.TestCase): |
| 88 | ''' Test the secure_remove function | 89 | ''' Test the secure_remove function |
| 89 | ''' | 90 | ''' |
diff --git a/test/test.py b/test/test.py index 0b7996b..1641f88 100644 --- a/test/test.py +++ b/test/test.py | |||
| @@ -8,12 +8,12 @@ | |||
| 8 | - remove the copy on end | 8 | - remove the copy on end |
| 9 | ''' | 9 | ''' |
| 10 | 10 | ||
| 11 | |||
| 11 | import shutil | 12 | import shutil |
| 12 | import os | 13 | import os |
| 13 | import glob | 14 | import glob |
| 14 | import tempfile | 15 | import tempfile |
| 15 | import unittest | 16 | import unittest |
| 16 | import subprocess | ||
| 17 | 17 | ||
| 18 | VERBOSITY = 15 | 18 | VERBOSITY = 15 |
| 19 | 19 | ||
| @@ -39,6 +39,7 @@ except ImportError: | |||
| 39 | FILE_LIST.remove(('clean é.mp3', 'dirty é.mp3')) | 39 | FILE_LIST.remove(('clean é.mp3', 'dirty é.mp3')) |
| 40 | FILE_LIST.remove(('clean é.flac', 'dirty é.flac')) | 40 | FILE_LIST.remove(('clean é.flac', 'dirty é.flac')) |
| 41 | 41 | ||
| 42 | |||
| 42 | class MATTest(unittest.TestCase): | 43 | class MATTest(unittest.TestCase): |
| 43 | ''' | 44 | ''' |
| 44 | Parent class of all test-functions | 45 | Parent class of all test-functions |
