shortcuts.py 2.2 KB

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