shortcuts.py 2.2 KB

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