shortcuts.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Apr 2 18:49:11 2013
  4. @author: pietro
  5. """
  6. from __future__ import print_function
  7. import fnmatch
  8. from grass.script.core import get_commands
  9. from interface import Module
  10. _CMDS = list(get_commands()[0])
  11. _CMDS.sort()
  12. class MetaModule(object):
  13. """Example how to use MetaModule
  14. >>> g = MetaModule('g')
  15. >>> g_mlist = g.mlist
  16. >>> g_mlist.name
  17. 'g.mlist'
  18. >>> g_mlist.required
  19. [Parameter <type> (required:yes, type:string, multiple:yes)]
  20. >>> g_mlist.inputs.type = 'rast'
  21. >>> g_mlist.stdout_ = -1
  22. >>> g_mlist.run()
  23. >>> g_mlist.outputs.stdout # doctest: +ELLIPSIS
  24. 'basins...soils...'
  25. >>> r = MetaModule('r')
  26. >>> what = r.what
  27. >>> what.description
  28. 'Queries raster maps on their category values and category labels.'
  29. >>> what.inputs.map = 'elevation'
  30. >>> what.inputs.coordinates = [640000,220500] # doctest: +SKIP
  31. >>> what.run() # doctest: +SKIP
  32. """
  33. def __init__(self, prefix, cls=None):
  34. self.prefix = prefix
  35. self.cls = cls if cls else Module
  36. def __dir__(self):
  37. return [mod[(len(self.prefix) + 1):].replace('.', '_')
  38. for mod in fnmatch.filter(_CMDS, "%s.*" % self.prefix)]
  39. def __getattr__(self, name):
  40. return self.cls('%s.%s' % (self.prefix, name.replace('_', '.')))
  41. # http://grass.osgeo.org/grass70/manuals/html70_user/full_index.html
  42. #[ d.* | db.* | g.* | i.* | m.* | ps.* | r.* | r3.* | t.* | v.* ]
  43. #
  44. # d.* display commands
  45. # db.* database commands
  46. # g.* general commands
  47. # i.* imagery commands
  48. # m.* miscellaneous commands
  49. # ps.* postscript commands
  50. # r.* raster commands
  51. # r3.* raster3D commands
  52. # t.* temporal commands
  53. # v.* vector commands
  54. display = MetaModule('d')
  55. database = MetaModule('db')
  56. general = MetaModule('g')
  57. imagery = MetaModule('i')
  58. miscellaneous = MetaModule('m')
  59. postscript = MetaModule('ps')
  60. raster = MetaModule('r')
  61. raster3D = MetaModule('r3')
  62. temporal = MetaModule('t')
  63. vector = MetaModule('v')