[GRASS-dev] [GRASS GIS] #2333: choose python interpreter during the GRASS installation on windows

GRASS GIS trac at osgeo.org
Thu Jun 19 05:40:56 PDT 2014


#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
 Reporter:  zarch                                 |       Owner:  grass-dev@…              
     Type:  enhancement                           |      Status:  new                      
 Priority:  normal                                |   Milestone:  7.1.0                    
Component:  Python                                |     Version:  svn-trunk                
 Keywords:  windows installer python interpreter  |    Platform:  MSWindows 8              
      Cpu:  All                                   |  
--------------------------------------------------+-------------------------

Comment(by glynn):

 Replying to [comment:20 martinl]:

 > > So, do we mimic the shell (locate the program and determine its
 suffix), or use it (and
 >
 > There was something similar installed for Python scripts (1).

 Right. But if we take that route, it should apply to everything. And if
 the extension isn't one which !CreateProcess() handles directly (exe, bat,
 cmd, what else?), we should set shell=True (and ideally perform any
 necessary escaping).

 IOW, something like:
 {{{
 class Popen(subprocess.Popen):
     def __init__(self, args, ...):
         if sys.platform == 'win32' and isinstance(args, list):
             cmd = shutil_which(args[0])
             args = [cmd] + args[1:]
             name, ext = os.path.splitext(cmd)
             if ext.lower() not in ['.exe', '.bat', '.cmd']:
                 shell = True
                 args = [escape_for_shell(arg) for arg in args]
         subprocess.Popen.__init__(self, args, shell=shell, ...)
 }}}

 > > I still don't consider the previous approach (use the shell, don't
 bother escaping anything) to be a viable solution.
 >
 > Using `shell=True` seems to be less problematic to me, is it problem to
 determine escaping rules for special characters (I know only about pipe
 problem till now).

 I'm unsure what the rules are, whether they're sufficient (i.e. whether
 there are sequences which simply cannot be passed), or whether I'd trust
 any documentation to be accurate. I also don't know whether there are any
 other gotchas (ANSI-versus-OEM codepage issues?). But we don't really have
 a choice; execution of arbitrary scripts has to go through the shell one
 way or another. The main thing is that we don't get the shell involved
 unless we have to (i.e. we don't do it for EXEs).

 The specific issue with the parser() function can be dealt with by using
 'g.parser.exe' on Windows. And it should probably use subprocess.Popen()
 directly rather than grass.script.Popen(), to avoid any issues with
 whatever magic may be added to the latter. Executing g.parser with
 shell=True may be where the need for double-escaping was coming from.

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:22>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list