test.py 1.1 KB

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