test.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. # g.parser demo script for python programing
  3. #%Module
  4. #% description: g.parser test script (python)
  5. #% keyword: keyword1
  6. #% keyword: keyword2
  7. #%End
  8. #%flag
  9. #% key: f
  10. #% description: A flag
  11. #%end
  12. #%option
  13. #% key: raster
  14. #% type: string
  15. #% gisprompt: old,cell,raster
  16. #% description: Raster input map
  17. #% required : yes
  18. #%end
  19. #%option
  20. #% key: vector
  21. #% type: string
  22. #% gisprompt: old,vector,vector
  23. #% description: Vector input map
  24. #% required : yes
  25. #%end
  26. #%option
  27. #% key: option1
  28. #% type: string
  29. #% description: An option
  30. #% required : no
  31. #%end
  32. import os
  33. import sys
  34. import grass.script as grass
  35. def main():
  36. #### add your code here ####
  37. if flags['f']:
  38. print "Flag -f set"
  39. else:
  40. print "Flag -f not set"
  41. # test if parameter present:
  42. if options['option1']:
  43. print "Value of GIS_OPT_OPTION1: '%s'" % options['option1']
  44. print "Value of GIS_OPT_RASTER: '%s'" % options['raster']
  45. print "Value of GIS_OPT_VECTOR: '%s'" % options['vector']
  46. #### end of your code ####
  47. return 0
  48. if __name__ == "__main__":
  49. options, flags = grass.parser()
  50. sys.exit(main())