test.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. # g.parser demo script for python programming
  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 G_OPT_R_MAP
  13. #% key: raster
  14. #% required: yes
  15. #%end
  16. #%option G_OPT_V_MAP
  17. #% key: vector
  18. #%end
  19. #%option
  20. #% key: option1
  21. #% type: string
  22. #% description: An option
  23. #% required: no
  24. #%end
  25. import sys
  26. import atexit
  27. import grass.script as grass
  28. def cleanup():
  29. # add some cleanup code
  30. grass.message(_("Inside cleanup function..."))
  31. def main():
  32. flag_f = flags['f']
  33. option1 = options['option1']
  34. raster = options['raster']
  35. vector = options['vector']
  36. #### add your code here ####
  37. exitcode = 0
  38. if flag_f:
  39. grass.message(_("Flag -f set"))
  40. else:
  41. grass.message(_("Flag -f not set"))
  42. # test if parameter present:
  43. if option1:
  44. grass.message(_("Value of option1 option: '%s'" % option1))
  45. grass.message(_("Value of raster option: '%s'" % raster))
  46. grass.message(_("Value of vector option: '%s'" % vector))
  47. #### end of your code ####
  48. sys.exit(exitcode)
  49. if __name__ == "__main__":
  50. options, flags = grass.parser()
  51. atexit.register(cleanup)
  52. main()