read.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Apr 2 18:30:34 2013
  4. @author: pietro
  5. """
  6. from __future__ import (
  7. nested_scopes,
  8. generators,
  9. division,
  10. absolute_import,
  11. with_statement,
  12. print_function,
  13. unicode_literals,
  14. )
  15. def do_nothing(p):
  16. return p
  17. def get_None(p):
  18. return None
  19. def get_dict(p):
  20. return dict(p.items())
  21. def get_values(p):
  22. return [e.text.strip() for e in p.findall("value/name")]
  23. def read_text(p):
  24. return p.text.strip()
  25. def read_keydesc(par):
  26. name = par.text.strip()
  27. items = [e.text.strip() for e in par.findall("item")]
  28. return name, tuple(items) if len(items) > 1 else None
  29. GETFROMTAG = {
  30. "description": read_text,
  31. "keydesc": read_keydesc,
  32. "gisprompt": get_dict,
  33. "default": read_text,
  34. "values": get_values,
  35. "value": get_None,
  36. "guisection": read_text,
  37. "label": read_text,
  38. "suppress_required": get_None,
  39. "keywords": read_text,
  40. "guidependency": read_text,
  41. "rules": get_None,
  42. }
  43. GETTYPE = {
  44. "string": str,
  45. "integer": int,
  46. "float": float,
  47. "double": float,
  48. "file": str,
  49. "all": do_nothing,
  50. }
  51. def element2dict(xparameter):
  52. diz = dict(xparameter.items())
  53. for p in xparameter:
  54. if p.tag in GETFROMTAG:
  55. diz[p.tag] = GETFROMTAG[p.tag](p)
  56. else:
  57. print("New tag: %s, ignored" % p.tag)
  58. return diz
  59. # dictionary used to create docstring for the objects
  60. DOC = {
  61. # ------------------------------------------------------------
  62. # head
  63. "head": """{cmd_name}({cmd_params})
  64. Parameters
  65. ----------
  66. """,
  67. # ------------------------------------------------------------
  68. # param
  69. "param": """{name}: {default}{required}{multi}{ptype}
  70. {description}{values}{keydescvalues}""",
  71. # ------------------------------------------------------------
  72. # flag_head
  73. "flag_head": """
  74. Flags
  75. ------
  76. """,
  77. # ------------------------------------------------------------
  78. # flag
  79. "flag": """{name}: {default}, {supress}
  80. {description}""",
  81. # ------------------------------------------------------------
  82. # foot
  83. "foot": """
  84. Special Parameters
  85. ------------------
  86. The Module class have some optional parameters which are distinct using a final
  87. underscore.
  88. run_: True, optional
  89. If True execute the module.
  90. finish_: True, optional
  91. If True wait until the end of the module execution, and store the module
  92. outputs into stdout, stderr attributes of the class.
  93. stdin_: PIPE, optional
  94. Set the standard input.
  95. env_: dictionary, optional
  96. Set the environment variables.
  97. """,
  98. }