shortcuts.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.inputs.mapset = 'PERMANENT'
  19. >>> g_list.stdout_ = -1
  20. >>> g_list.run()
  21. Module('g.list')
  22. >>> g_list.outputs.stdout # doctest: +ELLIPSIS
  23. '...basin...soils...'
  24. >>> r = MetaModule('r')
  25. >>> what = r.what
  26. >>> what.description
  27. 'Queries raster maps on their category values and category labels.'
  28. >>> what.inputs.map = 'elevation'
  29. >>> what.inputs.coordinates = [640000,220500] # doctest: +SKIP
  30. >>> what.run() # doctest: +SKIP
  31. """
  32. def __init__(self, prefix, cls=None):
  33. self.prefix = prefix
  34. self.cls = cls if cls else Module
  35. def __dir__(self):
  36. return [mod[(len(self.prefix) + 1):].replace('.', '_')
  37. for mod in fnmatch.filter(_CMDS, "%s.*" % self.prefix)]
  38. def __getattr__(self, name):
  39. return self.cls('%s.%s' % (self.prefix, name.replace('_', '.')))
  40. # http://grass.osgeo.org/grass73/manuals/full_index.html
  41. #[ d.* | db.* | g.* | i.* | m.* | ps.* | r.* | r3.* | t.* | v.* ]
  42. #
  43. # d.* display commands
  44. # db.* database commands
  45. # g.* general commands
  46. # i.* imagery commands
  47. # m.* miscellaneous commands
  48. # ps.* postscript commands
  49. # r.* raster commands
  50. # r3.* 3D raster commands
  51. # t.* temporal commands
  52. # v.* vector commands
  53. display = MetaModule('d')
  54. database = MetaModule('db')
  55. general = MetaModule('g')
  56. imagery = MetaModule('i')
  57. miscellaneous = MetaModule('m')
  58. postscript = MetaModule('ps')
  59. raster = MetaModule('r')
  60. raster3d = MetaModule('r3')
  61. temporal = MetaModule('t')
  62. vector = MetaModule('v')