[GRASS-SVN] r30476 - grass/trunk/swig/python/examples

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 5 04:56:00 EST 2008


Author: hamish
Date: 2008-03-05 04:56:00 -0500 (Wed, 05 Mar 2008)
New Revision: 30476

Modified:
   grass/trunk/swig/python/examples/m.distance
Log:
use a flag to know if input is from stdin instead of trying to guess.
less problematic and it lets us demonstrate using parser flags.


Modified: grass/trunk/swig/python/examples/m.distance
===================================================================
--- grass/trunk/swig/python/examples/m.distance	2008-03-05 09:48:30 UTC (rev 30475)
+++ grass/trunk/swig/python/examples/m.distance	2008-03-05 09:56:00 UTC (rev 30476)
@@ -36,7 +36,12 @@
 #%  key_desc: x,y
 #%  description: Comma separated list of coordinate pairs
 #%End
+#%Flag
+#%  key: i
+#%  description: Read coordinate pairs from stdin
+#%End
 
+
 import sys
 import os
 
@@ -71,12 +76,10 @@
     # parser always creates at least an empty variable, and sys.argv is
     #  toast, so no way to check if option was given. So it hangs if
     #  --q was the only option given and there is no data from stdin.
-    coord_ans = os.getenv("GIS_OPT_COORD")
-    if coord_ans:
-        # read from coord= command line option
-        coords = coord_ans.split(',')
-    else:
-        # FIXME: this can hang if no input is given
+    coord_ans  = os.getenv("GIS_OPT_COORD")
+    stdin_flag = bool(int(os.getenv("GIS_FLAG_I")))
+
+    if stdin_flag is True:
         coords = []
         # read line by line from stdin
         while 1:
@@ -85,7 +88,11 @@
                 break
             else:
                 coords += line.split(',')
+    else:
+        # read from coord= command line option
+        coords = coord_ans.split(',')
 
+
     if len(coords) < 4:
        print "A minimum of two input coordinate pairs are needed"
        return



More information about the grass-commit mailing list