I wanted to see how it would be to port one of the bash scripts to Python. I followed the WIKI template and it didn't run. So I made a script that is ONLY from the WIKI template and it doesn't run either. I've tried it by just typing the script into the command prompt and also by typing:
python $GISBASE/scripts/pytest.py
The error is the same every time and is rather strange:
Line too long or missing newline at line 75
Line 75 is the last line (blank) of the script. If I get rid of this line, I still get the error, but on line 74.
I'll paste in the WIKI script below so you won't have to look it up. It seems OK and the error is kind of enigmatic. I've tried various permutations and get the same results.
Michael
================ WIKI script ===================
#!/usr/bin/python
############################################################################
#
# MODULE: g.example
#
# AUTHOR(S): Jane GrassUser
#
# PURPOSE: Demonstrates GRASS parser usage in a Python script
#
# COPYRIGHT: (c) 2007 The GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
############################################################################
#
# REQUIREMENTS:
# - footool: http://www.example.org
#%Module
#% description: g.parser test script
#% keywords: keyword1, keyword2
#%End
#%flag
#% key: f
#% description: a flag
#%END
#%option
#% key: raster
#% type: string
#% gisprompt: old,cell,raster
#% description: raster input map
#% required : yes
#%end
#%option
#% key: vector
#% type: string
#% gisprompt: old,vector,vector
#% description: vector input map
#% required : yes
#%end
#%option
#% key: option1
#% type: string
#% description: an option
#% required : yes
#%end
import sys
import os
def main():
#### add your code here ####
print ""
if ( os.getenv("GIS_FLAG_F") == "1" ):
print "Flag -f set"
else:
print "Flag -f not set"
print "Value of GIS_OPT_OPTION1: %s" % os.getenv("GIS_OPT_OPTION1")
print "Value of GIS_OPT_RASTER: %s" % os.getenv("GIS_OPT_RASTER")
print "Value of GIS_OPT_VECTOR: %s" % os.getenv("GIS_OPT_VECTOR")
#### end of your code ####
return
if __name__ == "__main__":
if ( len(sys.argv) <= 1 or sys.argv[1] != "@ARGS_PARSED@" ):
os.execvp("g.parser", [sys.argv[0]] + sys.argv)
else:
main();