浏览代码

wingrass77 core python3 issues, see https://trac.osgeo.org/grass/ticket/3723

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73930 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 6 年之前
父节点
当前提交
9d6c75cb1d
共有 4 个文件被更改,包括 21 次插入48 次删除
  1. 4 17
      gui/wxpython/core/gcmd.py
  2. 5 6
      gui/wxpython/core/globalvar.py
  3. 3 18
      gui/wxpython/core/utils.py
  4. 9 7
      lib/python/script/core.py

+ 4 - 17
gui/wxpython/core/gcmd.py

@@ -47,25 +47,12 @@ else:
     import select
     import fcntl
 
-from grass.script import core as grass
-from core import globalvar
 from core.debug import Debug
+from core.globalvar import SCT_EXT, _
+
+from grass.script import core as grass
 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 @@ class CommandThread(Thread):
         # 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

+ 5 - 6
gui/wxpython/core/globalvar.py

@@ -30,15 +30,14 @@ SYMBDIR = os.path.join(IMGDIR, "symbols")
 
 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):

+ 3 - 18
gui/wxpython/core/utils.py

@@ -26,24 +26,9 @@ from grass.script import core as grass
 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
-
-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
-
+from core.globalvar import ETCDIR, wxPythonPhoenix, _
 
 def cmp(a, b):
     """cmp function"""
@@ -840,7 +825,7 @@ def GetSettingsPath():
     """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 @@ def PilImageToWxImage(pilImage, copyAlpha=True):
                 pilImageCopyRGBA,
                 "tostring"))
         # Create layer and insert alpha values.
-        if globalvar.wxPythonPhoenix:
+        if wxPythonPhoenix:
             wxImage.SetAlpha(fn()[3::4])
         else:
             wxImage.SetAlphaData(fn()[3::4])

+ 9 - 7
lib/python/script/core.py

@@ -72,6 +72,7 @@ class Popen(subprocess.Popen):
             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 @@ def shutil_which(cmd, mode=os.F_OK | os.X_OK, path=None):
         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 @@ def shutil_which(cmd, mode=os.F_OK | os.X_OK, path=None):
         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