[GRASS-dev] Re: [GRASS-user] grass 6.4 rc5 and python scripting

Glynn Clements glynn at gclements.plus.com
Sat Jul 4 20:24:15 EDT 2009


Martin Landa wrote:

> > implemented in the other branches. But there isn't much point until
> > menuform.py is fixed.
> 
> I am not sure what should have been fixed. It's possible to launch a
> script which is not in the PATH. The script must be executable, then
> wxGUI is started properly.

1. Create a script in the current directory, e.g.:

	#!/usr/bin/env python
	#%Module
	#% description: Test script.
	#%End
	#%option
	#% key: option
	#% type: string
	#% description: An Option
	#% required: yes
	#%END
	
	import sys
	from grass.script import core as grass
	
	def main():
	    print options['option']
	
	if __name__ == "__main__":
	    options, flags = grass.parser()
	    main()


2. Run it with e.g. "./test.py --ui". It invokes g.parser which
invokes menuform.py with the full path to the script.


3. Fill in the option then click on the "Run" button. This results in
an error dialog:

	Execution failed: 'test.py option=foo'
	
	Details: 
	Error: Unable to exectute command: 'test.py option=foo'

If you copy the script to a directory in $PATH, clicking the "Run"
button runs that script. This indicates that menuform.py is executing
the script using its basename, not the full path given as an argument.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list