test.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 gs
  28. def cleanup():
  29. # add some cleanup code
  30. gs.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 main code here
  37. exitcode = 0
  38. if flag_f:
  39. gs.message(_("Flag -f set"))
  40. else:
  41. gs.message(_("Flag -f not set"))
  42. # test if parameter present:
  43. if option1:
  44. gs.message(_("Value of option1 option: '%s'" % option1))
  45. gs.message(_("Value of raster option: '%s'" % raster))
  46. gs.message(_("Value of vector option: '%s'" % vector))
  47. # End of your main code here
  48. sys.exit(exitcode)
  49. if __name__ == "__main__":
  50. options, flags = gs.parser()
  51. atexit.register(cleanup)
  52. main()