read.py 2.5 KB

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