[Tails-dev] MAT nautilus

Borrar esta mensaxe

Responder a esta mensaxe
Autor: alan
Data:  
Para: tails-dev
Asunto: [Tails-dev] MAT nautilus

Hi,

I had fun writing a basic MAT nautilus extension. It works fine for me
under Tails, with nautilus 2.x.

For now, it doesn't work with nautilus 3.x under wheezy. If I understood
the problem well, Nautilus 3.x imports Gtk through GI, while poppler and
cairo (imported by MAT) import Gtk2 through python bindings. Result:

    /usr/lib/python2.7/dist-packages/gobject/constants.py:24: Warning: g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
      import gobject._gobject
    /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for type `PyGtkGenericCellRenderer' is smaller than the parent type's `GtkCellRenderer' class size
      from gtk import _gtk
    /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion `node != NULL' failed
      from gtk import _gtk
    Segmentation fault


Cheers,

Alan



--
From 55f39caa0823c123a89aba3e04a728bed32f7b60 Mon Sep 17 00:00:00 2001
From: Tails developers <amnesia@???>
Date: Fri, 10 Aug 2012 10:21:05 +0200
Subject: [PATCH] Add nautilus 2.x extension

---
 nautilus2-mat.py |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 setup.py         |    1 +
 2 files changed, 92 insertions(+)
 create mode 100644 nautilus2-mat.py


diff --git a/nautilus2-mat.py b/nautilus2-mat.py
new file mode 100644
index 0000000..c5bc6ac
--- /dev/null
+++ b/nautilus2-mat.py
@@ -0,0 +1,91 @@
+#! /usr/bin/python
+
+import os
+import urllib
+import logging
+import gettext
+gettext.install("mat")
+
+import xml.sax
+import nautilus
+import gtk
+
+# mat package is called lib
+import lib.mat as mat
+import lib.strippers as strippers
+
+class MatExtension(nautilus.MenuProvider):
+    def __init__(self):
+        logging.debug("nautilus-mat: initializing")
+        pass
+
+    def get_file_items(self, window, files):
+        if len(files) != 1:
+            return
+
+        file = files[0]
+
+        # We're only going to put ourselves on supported mimetypes' context menus
+        if not file.get_mime_type() in [i["mimetype"] for i in self.__list_supported()]:
+            logging.debug("%s is not supported by MAT" % file.get_mime_type())
+            return
+
+        # MAT can only handle local file:
+        if file.get_uri_scheme() != 'file':
+            ligging.debug("%s files not supported by MAT" % file.get_uri_scheme())
+            return
+
+        item = nautilus.MenuItem(name="Nautilus::clean_metadata",
+                                 label=_("Clean metadata"),
+                                 tip=_("Clean file's metadata with MAT"))
+        item.connect('activate', self.menu_activate_cb, file)
+        return item,
+
+    def show_message(self, message, type = gtk.MESSAGE_INFO):
+        dialog = gtk.MessageDialog(parent=None,
+                                   flags=gtk.DIALOG_MODAL,
+                                   type=type,
+                                   buttons=gtk.BUTTONS_OK,
+                                   message_format=message)
+        ret = dialog.run()
+        dialog.destroy()
+        return ret
+
+    # Convenience functions that should be merged into MAT core
+    def __list_supported(self):
+        '''
+            Print all supported fileformat, and exit
+        '''
+        handler = mat.XMLParser()
+        parser = xml.sax.make_parser()
+        parser.setContentHandler(handler)
+        path = os.path.join(mat.get_sharedir('FORMATS'))
+        with open(path, 'r') as xmlfile:
+            parser.parse(xmlfile)
+
+        localy_supported = []
+        for item in handler.list:
+            if strippers.STRIPPERS.has_key(item['mimetype'].split(',')[0]):
+                localy_supported.append(item)
+
+        return localy_supported
+
+    def menu_activate_cb(self, menu, file):
+        if file.is_gone():
+            return
+
+        file_path = urllib.unquote(file.get_uri()[7:])
+
+        class_file = mat.create_class_file(file_path,
+                                           backup=True,
+                                           add2archive=False)
+        if class_file:
+            if class_file.is_clean():
+                self.show_message(_("%s is already clean") % file_path)
+            else:
+                if not class_file.remove_all():
+                    self.show_message(_("Unable to clean %s") % file_path, gtk.MessageType.ERROR)
+        else:
+            self.show_message(_("Unable to process %s") % file_path, gtk.MessageType.ERROR)
+
+
diff --git a/setup.py b/setup.py
index 22a6718..3b978b3 100644
--- a/setup.py
+++ b/setup.py
@@ -29,6 +29,7 @@ setup(
         ( 'share/applications', ['mat.desktop'] ),
         ( 'share/mat', ['FORMATS', 'logo.png'] ),
         ( 'share/doc/mat', ['README', 'TODO'] ),
+        ( 'share/nautilus/extensions-2.0/python', ['nautilus2-mat.py'] ),
     ],
     cmdclass          = {
         'build': build_extra.build_extra,
-- 
1.7.10.4