read.py 2.5 KB

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