From 68e490c9efd0885deca76e5eed5247f87aa8f733 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 6 Jan 2014 23:30:28 +0000 Subject: GUI-archive-unsupported-handling, 2nd iteration --- MAT/archive.py | 21 +++++++++------------ MAT/office.py | 2 +- mat-gui | 36 +++++++++++++++--------------------- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/MAT/archive.py b/MAT/archive.py index e6f9e14..9179e48 100644 --- a/MAT/archive.py +++ b/MAT/archive.py @@ -172,8 +172,8 @@ class TarStripper(GenericArchiveStripper): tarout = tarfile.open(self.output, 'w' + self.compression, encoding='utf-8') for item in tarin.getmembers(): tarin.extract(item, self.tempdir) - complete_name = os.path.join(self.tempdir, item.name) if item.isfile(): + complete_name = os.path.join(self.tempdir, item.name) cfile = mat.create_class_file(complete_name, False, add2archive=self.add2archive) if cfile: cfile.remove_all() @@ -209,7 +209,7 @@ class TarStripper(GenericArchiveStripper): ''' if list_unsupported: ret_list = [] - tmp_len = len(self.tempdir) + 1 # trim the tempfile path + tempdir_len = len(self.tempdir) + 1 # trim the tempfile path tarin = tarfile.open(self.filename, 'r' + self.compression) for item in tarin.getmembers(): if not self.is_file_clean(item) and not list_unsupported: @@ -219,21 +219,18 @@ class TarStripper(GenericArchiveStripper): if item.isfile(): class_file = mat.create_class_file(complete_name, False, add2archive=self.add2archive) if class_file: + # We don't support nested archives if not class_file.is_clean(): - # We don't support nested archives - if list_unsupported: - if isinstance(class_file, GenericArchiveStripper): - ret_list.append(complete_name[tmp_len:]) - else: + if not list_unsupported: return False + elif isinstance(class_file, GenericArchiveStripper): + ret_list.append(complete_name[tempdir_len:]) else: logging.error('%s\'s format is not supported or harmless' % item.name) - basename, ext = os.path.splitext(complete_name) - if ext not in parser.NOMETA: - if list_unsupported: - ret_list.append(complete_name[tmp_len:]) - else: + if os.path.splitext(complete_name)[1] not in parser.NOMETA: + if not list_unsupported: return False + ret_list.append(complete_name[tempdir_len:]) tarin.close() if list_unsupported: return ret_list diff --git a/MAT/office.py b/MAT/office.py index 91e49be..f60fc64 100644 --- a/MAT/office.py +++ b/MAT/office.py @@ -21,7 +21,7 @@ import parser import archive -class OpenDocumentStripper(archive.GenericArchiveStripper): +class OpenDocumentStripper(archive.ZipStripper): ''' An open document file is a zip, with xml file into. The one that interest us is meta.xml ''' diff --git a/mat-gui b/mat-gui index a1cb446..de0da83 100755 --- a/mat-gui +++ b/mat-gui @@ -10,7 +10,6 @@ import gettext import logging import os import sys -import mimetypes import xml.sax import urllib2 @@ -69,11 +68,11 @@ class GUI(object): def __init_supported_popup(self): ''' Initialise the "supported formats" popup ''' self.supported_dict = mat.XMLParser() - parser = xml.sax.make_parser() - parser.setContentHandler(self.supported_dict) + xml_parser = xml.sax.make_parser() + xml_parser.setContentHandler(self.supported_dict) path = os.path.join(mat.get_datadir(), 'FORMATS') with open(path, 'r') as xmlfile: - parser.parse(xmlfile) + xml_parser.parse(xmlfile) supported_cbox = self.builder.get_object('supported_cbox') store = Gtk.ListStore(int, str) @@ -110,8 +109,7 @@ class GUI(object): ''' Fill GtkEntries of the supported_format_popups with corresponding data. ''' - i = window.get_active_iter() - index = window.get_model()[i][0] + index = window.get_model()[window.get_active_iter()][0] support = self.builder.get_object('supported_support') support.set_text(self.supported_dict.list[index]['support']) metadata = self.builder.get_object('supported_metadata').get_buffer() @@ -234,14 +232,13 @@ non-anonymised) file to output archive')) hbox.show_all() if not dialog.run(): # Gtk.STOCK_OK - for file in self.liststore: # update preferences - file[0].file.add2archive = self.add2archive - if file[0].file.mime.startswith('pdf'): - file[0].file.pdf_quality = self.pdf_quality + for f in self.liststore: # update preferences + f[0].file.add2archive = self.add2archive + if f[0].file.mime.startswith('pdf'): + f[0].file.pdf_quality = self.pdf_quality dialog.hide() - def cb_drag_data_received(self, widget, context, - x, y, selection, target_type, timestamp): + def cb_drag_data_received(self, widget, context, x, y, selection, target_type, timestamp): ''' This function is called when something is drag'n'droped into mat. It basically add files. @@ -266,9 +263,7 @@ non-anonymised) file to output archive')) def __add_file_to_treeview(self, filename): ''' Add a file to the list if its format is supported ''' - cf = CFile(filename, add2archive=self.add2archive, - low_pdf_quality=self.pdf_quality) - # if the file is supported by the mat, and is writable (for usability's sake). + cf = CFile(filename, add2archive=self.add2archive, low_pdf_quality=self.pdf_quality) if cf.file and cf.file.is_writable: self.liststore.append([cf, cf.file.basename, _('Unknown')]) return False @@ -325,8 +320,7 @@ non-anonymised) file to output archive')) # appends "filename - reason" to the ListStore for item in filelist: - ext = os.path.splitext(item)[1] - if ext in parser.NOMETA: + if os.path.splitext(item)[1] in parser.NOMETA: store.append([os.path.basename(item), _('Harmless fileformat')]) else: store.append([os.path.basename(item), _('Fileformat not supported')]) @@ -372,14 +366,14 @@ non-anonymised) file to output archive')) cellrenderer_text = Gtk.CellRendererText() column_text.pack_start(cellrenderer_text, False) - column_text.add_attribute(cellrenderer_text, "text", 1) + column_text.add_attribute(cellrenderer_text, 'text', 1) cellrenderer_toggle = Gtk.CellRendererToggle() column_toggle.pack_start(cellrenderer_toggle, True) - column_toggle.add_attribute(cellrenderer_toggle, "active", 0) + column_toggle.add_attribute(cellrenderer_toggle, 'active', 0) def cell_toggled(widget, path, model): model[path][0] = not model[path][0] - cellrenderer_toggle.connect("toggled", cell_toggled, store) + cellrenderer_toggle.connect('toggled', cell_toggled, store) vbox.pack_start(treeview, True, True, 0) vbox.pack_start(Gtk.Label(_('Thoses files are not recognized by MAT, and' @@ -433,6 +427,6 @@ if __name__ == '__main__': infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] if infiles: task = gui.populate(infiles) - Glib.idle_add(task.next) + GLib.idle_add(task.next) Gtk.main() -- cgit v1.3