shortcuts.py 2.1 KB

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