[GRASS-dev] [GRASS GIS] #2008: grass.script's find_program() can't find modules

GRASS GIS trac at osgeo.org
Wed Jun 19 05:55:28 PDT 2013


#2008: grass.script's find_program() can't find modules
-----------------------+----------------------------------------------------
  Reporter:  hamish    |       Owner:  grass-dev@…              
      Type:  defect    |      Status:  reopened                 
  Priority:  critical  |   Milestone:  6.4.4                    
 Component:  Python    |     Version:  svn-releasebranch64      
Resolution:            |    Keywords:  find_program()           
  Platform:  All       |         Cpu:  x86-64                   
-----------------------+----------------------------------------------------

Comment(by zarch):

 Replying to [comment:6 hamish]:
 > Replying to [comment:5 zarch]:
 > > Why not change the function in:
 > >
 > > {{{
 > > >>> def find_program(cmd):
 > > ...     return cmd in grass.get_commands()[0]
 > > ...
 > > >>> find_program('r.sun')
 > > True
 > > }}}
 >
 >
 > because we want to use the function as a replacement for `which`, so
 > find arbitrary helper apps like xml2 and gdalwarp which are not
 > grass modules. Also, get_commands() is not very robust.

 What about:

 {{{
 def which(pgm):
     for p in os.getenv('PATH').split(os.path.pathsep):
         p = os.path.join(p, pgm)
         if os.path.exists(p) and os.access(p, os.X_OK):
             return p
 }}}

 In python3.3 they add this function in "shutil.which"

 http://hg.python.org/cpython/file/6860263c05b3/Lib/shutil.py#l1068

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/2008#comment:7>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list