[gedit/wip/python3] Port plugins to python 3
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/python3] Port plugins to python 3
- Date: Thu, 25 Oct 2012 20:02:59 +0000 (UTC)
commit cbd2ff4f08c356e7c9771705a81e745ab7dc7d7c
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Oct 25 16:37:27 2012 +0200
Port plugins to python 3
plugins/externaltools/tools/__init__.py | 4 ++--
plugins/externaltools/tools/capture.py | 10 +++++++---
plugins/externaltools/tools/functions.py | 4 ++--
plugins/externaltools/tools/library.py | 13 ++++++-------
plugins/externaltools/tools/manager.py | 4 ++--
plugins/externaltools/tools/outputpanel.py | 6 +++---
plugins/externaltools/tools/windowactivatable.py | 10 +++++-----
plugins/pythonconsole/pythonconsole/__init__.py | 4 ++--
plugins/quickopen/quickopen/__init__.py | 10 +++++-----
plugins/quickopen/quickopen/popup.py | 14 ++++++++++----
plugins/quickopen/quickopen/virtualdirs.py | 2 +-
plugins/snippets/snippets/__init__.py | 6 +++---
plugins/snippets/snippets/appactivatable.py | 4 ++--
plugins/snippets/snippets/completion.py | 6 +++---
plugins/snippets/snippets/document.py | 14 +++++++-------
plugins/snippets/snippets/exporter.py | 4 ++--
plugins/snippets/snippets/importer.py | 4 ++--
plugins/snippets/snippets/languagemanager.py | 2 +-
plugins/snippets/snippets/library.py | 4 ++--
plugins/snippets/snippets/manager.py | 14 +++++++-------
plugins/snippets/snippets/parser.py | 2 +-
plugins/snippets/snippets/placeholder.py | 12 ++++++------
plugins/snippets/snippets/shareddata.py | 2 +-
plugins/snippets/snippets/snippet.py | 6 +++---
plugins/snippets/snippets/windowactivatable.py | 8 ++++----
25 files changed, 89 insertions(+), 80 deletions(-)
---
diff --git a/plugins/externaltools/tools/__init__.py b/plugins/externaltools/tools/__init__.py
index 721fd85..87af9cf 100644
--- a/plugins/externaltools/tools/__init__.py
+++ b/plugins/externaltools/tools/__init__.py
@@ -17,8 +17,8 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gi.repository import GObject, Gedit
-from windowactivatable import WindowActivatable
-from library import ToolLibrary
+from .windowactivatable import WindowActivatable
+from .library import ToolLibrary
import os
class AppActivatable(GObject.Object, Gedit.AppActivatable):
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
index 64b50a2..a41a96a 100644
--- a/plugins/externaltools/tools/capture.py
+++ b/plugins/externaltools/tools/capture.py
@@ -87,7 +87,7 @@ class Capture(GObject.Object):
try:
self.pipe = subprocess.Popen(self.command, **popen_args)
- except OSError, e:
+ except OSError as e:
self.pipe = None
self.emit('stderr-line', _('Could not execute command: %s') % (e, ))
return
@@ -116,7 +116,7 @@ class Capture(GObject.Object):
# IO
if self.input_text is not None:
# Write async, in chunks of something
- self.write_buffer = str(self.input_text)
+ self.write_buffer = bytes(self.input_text, 'UTF-8')
if self.idle_write_chunk():
self.idle_write_id = GObject.idle_add(self.idle_write_chunk)
@@ -213,9 +213,13 @@ class Capture(GObject.Object):
else:
os.kill(self.pipe.pid, signal.SIGKILL)
+ def emit_end_execute(self, error_code):
+ self.emit('end-execute', error_code)
+ return False
+
def on_child_end(self, pid, error_code):
# In an idle, so it is emitted after all the std*-line signals
# have been intercepted
- GObject.idle_add(self.emit, 'end-execute', error_code)
+ GObject.idle_add(self.emit_end_execute, error_code)
# ex:ts=4:et:
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index 6a6266e..5acf50d 100644
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -18,8 +18,8 @@
import os
from gi.repository import Gio, Gtk, Gdk, GtkSource, Gedit
-from outputpanel import OutputPanel
-from capture import *
+from .outputpanel import OutputPanel
+from .capture import *
def default(val, d):
if val is not None:
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index 1e4ef64..47f0bba 100644
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -88,7 +88,7 @@ class ToolLibrary(Singleton):
if not os.path.isfile(filename):
return
- print "External tools: importing old tools into the new store..."
+ print("External tools: importing old tools into the new store...")
xtree = et.parse(filename)
xroot = xtree.getroot()
@@ -159,8 +159,7 @@ class ToolDirectory(object):
continue
for i in os.listdir(d):
elements[i] = None
- keys = elements.keys()
- keys.sort()
+ keys = sorted(elements.keys())
return keys
def _load(self):
@@ -245,7 +244,7 @@ class Tool(object):
if filename is None:
return
- fp = file(filename, 'r', 1)
+ fp = open(filename, 'r', 1)
in_block = False
lang = locale.getlocale(locale.LC_MESSAGES)[0]
@@ -453,7 +452,7 @@ class Tool(object):
fp.write(line + "\n")
fp.close()
- os.chmod(filename, 0750)
+ os.chmod(filename, 0o750)
self.changed = False
def save(self):
@@ -480,10 +479,10 @@ if __name__ == '__main__':
library = ToolLibrary()
def print_tool(t, indent):
- print indent * " " + "%s: %s" % (t.filename, t.name)
+ print(indent * " " + "%s: %s" % (t.filename, t.name))
def print_dir(d, indent):
- print indent * " " + d.dirname + '/'
+ print(indent * " " + d.dirname + '/')
for i in d.subdirs:
print_dir(i, indent+1)
for i in d.tools:
diff --git a/plugins/externaltools/tools/manager.py b/plugins/externaltools/tools/manager.py
index 2a39a79..f9d3a8b 100644
--- a/plugins/externaltools/tools/manager.py
+++ b/plugins/externaltools/tools/manager.py
@@ -19,8 +19,8 @@
__all__ = ('Manager', )
import os.path
-from library import *
-from functions import *
+from .library import *
+from .functions import *
import hashlib
from xml.sax import saxutils
from gi.repository import GObject, Gtk, GtkSource, Gedit
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py
index afb41d2..cf24a33 100644
--- a/plugins/externaltools/tools/outputpanel.py
+++ b/plugins/externaltools/tools/outputpanel.py
@@ -21,10 +21,10 @@ __all__ = ('OutputPanel', 'UniqueById')
import os
from weakref import WeakKeyDictionary
-from capture import *
+from .capture import *
import re
-import linkparsing
-import filelookup
+from . import linkparsing
+from . import filelookup
from gi.repository import GObject, Gio, Gdk, Gtk, Pango, Gedit
class UniqueById:
diff --git a/plugins/externaltools/tools/windowactivatable.py b/plugins/externaltools/tools/windowactivatable.py
index da03b78..cfd99f0 100644
--- a/plugins/externaltools/tools/windowactivatable.py
+++ b/plugins/externaltools/tools/windowactivatable.py
@@ -19,11 +19,11 @@
__all__ = ('ExternalToolsPlugin', 'Manager', 'OutputPanel', 'Capture', 'UniqueById')
from gi.repository import GObject, Gtk, Gedit, PeasGtk
-from manager import Manager
-from library import ToolLibrary
-from outputpanel import OutputPanel
-from capture import Capture
-from functions import *
+from .manager import Manager
+from .library import ToolLibrary
+from .outputpanel import OutputPanel
+from .capture import Capture
+from .functions import *
class ToolMenu(object):
def __init__(self, library, window, panel, menupath):
diff --git a/plugins/pythonconsole/pythonconsole/__init__.py b/plugins/pythonconsole/pythonconsole/__init__.py
index 29cd24b..cbe2a01 100644
--- a/plugins/pythonconsole/pythonconsole/__init__.py
+++ b/plugins/pythonconsole/pythonconsole/__init__.py
@@ -26,8 +26,8 @@
from gi.repository import GObject, Gtk, Gedit, Peas, PeasGtk
-from console import PythonConsole
-from config import PythonConsoleConfigWidget
+from .console import PythonConsole
+from .config import PythonConsoleConfigWidget
PYTHON_ICON = 'gnome-mime-text-x-python'
diff --git a/plugins/quickopen/quickopen/__init__.py b/plugins/quickopen/quickopen/__init__.py
index e4772af..9a32187 100644
--- a/plugins/quickopen/quickopen/__init__.py
+++ b/plugins/quickopen/quickopen/__init__.py
@@ -17,11 +17,11 @@
# Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307, USA.
-from popup import Popup
+from .popup import Popup
import os
from gi.repository import GObject, Gio, Gtk, Gedit
-from virtualdirs import RecentDocumentsDirectory
-from virtualdirs import CurrentDocumentsDirectory
+from .virtualdirs import RecentDocumentsDirectory
+from .virtualdirs import CurrentDocumentsDirectory
ui_str = """<ui>
<menubar name="MenuBar">
@@ -133,7 +133,7 @@ class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
paths = []
- for line in file(filename, 'r').xreadlines():
+ for line in open(filename, 'r'):
uri = line.strip().split(" ")[0]
f = Gio.file_new_for_uri(uri)
@@ -160,7 +160,7 @@ class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
desktopdir = None
if os.path.isfile(config):
- for line in file(config, 'r').xreadlines():
+ for line in open(config, 'r'):
line = line.strip()
if line.startswith('XDG_DESKTOP_DIR'):
diff --git a/plugins/quickopen/quickopen/popup.py b/plugins/quickopen/quickopen/popup.py
index 237a8c9..331ca6e 100644
--- a/plugins/quickopen/quickopen/popup.py
+++ b/plugins/quickopen/quickopen/popup.py
@@ -18,10 +18,11 @@
# Boston, MA 02111-1307, USA.
import os
+import functools
import fnmatch
from gi.repository import Gio, GObject, Pango, Gtk, Gdk, Gedit
import xml.sax.saxutils
-from virtualdirs import VirtualDirectory
+from .virtualdirs import VirtualDirectory
class Popup(Gtk.Dialog):
__gtype_name__ = "QuickOpenPopup"
@@ -172,7 +173,12 @@ class Popup(Gtk.Dialog):
def _compare_entries(self, a, b, lpart):
if lpart in a:
if lpart in b:
- return cmp(a.index(lpart), b.index(lpart))
+ if a.index(lpart) < b.index(lpart):
+ return -1
+ elif a.index(lpart) > b.index(lpart):
+ return 1
+ else:
+ return 0
else:
return -1
elif lpart in b:
@@ -194,7 +200,7 @@ class Popup(Gtk.Dialog):
entries = self._cache[d]
else:
entries = self._list_dir(d)
- entries.sort(lambda x, y: cmp(x[1].lower(), y[1].lower()))
+ entries.sort(key=lambda x: x[1].lower())
self._cache[d] = entries
found = []
@@ -218,7 +224,7 @@ class Popup(Gtk.Dialog):
(not lpart or len(parts) == 1):
found.append(entry)
- found.sort(lambda a, b: self._compare_entries(a[1].lower(), b[1].lower(), lpart))
+ found.sort(key=functools.cmp_to_key(lambda a, b: self._compare_entries(a[1].lower(), b[1].lower(), lpart)))
if lpart == '..':
newdirs.append(d.get_parent())
diff --git a/plugins/quickopen/quickopen/virtualdirs.py b/plugins/quickopen/quickopen/virtualdirs.py
index 40cb2c2..71fca2a 100644
--- a/plugins/quickopen/quickopen/virtualdirs.py
+++ b/plugins/quickopen/quickopen/virtualdirs.py
@@ -58,7 +58,7 @@ class RecentDocumentsDirectory(VirtualDirectory):
manager = Gtk.RecentManager.get_default()
items = manager.get_items()
- items.sort(lambda a, b: cmp(b.get_visited(), a.get_visited()))
+ items.sort(key=lambda a: a.get_visited())
added = 0
diff --git a/plugins/snippets/snippets/__init__.py b/plugins/snippets/snippets/__init__.py
index 0d4d92e..305d4c8 100644
--- a/plugins/snippets/snippets/__init__.py
+++ b/plugins/snippets/snippets/__init__.py
@@ -15,8 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-from appactivatable import AppActivatable
-from windowactivatable import WindowActivatable
-from document import Document
+from .appactivatable import AppActivatable
+from .windowactivatable import WindowActivatable
+from .document import Document
# ex:ts=8:et:
diff --git a/plugins/snippets/snippets/appactivatable.py b/plugins/snippets/snippets/appactivatable.py
index 63f9147..9c33426 100644
--- a/plugins/snippets/snippets/appactivatable.py
+++ b/plugins/snippets/snippets/appactivatable.py
@@ -22,8 +22,8 @@ import shutil
from gi.repository import Gedit, GLib, GObject, Gtk
import platform
-from library import Library
-from manager import Manager
+from .library import Library
+from .manager import Manager
class AppActivatable(GObject.Object, Gedit.AppActivatable):
__gtype_name__ = "GeditSnippetsAppActivatable"
diff --git a/plugins/snippets/snippets/completion.py b/plugins/snippets/snippets/completion.py
index b97ddba..8740516 100644
--- a/plugins/snippets/snippets/completion.py
+++ b/plugins/snippets/snippets/completion.py
@@ -17,9 +17,9 @@
from gi.repository import GObject, Gtk, GtkSource, Gedit
-from library import Library
-from languagemanager import get_language_manager
-from snippet import Snippet
+from .library import Library
+from .languagemanager import get_language_manager
+from .snippet import Snippet
class Proposal(GObject.Object, GtkSource.CompletionProposal):
__gtype_name__ = "GeditSnippetsProposal"
diff --git a/plugins/snippets/snippets/document.py b/plugins/snippets/snippets/document.py
index 678aa5e..890216b 100644
--- a/plugins/snippets/snippets/document.py
+++ b/plugins/snippets/snippets/document.py
@@ -21,13 +21,13 @@ import re
import cairo
from gi.repository import Gtk, Gdk, Gio, GLib, GtkSource, Gedit
-from library import Library
-from snippet import Snippet
-from placeholder import *
-import completion
-from signals import Signals
-from shareddata import SharedData
-import helper
+from .library import Library
+from .snippet import Snippet
+from .placeholder import *
+from . import completion
+from .signals import Signals
+from .shareddata import SharedData
+from . import helper
class DynamicSnippet(dict):
def __init__(self, text):
diff --git a/plugins/snippets/snippets/exporter.py b/plugins/snippets/snippets/exporter.py
index 7b80210..185215e 100644
--- a/plugins/snippets/snippets/exporter.py
+++ b/plugins/snippets/snippets/exporter.py
@@ -20,9 +20,9 @@ import tempfile
import sys
import shutil
-from library import *
+from .library import *
import xml.etree.ElementTree as et
-from helper import *
+from .helper import *
class Exporter:
def __init__(self, filename, snippets):
diff --git a/plugins/snippets/snippets/importer.py b/plugins/snippets/snippets/importer.py
index 2cf6063..da0d977 100644
--- a/plugins/snippets/snippets/importer.py
+++ b/plugins/snippets/snippets/importer.py
@@ -21,7 +21,7 @@ import tempfile
import sys
import shutil
-from library import *
+from .library import *
class Importer:
def __init__(self, filename):
@@ -55,7 +55,7 @@ class Importer:
# Make sure dir exists
try:
os.makedirs(destdir)
- except OSError, e:
+ except OSError as e:
if e.errno != errno.EEXIST:
raise
diff --git a/plugins/snippets/snippets/languagemanager.py b/plugins/snippets/snippets/languagemanager.py
index d70449b..30b079e 100644
--- a/plugins/snippets/snippets/languagemanager.py
+++ b/plugins/snippets/snippets/languagemanager.py
@@ -18,7 +18,7 @@
from gi.repository import GtkSource
import os
-from library import Library
+from .library import Library
global manager
manager = None
diff --git a/plugins/snippets/snippets/library.py b/plugins/snippets/snippets/library.py
index 79b894c..959dd78 100644
--- a/plugins/snippets/snippets/library.py
+++ b/plugins/snippets/snippets/library.py
@@ -24,7 +24,7 @@ import re
from gi.repository import Gdk, Gtk
import xml.etree.ElementTree as et
-from helper import *
+from .helper import *
class NamespacedId:
def __init__(self, namespace, id):
@@ -620,7 +620,7 @@ class SnippetsUserFile(SnippetsSystemFile):
try:
if not os.path.isdir(path):
- os.makedirs(path, 0755)
+ os.makedirs(path, 0o755)
except OSError:
# TODO: this is bad...
sys.stderr.write("Error in making dirs\n")
diff --git a/plugins/snippets/snippets/manager.py b/plugins/snippets/snippets/manager.py
index 3720509..33348c5 100644
--- a/plugins/snippets/snippets/manager.py
+++ b/plugins/snippets/snippets/manager.py
@@ -21,13 +21,13 @@ import shutil
from gi.repository import Gtk, Gio, Gdk, GtkSource, Gedit, GObject
-from snippet import Snippet
-from helper import *
-from library import *
-from importer import *
-from exporter import *
-from document import Document
-from languagemanager import get_language_manager
+from .snippet import Snippet
+from .helper import *
+from .library import *
+from .importer import *
+from .exporter import *
+from .document import Document
+from .languagemanager import get_language_manager
class Manager(Gtk.Dialog, Gtk.Buildable):
NAME_COLUMN = 0
diff --git a/plugins/snippets/snippets/parser.py b/plugins/snippets/snippets/parser.py
index 0012c71..628db4e 100644
--- a/plugins/snippets/snippets/parser.py
+++ b/plugins/snippets/snippets/parser.py
@@ -18,7 +18,7 @@
import os
import re
import sys
-from substitutionparser import SubstitutionParser
+from .substitutionparser import SubstitutionParser
class Token:
def __init__(self, klass, data):
diff --git a/plugins/snippets/snippets/placeholder.py b/plugins/snippets/snippets/placeholder.py
index 5fc95f1..688195c 100644
--- a/plugins/snippets/snippets/placeholder.py
+++ b/plugins/snippets/snippets/placeholder.py
@@ -25,8 +25,8 @@ import locale
import subprocess
from gi.repository import GObject
-from helper import *
-from substitutionparser import SubstitutionParser
+from .helper import *
+from .substitutionparser import SubstitutionParser
# These are places in a view where the cursor can go and do things
class Placeholder:
@@ -539,7 +539,7 @@ class PlaceholderEval(PlaceholderExpand):
return hasattr(signal, 'SIGALRM')
def timeout_cb(self, signum = 0, frame = 0):
- raise TimeoutError, "Operation timed out (>2 seconds)"
+ raise TimeoutError("Operation timed out (>2 seconds)")
def install_timeout(self):
if not self.timeout_supported():
@@ -578,7 +578,7 @@ class PlaceholderEval(PlaceholderExpand):
del self.namespace['process_snippet']
try:
- exec text in self.namespace
+ exec(text, self.namespace)
except:
traceback.print_exc()
@@ -603,7 +603,7 @@ class PlaceholderEval(PlaceholderExpand):
'time, execution aborted.') % self.command)
return False
- except Exception, detail:
+ except Exception as detail:
self.remove_timeout()
message_dialog(None, Gtk.MessageType.ERROR,
@@ -684,7 +684,7 @@ class PlaceholderRegex(PlaceholderExpand):
# Try to compile pattern
try:
regex = re.compile(pattern, self.modifiers)
- except re.error, message:
+ except re.error as message:
sys.stderr.write('Could not compile regular expression: %s\n%s\n' % (pattern, message))
return False
diff --git a/plugins/snippets/snippets/shareddata.py b/plugins/snippets/snippets/shareddata.py
index 1b5c9c2..2c8aae9 100644
--- a/plugins/snippets/snippets/shareddata.py
+++ b/plugins/snippets/snippets/shareddata.py
@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-from singleton import Singleton
+from .singleton import Singleton
import os
from gi.repository import Gtk
diff --git a/plugins/snippets/snippets/snippet.py b/plugins/snippets/snippets/snippet.py
index c3afeba..a92f0be 100644
--- a/plugins/snippets/snippets/snippet.py
+++ b/plugins/snippets/snippets/snippet.py
@@ -18,9 +18,9 @@
import os
from gi.repository import Gio
-from placeholder import *
-from parser import Parser, Token
-from helper import *
+from .placeholder import *
+from .parser import Parser, Token
+from .helper import *
class EvalUtilities:
def __init__(self, view=None):
diff --git a/plugins/snippets/snippets/windowactivatable.py b/plugins/snippets/snippets/windowactivatable.py
index 7b99e98..d34e279 100644
--- a/plugins/snippets/snippets/windowactivatable.py
+++ b/plugins/snippets/snippets/windowactivatable.py
@@ -21,10 +21,10 @@ import gettext
from gi.repository import Gtk, Gdk, Gedit, GObject
-from document import Document
-from library import Library
-from shareddata import SharedData
-from signals import Signals
+from .document import Document
+from .library import Library
+from .shareddata import SharedData
+from .signals import Signals
class Message(Gedit.Message):
view = GObject.property(type=Gedit.View)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]