summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2014-01-06 23:30:28 +0000
committerjvoisin2014-01-06 23:30:28 +0000
commit68e490c9efd0885deca76e5eed5247f87aa8f733 (patch)
treeadcb4d8ebbd55294f52aa32cc26e84f24e6b66a0
parent9c44ef035133d928afa4cbc41e40883b7460d210 (diff)
GUI-archive-unsupported-handling, 2nd iteration
-rw-r--r--MAT/archive.py21
-rw-r--r--MAT/office.py2
-rwxr-xr-xmat-gui36
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):
172 tarout = tarfile.open(self.output, 'w' + self.compression, encoding='utf-8') 172 tarout = tarfile.open(self.output, 'w' + self.compression, encoding='utf-8')
173 for item in tarin.getmembers(): 173 for item in tarin.getmembers():
174 tarin.extract(item, self.tempdir) 174 tarin.extract(item, self.tempdir)
175 complete_name = os.path.join(self.tempdir, item.name)
176 if item.isfile(): 175 if item.isfile():
176 complete_name = os.path.join(self.tempdir, item.name)
177 cfile = mat.create_class_file(complete_name, False, add2archive=self.add2archive) 177 cfile = mat.create_class_file(complete_name, False, add2archive=self.add2archive)
178 if cfile: 178 if cfile:
179 cfile.remove_all() 179 cfile.remove_all()
@@ -209,7 +209,7 @@ class TarStripper(GenericArchiveStripper):
209 ''' 209 '''
210 if list_unsupported: 210 if list_unsupported:
211 ret_list = [] 211 ret_list = []
212 tmp_len = len(self.tempdir) + 1 # trim the tempfile path 212 tempdir_len = len(self.tempdir) + 1 # trim the tempfile path
213 tarin = tarfile.open(self.filename, 'r' + self.compression) 213 tarin = tarfile.open(self.filename, 'r' + self.compression)
214 for item in tarin.getmembers(): 214 for item in tarin.getmembers():
215 if not self.is_file_clean(item) and not list_unsupported: 215 if not self.is_file_clean(item) and not list_unsupported:
@@ -219,21 +219,18 @@ class TarStripper(GenericArchiveStripper):
219 if item.isfile(): 219 if item.isfile():
220 class_file = mat.create_class_file(complete_name, False, add2archive=self.add2archive) 220 class_file = mat.create_class_file(complete_name, False, add2archive=self.add2archive)
221 if class_file: 221 if class_file:
222 # We don't support nested archives
222 if not class_file.is_clean(): 223 if not class_file.is_clean():
223 # We don't support nested archives 224 if not list_unsupported:
224 if list_unsupported:
225 if isinstance(class_file, GenericArchiveStripper):
226 ret_list.append(complete_name[tmp_len:])
227 else:
228 return False 225 return False
226 elif isinstance(class_file, GenericArchiveStripper):
227 ret_list.append(complete_name[tempdir_len:])
229 else: 228 else:
230 logging.error('%s\'s format is not supported or harmless' % item.name) 229 logging.error('%s\'s format is not supported or harmless' % item.name)
231 basename, ext = os.path.splitext(complete_name) 230 if os.path.splitext(complete_name)[1] not in parser.NOMETA:
232 if ext not in parser.NOMETA: 231 if not list_unsupported:
233 if list_unsupported:
234 ret_list.append(complete_name[tmp_len:])
235 else:
236 return False 232 return False
233 ret_list.append(complete_name[tempdir_len:])
237 tarin.close() 234 tarin.close()
238 if list_unsupported: 235 if list_unsupported:
239 return ret_list 236 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
21import archive 21import archive
22 22
23 23
24class OpenDocumentStripper(archive.GenericArchiveStripper): 24class OpenDocumentStripper(archive.ZipStripper):
25 ''' An open document file is a zip, with xml file into. 25 ''' An open document file is a zip, with xml file into.
26 The one that interest us is meta.xml 26 The one that interest us is meta.xml
27 ''' 27 '''
diff --git a/mat-gui b/mat-gui
index a1cb446..de0da83 100755
--- a/mat-gui
+++ b/mat-gui
@@ -10,7 +10,6 @@ import gettext
10import logging 10import logging
11import os 11import os
12import sys 12import sys
13import mimetypes
14import xml.sax 13import xml.sax
15import urllib2 14import urllib2
16 15
@@ -69,11 +68,11 @@ class GUI(object):
69 def __init_supported_popup(self): 68 def __init_supported_popup(self):
70 ''' Initialise the "supported formats" popup ''' 69 ''' Initialise the "supported formats" popup '''
71 self.supported_dict = mat.XMLParser() 70 self.supported_dict = mat.XMLParser()
72 parser = xml.sax.make_parser() 71 xml_parser = xml.sax.make_parser()
73 parser.setContentHandler(self.supported_dict) 72 xml_parser.setContentHandler(self.supported_dict)
74 path = os.path.join(mat.get_datadir(), 'FORMATS') 73 path = os.path.join(mat.get_datadir(), 'FORMATS')
75 with open(path, 'r') as xmlfile: 74 with open(path, 'r') as xmlfile:
76 parser.parse(xmlfile) 75 xml_parser.parse(xmlfile)
77 76
78 supported_cbox = self.builder.get_object('supported_cbox') 77 supported_cbox = self.builder.get_object('supported_cbox')
79 store = Gtk.ListStore(int, str) 78 store = Gtk.ListStore(int, str)
@@ -110,8 +109,7 @@ class GUI(object):
110 ''' Fill GtkEntries of the supported_format_popups 109 ''' Fill GtkEntries of the supported_format_popups
111 with corresponding data. 110 with corresponding data.
112 ''' 111 '''
113 i = window.get_active_iter() 112 index = window.get_model()[window.get_active_iter()][0]
114 index = window.get_model()[i][0]
115 support = self.builder.get_object('supported_support') 113 support = self.builder.get_object('supported_support')
116 support.set_text(self.supported_dict.list[index]['support']) 114 support.set_text(self.supported_dict.list[index]['support'])
117 metadata = self.builder.get_object('supported_metadata').get_buffer() 115 metadata = self.builder.get_object('supported_metadata').get_buffer()
@@ -234,14 +232,13 @@ non-anonymised) file to output archive'))
234 232
235 hbox.show_all() 233 hbox.show_all()
236 if not dialog.run(): # Gtk.STOCK_OK 234 if not dialog.run(): # Gtk.STOCK_OK
237 for file in self.liststore: # update preferences 235 for f in self.liststore: # update preferences
238 file[0].file.add2archive = self.add2archive 236 f[0].file.add2archive = self.add2archive
239 if file[0].file.mime.startswith('pdf'): 237 if f[0].file.mime.startswith('pdf'):
240 file[0].file.pdf_quality = self.pdf_quality 238 f[0].file.pdf_quality = self.pdf_quality
241 dialog.hide() 239 dialog.hide()
242 240
243 def cb_drag_data_received(self, widget, context, 241 def cb_drag_data_received(self, widget, context, x, y, selection, target_type, timestamp):
244 x, y, selection, target_type, timestamp):
245 ''' This function is called when something is 242 ''' This function is called when something is
246 drag'n'droped into mat. 243 drag'n'droped into mat.
247 It basically add files. 244 It basically add files.
@@ -266,9 +263,7 @@ non-anonymised) file to output archive'))
266 263
267 def __add_file_to_treeview(self, filename): 264 def __add_file_to_treeview(self, filename):
268 ''' Add a file to the list if its format is supported ''' 265 ''' Add a file to the list if its format is supported '''
269 cf = CFile(filename, add2archive=self.add2archive, 266 cf = CFile(filename, add2archive=self.add2archive, low_pdf_quality=self.pdf_quality)
270 low_pdf_quality=self.pdf_quality)
271 # if the file is supported by the mat, and is writable (for usability's sake).
272 if cf.file and cf.file.is_writable: 267 if cf.file and cf.file.is_writable:
273 self.liststore.append([cf, cf.file.basename, _('Unknown')]) 268 self.liststore.append([cf, cf.file.basename, _('Unknown')])
274 return False 269 return False
@@ -325,8 +320,7 @@ non-anonymised) file to output archive'))
325 320
326 # appends "filename - reason" to the ListStore 321 # appends "filename - reason" to the ListStore
327 for item in filelist: 322 for item in filelist:
328 ext = os.path.splitext(item)[1] 323 if os.path.splitext(item)[1] in parser.NOMETA:
329 if ext in parser.NOMETA:
330 store.append([os.path.basename(item), _('Harmless fileformat')]) 324 store.append([os.path.basename(item), _('Harmless fileformat')])
331 else: 325 else:
332 store.append([os.path.basename(item), _('Fileformat not supported')]) 326 store.append([os.path.basename(item), _('Fileformat not supported')])
@@ -372,14 +366,14 @@ non-anonymised) file to output archive'))
372 366
373 cellrenderer_text = Gtk.CellRendererText() 367 cellrenderer_text = Gtk.CellRendererText()
374 column_text.pack_start(cellrenderer_text, False) 368 column_text.pack_start(cellrenderer_text, False)
375 column_text.add_attribute(cellrenderer_text, "text", 1) 369 column_text.add_attribute(cellrenderer_text, 'text', 1)
376 370
377 cellrenderer_toggle = Gtk.CellRendererToggle() 371 cellrenderer_toggle = Gtk.CellRendererToggle()
378 column_toggle.pack_start(cellrenderer_toggle, True) 372 column_toggle.pack_start(cellrenderer_toggle, True)
379 column_toggle.add_attribute(cellrenderer_toggle, "active", 0) 373 column_toggle.add_attribute(cellrenderer_toggle, 'active', 0)
380 def cell_toggled(widget, path, model): 374 def cell_toggled(widget, path, model):
381 model[path][0] = not model[path][0] 375 model[path][0] = not model[path][0]
382 cellrenderer_toggle.connect("toggled", cell_toggled, store) 376 cellrenderer_toggle.connect('toggled', cell_toggled, store)
383 377
384 vbox.pack_start(treeview, True, True, 0) 378 vbox.pack_start(treeview, True, True, 0)
385 vbox.pack_start(Gtk.Label(_('Thoses files are not recognized by MAT, and' 379 vbox.pack_start(Gtk.Label(_('Thoses files are not recognized by MAT, and'
@@ -433,6 +427,6 @@ if __name__ == '__main__':
433 infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)] 427 infiles = [arg for arg in sys.argv[1:] if os.path.exists(arg)]
434 if infiles: 428 if infiles:
435 task = gui.populate(infiles) 429 task = gui.populate(infiles)
436 Glib.idle_add(task.next) 430 GLib.idle_add(task.next)
437 431
438 Gtk.main() 432 Gtk.main()