Python Library REQ-IF
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import optparse
  2. import os
  3. import xml_parser
  4. import reqif_conv
  5. class reqif_dict(dict):
  6. KEY_TITLE = 'titel'
  7. KEY_COMMENT = 'comment'
  8. KEY_ITEM_DICT = 'item_dict'
  9. KEY_UID_LIST_SORTED = 'uid_list_sorted'
  10. def __init__(self, filename, specification_key, specification_identifier):
  11. dict.__init__(self)
  12. self.rd = reqif(filename)
  13. self[self.KEY_TITLE] = self.rd.get_title()
  14. self[self.KEY_COMMENT] = self.rd.get_comment()
  15. self[self.KEY_UID_LIST_SORTED] = []
  16. for specification in self.rd.get_specifications():
  17. if specification.get(specification_key) == specification_identifier:
  18. sw_spec = specification
  19. break
  20. #
  21. self[self.KEY_ITEM_DICT] = {}
  22. for obj_id in sw_spec.children:
  23. item = self.rd.get_spec_object(obj_id)
  24. req_id = item.get('system_uid')
  25. self[self.KEY_ITEM_DICT][req_id] = item
  26. if req_id is not None:
  27. self[self.KEY_UID_LIST_SORTED].append(req_id)
  28. class reqif(object):
  29. def __init__(self, filename):
  30. self._data = xml_parser.parse(filename)
  31. def get_comment(self):
  32. return self._data._comment
  33. def get_data_types(self):
  34. return self._data._datatypes
  35. def get_relations_by_id(self, obj_id):
  36. rv = dict()
  37. rv['incomming'] = list()
  38. rv['outgoing'] = list()
  39. for relation in self._data._relations:
  40. if obj_id == relation[xml_parser.KEY_SOURCE]:
  41. rv['outgoing'].append(relation)
  42. elif obj_id == relation[xml_parser.KEY_TARGET]:
  43. rv['incomming'].append(relation)
  44. return rv
  45. def get_specifications(self):
  46. return self._data._specifications
  47. def get_specification_by_id(self, obj_id):
  48. for specification in self._data._specifications:
  49. if obj_id == specification[xml_parser.KEY_SYSTEM_UID]:
  50. return specification
  51. def get_spec_object(self, obj_id):
  52. return self._data._spec_objects[obj_id]
  53. def get_spec_types(self):
  54. return self._data._spec_types
  55. def get_title(self):
  56. return self._data._title
  57. if __name__ == '__main__':
  58. parser = optparse.OptionParser("usage: %%prog reqif_file [options]")
  59. (options, args) = parser.parse_args()
  60. #
  61. # Check options and args
  62. if len(args) != 1 or not os.path.isfile(args[0]):
  63. parser.print_help()
  64. else:
  65. reqif_path = args[0]
  66. tex_path = os.path.abspath(os.path.splitext(reqif_path)[0] + '.tex')
  67. reqif_data = reqif_dict(reqif_path, 'Heading', 'Software Specification')
  68. reqif_conv.tex_gen(reqif_data, tex_path)
  69. reqif_conv.pdf_gen(tex_path)