File: 0001-nautilus-ext-python2.7.patch

package info (click to toggle)
mat2 0.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 6,236 kB
  • sloc: python: 2,733; makefile: 7
file content (152 lines) | stat: -rw-r--r-- 6,111 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From: Jonas Meurer <jonas@freesources.org>
Date: Fri, 22 Feb 2019 22:59:18 +0100
Subject: Patch nautilus/mat2.py to be a python2 wrapper around mat2

* Since Debian Buster still ships only Python 2 version of
  nautilus-python, the only option to use the mat2 nautilus
  extension is to make it a python2 wrapper around mat2.

Author: Georg Faerber <georg@riseup.net>, Julien Voisin
 <julien.voisin@dustri.org>
Forwarded: not-needed
---
 nautilus/mat2.py | 51 +++++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/nautilus/mat2.py b/nautilus/mat2.py
index 562f8a7..d0794d0 100644
--- a/nautilus/mat2.py
+++ b/nautilus/mat2.py
@@ -1,5 +1,5 @@
-#!/usr/bin/env python3
-
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
 """
 Because writing GUI is non-trivial (cf. https://0xacab.org/jvoisin/mat2/issues/3),
 we decided to write a Nautilus extensions instead
@@ -12,34 +12,37 @@ thread, so we'll have to resort to using a `queue` to pass "messages" around.
 
 # pylint: disable=no-name-in-module,unused-argument,no-self-use,import-error
 
-import queue
+import Queue as queue
 import threading
-from typing import Tuple, Optional, List
-from urllib.parse import unquote
+from urlparse import unquote
 
 import gi
 gi.require_version('Nautilus', '3.0')
 gi.require_version('Gtk', '3.0')
 gi.require_version('GdkPixbuf', '2.0')
 from gi.repository import Nautilus, GObject, Gtk, Gio, GLib, GdkPixbuf
+import subprocess
+import mimetypes
+
 
-from libmat2 import parser_factory
+def _remove_metadata(fpath):
+    """ This is a simple wrapper around the mat2 cli. """
+    try:
+        return subprocess.check_output(['mat2', fpath])
+    except subprocess.CalledProcessError, e:
+        return e.output
 
 
-def _remove_metadata(fpath) -> Tuple[bool, Optional[str]]:
-    """ This is a simple wrapper around libmat2, because it's
-    easier and cleaner this way.
-    """
-    parser, mtype = parser_factory.get_parser(fpath)
-    if parser is None:
-        return False, mtype
-    return parser.remove_all(), mtype
+def _guess_mtype(fpath):
+    """ Function to guess the mtype of a given file. """
+    mtype, _ = mimetypes.guess_type(fpath)
+    return mtype
 
 class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWidgetProvider):
     """ This class adds an item to the right-clic menu in Nautilus. """
 
     def __init__(self):
-        super().__init__()
+        super(Mat2Extension, self).__init__()
         self.infobar_hbox = None
         self.infobar = None
         self.failed_items = list()
@@ -61,7 +64,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
         self.infobar.get_content_area().pack_start(self.infobar_hbox, True, True, 0)
         self.infobar.show_all()
 
-    def get_widget(self, uri, window) -> Gtk.Widget:
+    def get_widget(self, uri, window):
         """ This is the method that we have to implement (because we're
         a LocationWidgetProvider) in order to show our infobar.
         """
@@ -103,7 +106,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
         window.show_all()
 
     @staticmethod
-    def __validate(fileinfo) -> Tuple[bool, str]:
+    def __validate(fileinfo):
         """ Validate if a given file FileInfo `fileinfo` can be processed.
         Returns a boolean, and a textreason why"""
         if fileinfo.get_uri_scheme() != "file" or fileinfo.is_directory():
@@ -112,7 +115,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
             return False, "Not writeable"
         return True, ""
 
-    def __create_treeview(self) -> Gtk.TreeView:
+    def __create_treeview(self):
         liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str)
         treeview = Gtk.TreeView(model=liststore)
 
@@ -144,7 +147,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
         treeview.show_all()
         return treeview
 
-    def __create_progressbar(self) -> Gtk.ProgressBar:
+    def __create_progressbar(self):
         """ Create the progressbar used to notify that files are currently
         being processed.
         """
@@ -161,7 +164,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
 
         return progressbar
 
-    def __update_progressbar(self, processing_queue, progressbar) -> bool:
+    def __update_progressbar(self, processing_queue, progressbar):
         """ This method is run via `Glib.add_idle` to update the progressbar."""
         try:
             fname = processing_queue.get(block=False)
@@ -186,7 +189,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
         self.infobar.show_all()
         return True
 
-    def __clean_files(self, files: list, processing_queue: queue.Queue) -> bool:
+    def __clean_files(self, files, processing_queue):
         """ This method is threaded in order to avoid blocking the GUI
         while cleaning up the files.
         """
@@ -200,8 +203,8 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
                 continue
 
             fpath = unquote(fileinfo.get_uri()[7:])  # `len('file://') = 7`
-            success, mtype = _remove_metadata(fpath)
-            if not success:
+            if _remove_metadata(fpath):
+                mtype = _guess_mtype(fpath)
                 self.failed_items.append((fname, mtype, 'Unsupported/invalid'))
         processing_queue.put(None)  # signal that we processed all the files
         return True
@@ -226,7 +229,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
         """ https://bugzilla.gnome.org/show_bug.cgi?id=784278 """
         return None
 
-    def get_file_items(self, window, files) -> Optional[List[Nautilus.MenuItem]]:
+    def get_file_items(self, window, files):
         """ This method is the one allowing us to create a menu item.
         """
         # Do not show the menu item if not a single file has a chance to be