[meld] Minor moves toward py3k compatibility



commit f08ee3fb6e55171c219035957a3f8d9ae119a59e
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Nov 7 05:01:08 2013 +1000

    Minor moves toward py3k compatibility

 bin/meld                |   20 +++++++++++++-------
 meld/recent.py          |   14 +++++++++-----
 meld/ui/historyentry.py |   12 ++++++++----
 3 files changed, 30 insertions(+), 16 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index 4ba9131..70f30be 100755
--- a/bin/meld
+++ b/bin/meld
@@ -17,6 +17,8 @@
 ### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 ### USA.
 
+from __future__ import print_function
+
 import locale
 import logging
 import os
@@ -74,7 +76,11 @@ locale_dir = meld.conf.LOCALEDIR
 gettext.bindtextdomain(locale_domain, locale_dir)
 locale.setlocale(locale.LC_ALL, '')
 gettext.textdomain(locale_domain)
-gettext.install(locale_domain, localedir=locale_dir, unicode=True)
+try:
+    gettext.install(locale_domain, localedir=locale_dir, unicode=True)
+except TypeError:
+    # py3k
+    gettext.install(locale_domain, localedir=locale_dir)
 
 try:
     if os.name == 'nt':
@@ -89,11 +95,11 @@ try:
 except AttributeError as e:
     # Python builds linked without libintl (i.e., OSX) don't have
     # bindtextdomain(), which causes Gtk.Builder translations to fail.
-    print "Couldn't bind the translation domain. Some translations won't work."
-    print e
+    print("Couldn't bind the translation domain. Some translations won't work.")
+    print(e)
 except locale.Error as e:
-    print "Couldn't bind the translation domain. Some translations won't work."
-    print e
+    print("Couldn't bind the translation domain. Some translations won't work.")
+    print(e)
 
 
 def check_requirements():
@@ -104,10 +110,10 @@ def check_requirements():
 
     def missing_reqs(mod, ver, exception=None):
         if isinstance(exception, ImportError):
-            print _("Cannot import: ") + mod + "\n" + str(e)
+            print(_("Cannot import: ") + mod + "\n" + str(e))
         else:
             modver = mod + " " + ".".join(map(str, ver))
-            print _("Meld requires %s or higher.") % modver
+            print(_("Meld requires %s or higher.") % modver)
         sys.exit(1)
 
     if sys.version_info[:2] < pyver:
diff --git a/meld/recent.py b/meld/recent.py
index 75c2a08..af7c78f 100644
--- a/meld/recent.py
+++ b/meld/recent.py
@@ -26,7 +26,11 @@ single-file registers for multi-file comparisons, and tell the recent files
 infrastructure that that's actually what we opened.
 """
 
-import ConfigParser
+try:
+    # py3k
+    import configparser
+except ImportError:
+    import ConfigParser as configparser
 import os
 import tempfile
 
@@ -127,12 +131,12 @@ class RecentFiles(object):
             raise IOError("File does not exist")
 
         try:
-            config = ConfigParser.RawConfigParser()
+            config = configparser.RawConfigParser()
             config.read(path)
             assert (config.has_section("Comparison") and
                     config.has_option("Comparison", "type") and
                     config.has_option("Comparison", "paths"))
-        except (ConfigParser.Error, AssertionError):
+        except (configparser.Error, AssertionError):
             raise ValueError("Invalid recent comparison file")
 
         comp_type = config.get("Comparison", "type")
@@ -151,7 +155,7 @@ class RecentFiles(object):
                                          suffix=self.recent_suffix,
                                          dir=self.recent_path,
                                          delete=False) as f:
-            config = ConfigParser.RawConfigParser()
+            config = configparser.RawConfigParser()
             config.add_section("Comparison")
             config.set("Comparison", "type", comp_type)
             config.set("Comparison", "paths", ";".join(paths))
@@ -228,4 +232,4 @@ class RecentFiles(object):
 
 if __name__ == "__main__":
     recent = RecentFiles()
-    print recent
+    print(recent)
diff --git a/meld/ui/historyentry.py b/meld/ui/historyentry.py
index adb467c..8758e4d 100644
--- a/meld/ui/historyentry.py
+++ b/meld/ui/historyentry.py
@@ -15,11 +15,15 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 # USA.
 
-import ConfigParser
+try:
+    # py3k
+    import configparser
+except ImportError:
+    import ConfigParser as configparser
 import os
 import sys
 
-import glib
+from gi.repository import GLib
 from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import Pango
@@ -75,13 +79,13 @@ class HistoryCombo(Gtk.ComboBox):
         if sys.platform == "win32":
             pref_dir = os.path.join(os.getenv("APPDATA"), "Meld")
         else:
-            pref_dir = os.path.join(glib.get_user_config_dir(), "meld")
+            pref_dir = os.path.join(GLib.get_user_config_dir(), "meld")
 
         if not os.path.exists(pref_dir):
             os.makedirs(pref_dir)
 
         self.history_file = os.path.join(pref_dir, "history.ini")
-        self.config = ConfigParser.SafeConfigParser()
+        self.config = configparser.SafeConfigParser()
         if os.path.exists(self.history_file):
             self.config.read(self.history_file)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]