Commit ff431ae3 authored by jvoisin's avatar jvoisin

More pep8 conformance

parent a646ebbd
......@@ -42,9 +42,9 @@ class PngStripper(parser.GenericParser):
'''
field_list = frozenset([
'id',
'header', # PNG header
'physical', # the intended pixel size or aspect ratio
'end']) # end of the image
'header', # PNG header
'physical', # the intended pixel size or aspect ratio
'end']) # end of the image
if field.name in field_list:
return False
if field.name.startswith('data['): # data
......
......@@ -31,6 +31,7 @@ logging.basicConfig(filename=fname, level=LOGGING_LEVEL)
import strippers # this is loaded here because we need LOGGING_LEVEL
def get_logo():
''' Return the path to the logo
'''
......@@ -41,6 +42,7 @@ def get_logo():
elif os.path.isfile('/usr/local/share/pixmaps/mat.png'):
return '/usr/local/share/pixmaps/mat.png'
def get_datadir():
''' Return the path to the data directory
'''
......@@ -51,6 +53,7 @@ def get_datadir():
elif os.path.isdir('/usr/share/mat/'):
return '/usr/share/mat/'
def list_supported_formats():
''' Return a list of all locally supported fileformat.
It parses that FORMATS file, and removes locally
......@@ -70,6 +73,7 @@ def list_supported_formats():
return localy_supported
class XMLParser(xml.sax.handler.ContentHandler):
''' Parse the supported format xml, and return a corresponding
list of dict
......@@ -132,7 +136,7 @@ def create_class_file(name, backup, **kwargs):
logging.error('%s is not a valid file' % name)
return None
if not os.access(name, os.R_OK): #check read permissions
if not os.access(name, os.R_OK): # check read permissions
logging.error('%s is is not readable' % name)
return None
......@@ -156,7 +160,7 @@ def create_class_file(name, backup, **kwargs):
if mime == 'application/zip': # some formats are zipped stuff
if mimetypes.guess_type(name)[0]:
mime = mimetypes.guess_type(name)[0]
mime = mimetypes.guess_type(name)[0]
if mime.startswith('application/vnd.oasis.opendocument'):
mime = 'application/opendocument' # opendocument fileformat
......
......@@ -19,7 +19,7 @@ class TorrentStripper(parser.GenericParser):
''' Get recursively all keys from a dict and
its subdicts
'''
for (i,j) in list(dictionary.items()):
for i, j in list(dictionary.items()):
if isinstance(j, dict):
return set([i]).union(self.__get_key_recursively(j))
return set([i])
......@@ -35,7 +35,7 @@ class TorrentStripper(parser.GenericParser):
''' Get recursively all harmful metadata
'''
d = dict()
for(i,j) in list(dictionary.items()):
for i, j in list(dictionary.items()):
if i not in self.fields:
d[i] = j
elif isinstance(j, dict):
......@@ -53,7 +53,7 @@ class TorrentStripper(parser.GenericParser):
''' Remove recursively all compromizing fields
'''
d = dict()
for (i,j) in [i for i in list(dictionary.items()) if i in self.fields]:
for i, j in [i for i in list(dictionary.items()) if i in self.fields]:
if isinstance(j, dict):
d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items()))
else:
......@@ -67,7 +67,7 @@ class TorrentStripper(parser.GenericParser):
with open(self.filename, 'r') as f:
decoded = bencode.bdecode(f.read())
cleaned = {i:j for i,j in list(decoded.items()) if i in self.fields}
cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields}
with open(self.output, 'w') as f: # encode the decoded torrent
f.write(bencode.bencode(cleaned)) # and write it in self.output
......
......@@ -11,11 +11,11 @@ import hachoir_editor
import mat
NOMETA = frozenset((
'.bmp', # "raw" image
'.rdf', # text
'.txt', # plain text
'.xml', # formated text (XML)
'.rels', # openXML formated text
'.bmp', # "raw" image
'.rdf', # text
'.txt', # plain text
'.xml', # formated text (XML)
'.rels', # openXML formated text
))
FIELD = object()
......
#! /usr/bin/python
''' This file is an extension for the Nautilus
file manager, to provide a contextual menu to
clean metadata
file manager, to provide a contextual menu to
clean metadata
'''
import logging
import os
import urllib
try:
import gettext
......@@ -15,13 +14,12 @@ except:
logging.warning("Failed to initialise gettext")
_ = lambda x: x
import xml.sax
from gi.repository import Nautilus, GObject, Gtk
import MAT.mat
import MAT.strippers
class MatExtension(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
logging.debug("nautilus-mat: initialising")
......@@ -44,7 +42,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider):
logging.debug("%s files not supported by MAT" % file.get_uri_scheme())
return
# MAT can not clean non-writable files
# MAT can not clean non-writable files
if not file.can_write():
logging.debug("%s is not writable by MAT" % file.get_uri_scheme())
return
......@@ -56,7 +54,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider):
item.connect('activate', self.menu_activate_cb, file)
return item,
def show_message(self, message, type = Gtk.MessageType.INFO):
def show_message(self, message, type=Gtk.MessageType.INFO):
dialog = Gtk.MessageDialog(parent=None,
flags=Gtk.DialogFlags.MODAL,
type=type,
......
......@@ -84,6 +84,7 @@ class TestFileAttributes(unittest.TestCase):
''' test MAT's behaviour on empty file'''
self.assertFalse(MAT.mat.create_class_file('empty_file', False, add2archive=True))
class TestSecureRemove(unittest.TestCase):
''' Test the secure_remove function
'''
......
......@@ -8,12 +8,12 @@
- remove the copy on end
'''
import shutil
import os
import glob
import tempfile
import unittest
import subprocess
VERBOSITY = 15
......@@ -39,6 +39,7 @@ except ImportError:
FILE_LIST.remove(('clean é.mp3', 'dirty é.mp3'))
FILE_LIST.remove(('clean é.flac', 'dirty é.flac'))
class MATTest(unittest.TestCase):
'''
Parent class of all test-functions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment