From ad31d77e6a199295ba44832abec35b054d04bced Mon Sep 17 00:00:00 2001
From: jvoisin
Date: Thu, 4 Aug 2011 16:12:22 +0200
Subject: Cleanup
---
cli.py | 1 +
gui.py | 27 +++++++++++++--------------
lib/archive.py | 8 +++++---
lib/office.py | 4 +---
lib/parser.py | 1 -
test/test.py | 7 +++----
6 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/cli.py b/cli.py
index 01b614d..a540258 100755
--- a/cli.py
+++ b/cli.py
@@ -123,6 +123,7 @@ def list_supported():
print('\n')
sys.exit(0)
+
def main():
'''
main function : get args, and launch the appropriate function
diff --git a/gui.py b/gui.py
index 66cf755..32b3469 100644
--- a/gui.py
+++ b/gui.py
@@ -196,15 +196,15 @@ class ListStoreApp:
chooser.set_default_response(0)
chooser.set_select_multiple(True)
- filter = gtk.FileFilter()
- filter.set_name('All files')
- filter.add_pattern('*')
- chooser.add_filter(filter)
+ all_filter = gtk.FileFilter()
+ all_filter.set_name('All files')
+ all_filter.add_pattern('*')
+ chooser.add_filter(all_filter)
- filter = gtk.FileFilter()
- [filter.add_mime_type(i) for i in mat.STRIPPERS.keys()]
- filter.set_name('Supported files')
- chooser.add_filter(filter)
+ supported_filter = gtk.FileFilter()
+ [supported_filter.add_mime_type(i) for i in mat.STRIPPERS.keys()]
+ supported_filter.set_name('Supported files')
+ chooser.add_filter(supported_filter)
response = chooser.run()
@@ -239,7 +239,7 @@ class ListStoreApp:
w.set_comments('This software was coded during the GSoC 2011')
w.set_website('https://gitweb.torproject.org/user/jvoisin/mat.git')
w.set_website_label('Website')
- w.set_authors(['Julien (jvoisin) Voisin',])
+ w.set_authors(['Julien (jvoisin) Voisin', ])
w.set_program_name('Metadata Anonymistion Toolkit')
click = w.run()
if click:
@@ -262,17 +262,16 @@ class ListStoreApp:
handler = mat.XMLParser()
parser = xml.sax.make_parser()
parser.setContentHandler(handler)
- with open('FORMATS', 'r') as f:
- parser.parse(f)
+ with open('FORMATS', 'r') as xmlfile:
+ parser.parse(xmlfile)
- for item in handler.list: # list of dict : one pict per format
+ for item in handler.list: # list of dict : one dict per format
#create one expander per format
title = '%s (%s)' % (item['name'], item['extension'])
support = '\tsupport : ' + item['support']
metadata = '\n\tmetadata : ' + item['metadata']
- method = '\n\tmethod : ' + item['method']
+ method = '\n\tmethod : ' + item['method']
content = support + metadata + method
-
if item['support'] == 'partial':
content += '\n\tremaining : ' + item['remaining']
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 @@
'''
Take care of archives formats
'''
-import tarfile
-import zipfile
+import zipfile
import shutil
import os
import logging
@@ -11,7 +10,7 @@ import tempfile
import parser
import mat
-
+import tarfile
class GenericArchiveStripper(parser.GenericParser):
'''
@@ -224,6 +223,7 @@ class TarStripper(GenericArchiveStripper):
tarin = tarfile.open(self.filename, 'r' + self.compression)
for item in tarin.getmembers():
if not self.is_file_clean(item):
+ tarin.close()
return False
tarin.extract(item, self.tempdir)
name = os.path.join(self.tempdir, item.name)
@@ -233,12 +233,14 @@ class TarStripper(GenericArchiveStripper):
class_file = mat.create_class_file(name,
False, self.add2archive)
if not class_file.is_clean():
+ tarin.close()
return False
except:
#best solution I have found
logging.error('%s is not supported' % item.filename)
_, ext = os.path.splitext(name)
if ext not in parser.NOMETA:
+ tarin.close()
return False
mat.secure_remove(name)
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):
zipin.close()
czf = archive.ZipStripper(self.filename, self.parser,
'application/zip', self.backup, self.add2archive)
- if czf.is_clean():
- return True
- else:
+ if not czf.is_clean():
return False
return True
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):
self.output = basename + '.cleaned' + ext
self.basename = os.path.basename(filename) # only filename
-
def is_clean(self):
'''
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 @@
'''
Class for the testing suite :
- - get the list of all test files
- - create a copy of them on start
- - remove the copy on end
+ - get the list of all test files
+ - create a copy of them on start
+ - remove the copy on end
'''
import shutil
import os
import glob
-import sys
import tempfile
import unittest
--
cgit v1.3