Changeset 73930


Ignore:
Timestamp:
Jan 12, 2019, 2:06:55 AM (6 years ago)
Author:
martinl
Message:

wingrass77 core python3 issues, see #3723

Location:
grass/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/gui/wxpython/core/gcmd.py

    r73796 r73930  
    4848    import fcntl
    4949
     50from core.debug import Debug
     51from core.globalvar import SCT_EXT, _
     52
    5053from grass.script import core as grass
    51 from core import globalvar
    52 from core.debug import Debug
    5354from grass.script.utils import decode
    5455
    55 # cannot import from the core.utils module to avoid cross dependencies
    56 try:
    57     # intended to be used also outside this module
    58     import gettext
    59     _ = gettext.translation(
    60         'grasswxpy',
    61         os.path.join(
    62             os.getenv("GISBASE"),
    63             'locale')).ugettext
    64 except IOError:
    65     # using no translation silently
    66     def null_gettext(string):
    67         return string
    68     _ = null_gettext
    6956
    7057if sys.version_info.major == 2:
     
    587574        args = self.cmd
    588575        if sys.platform == 'win32':
    589             if os.path.splitext(args[0])[1] == globalvar.SCT_EXT:
     576            if os.path.splitext(args[0])[1] == SCT_EXT:
    590577                args[0] = args[0][:-3]
    591578            # using Python executable to run the module if it is a script
  • grass/trunk/gui/wxpython/core/globalvar.py

    r71833 r73930  
    3131from core.debug import Debug
    3232
    33 # cannot import from the core.utils module to avoid cross dependencies
    3433try:
    3534    # intended to be used also outside this module
    3635    import gettext
    37     _ = gettext.translation(
    38         'grasswxpy',
    39         os.path.join(
    40             os.getenv("GISBASE"),
    41             'locale')).ugettext
     36    trans = gettext.translation('grasswxpy',
     37                                os.path.join(os.getenv("GISBASE"),
     38                                                       'locale')
     39    )
     40    _ = trans.gettext if sys.version_info.major >=3 else trans.ugettext
    4241except IOError:
    4342    # using no translation silently
  • grass/trunk/gui/wxpython/core/utils.py

    r73903 r73930  
    2727from grass.exceptions import OpenError
    2828
    29 from core import globalvar
    3029from core.gcmd import RunCommand
    3130from core.debug import Debug
    32 
    33 try:
    34     # intended to be used also outside this module
    35     import gettext
    36     _ = gettext.translation(
    37         'grasswxpy',
    38         os.path.join(
    39             os.getenv("GISBASE"),
    40             'locale')).ugettext
    41 except IOError:
    42     # using no translation silently
    43     def null_gettext(string):
    44         return string
    45     _ = null_gettext
    46 
     31from core.globalvar import ETCDIR, wxPythonPhoenix, _
    4732
    4833def cmp(a, b):
     
    841826    """
    842827    try:
    843         verFd = open(os.path.join(globalvar.ETCDIR, "VERSIONNUMBER"))
     828        verFd = open(os.path.join(ETCDIR, "VERSIONNUMBER"))
    844829        version = int(verFd.readlines()[0].split(' ')[0].split('.')[0])
    845830    except (IOError, ValueError, TypeError, IndexError) as e:
     
    10981083                "tostring"))
    10991084        # Create layer and insert alpha values.
    1100         if globalvar.wxPythonPhoenix:
     1085        if wxPythonPhoenix:
    11011086            wxImage.SetAlpha(fn()[3::4])
    11021087        else:
  • grass/trunk/lib/python/script/core.py

    r73906 r73930  
    7373                kwargs['shell'] = True
    7474                args = [self._escape_for_shell(arg) for arg in args]
     75            args = [decode(arg) for arg in args]
    7576        subprocess.Popen.__init__(self, args, **kwargs)
    7677
     
    209210            path.insert(0, os.curdir)
    210211
    211         # PATHEXT is necessary to check on Windows.
    212         pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
    213         map(lambda x: x.lower(), pathext) # force lowercase
    214         if '.py' not in pathext:          # we assume that PATHEXT contains always '.py'
    215             pathext.insert(0, '.py')
     212        # PATHEXT is necessary to check on Windows (force lowercase)
     213        pathext = list(map(lambda x: encode(x.lower()),
     214                           os.environ.get("PATHEXT", "").split(os.pathsep)))
     215        if b'.py' not in pathext:
     216            # we assume that PATHEXT contains always '.py'
     217            pathext.insert(0, b'.py')
    216218        # See if the given file matches any of the expected path extensions.
    217219        # This will allow us to short circuit when given "python.exe".
    218220        # If it does match, only test that one, otherwise we have to try
    219221        # others.
    220         if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
     222        if any(cmd.lower().endswith(ext) for ext in pathext):
    221223            files = [cmd]
    222224        else:
     
    233235            seen.add(normdir)
    234236            for thefile in files:
    235                 name = os.path.join(dir, thefile)
     237                name = os.path.join(encode(dir), thefile)
    236238                if _access_check(name, mode):
    237239                    return name
Note: See TracChangeset for help on using the changeset viewer.