[GRASS-SVN] r73930 - in grass/trunk: gui/wxpython/core lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 12 02:06:55 PST 2019


Author: martinl
Date: 2019-01-12 02:06:55 -0800 (Sat, 12 Jan 2019)
New Revision: 73930

Modified:
   grass/trunk/gui/wxpython/core/gcmd.py
   grass/trunk/gui/wxpython/core/globalvar.py
   grass/trunk/gui/wxpython/core/utils.py
   grass/trunk/lib/python/script/core.py
Log:
wingrass77 core python3 issues, see #3723

Modified: grass/trunk/gui/wxpython/core/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/core/gcmd.py	2019-01-12 08:08:33 UTC (rev 73929)
+++ grass/trunk/gui/wxpython/core/gcmd.py	2019-01-12 10:06:55 UTC (rev 73930)
@@ -47,25 +47,12 @@
     import select
     import fcntl
 
+from core.debug import Debug
+from core.globalvar import SCT_EXT, _
+
 from grass.script import core as grass
-from core import globalvar
-from core.debug import Debug
 from grass.script.utils import decode
 
-# cannot import from the core.utils module to avoid cross dependencies
-try:
-    # intended to be used also outside this module
-    import gettext
-    _ = gettext.translation(
-        'grasswxpy',
-        os.path.join(
-            os.getenv("GISBASE"),
-            'locale')).ugettext
-except IOError:
-    # using no translation silently
-    def null_gettext(string):
-        return string
-    _ = null_gettext
 
 if sys.version_info.major == 2:
     bytes = str
@@ -586,7 +573,7 @@
         # changing from one chdir to get_real_command function
         args = self.cmd
         if sys.platform == 'win32':
-            if os.path.splitext(args[0])[1] == globalvar.SCT_EXT:
+            if os.path.splitext(args[0])[1] == SCT_EXT:
                 args[0] = args[0][:-3]
             # using Python executable to run the module if it is a script
             # expecting at least module name at first position

Modified: grass/trunk/gui/wxpython/core/globalvar.py
===================================================================
--- grass/trunk/gui/wxpython/core/globalvar.py	2019-01-12 08:08:33 UTC (rev 73929)
+++ grass/trunk/gui/wxpython/core/globalvar.py	2019-01-12 10:06:55 UTC (rev 73930)
@@ -30,15 +30,14 @@
 
 from core.debug import Debug
 
-# cannot import from the core.utils module to avoid cross dependencies
 try:
     # intended to be used also outside this module
     import gettext
-    _ = gettext.translation(
-        'grasswxpy',
-        os.path.join(
-            os.getenv("GISBASE"),
-            'locale')).ugettext
+    trans = gettext.translation('grasswxpy',
+                                os.path.join(os.getenv("GISBASE"),
+                                                       'locale')
+    )
+    _ = trans.gettext if sys.version_info.major >=3 else trans.ugettext
 except IOError:
     # using no translation silently
     def null_gettext(string):

Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py	2019-01-12 08:08:33 UTC (rev 73929)
+++ grass/trunk/gui/wxpython/core/utils.py	2019-01-12 10:06:55 UTC (rev 73930)
@@ -26,25 +26,10 @@
 from grass.script import task as gtask
 from grass.exceptions import OpenError
 
-from core import globalvar
 from core.gcmd import RunCommand
 from core.debug import Debug
+from core.globalvar import ETCDIR, wxPythonPhoenix, _
 
-try:
-    # intended to be used also outside this module
-    import gettext
-    _ = gettext.translation(
-        'grasswxpy',
-        os.path.join(
-            os.getenv("GISBASE"),
-            'locale')).ugettext
-except IOError:
-    # using no translation silently
-    def null_gettext(string):
-        return string
-    _ = null_gettext
-
-
 def cmp(a, b):
     """cmp function"""
     return ((a > b) - (a < b))
@@ -840,7 +825,7 @@
     """Get full path to the settings directory
     """
     try:
-        verFd = open(os.path.join(globalvar.ETCDIR, "VERSIONNUMBER"))
+        verFd = open(os.path.join(ETCDIR, "VERSIONNUMBER"))
         version = int(verFd.readlines()[0].split(' ')[0].split('.')[0])
     except (IOError, ValueError, TypeError, IndexError) as e:
         sys.exit(
@@ -1097,7 +1082,7 @@
                 pilImageCopyRGBA,
                 "tostring"))
         # Create layer and insert alpha values.
-        if globalvar.wxPythonPhoenix:
+        if wxPythonPhoenix:
             wxImage.SetAlpha(fn()[3::4])
         else:
             wxImage.SetAlphaData(fn()[3::4])

Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py	2019-01-12 08:08:33 UTC (rev 73929)
+++ grass/trunk/lib/python/script/core.py	2019-01-12 10:06:55 UTC (rev 73930)
@@ -72,6 +72,7 @@
             if ext.lower() not in self._builtin_exts:
                 kwargs['shell'] = True
                 args = [self._escape_for_shell(arg) for arg in args]
+            args = [decode(arg) for arg in args]
         subprocess.Popen.__init__(self, args, **kwargs)
 
 PIPE = subprocess.PIPE
@@ -208,16 +209,17 @@
         if not os.curdir in path:
             path.insert(0, os.curdir)
 
-        # PATHEXT is necessary to check on Windows.
-        pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
-        map(lambda x: x.lower(), pathext) # force lowercase
-        if '.py' not in pathext:          # we assume that PATHEXT contains always '.py'
-            pathext.insert(0, '.py')
+        # PATHEXT is necessary to check on Windows (force lowercase)
+        pathext = list(map(lambda x: encode(x.lower()),
+                           os.environ.get("PATHEXT", "").split(os.pathsep)))
+        if b'.py' not in pathext:
+            # we assume that PATHEXT contains always '.py'
+            pathext.insert(0, b'.py')
         # See if the given file matches any of the expected path extensions.
         # This will allow us to short circuit when given "python.exe".
         # If it does match, only test that one, otherwise we have to try
         # others.
-        if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
+        if any(cmd.lower().endswith(ext) for ext in pathext):
             files = [cmd]
         else:
             files = [cmd + ext for ext in pathext]
@@ -232,7 +234,7 @@
         if not normdir in seen:
             seen.add(normdir)
             for thefile in files:
-                name = os.path.join(dir, thefile)
+                name = os.path.join(encode(dir), thefile)
                 if _access_check(name, mode):
                     return name
     return None



More information about the grass-commit mailing list