Python Library REQ-IF
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

__init__.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from reqif import xml_parser
  2. from reqif import reqif_conv
  3. class reqif_dict(dict):
  4. KEY_TITLE = 'titel'
  5. KEY_COMMENT = 'comment'
  6. KEY_ITEM_DICT = 'item_dict'
  7. KEY_UID_LIST_SORTED = 'uid_list_sorted'
  8. def __init__(self, filename, specification_key, specification_identifier):
  9. dict.__init__(self)
  10. self.rd = reqif(filename)
  11. self[self.KEY_TITLE] = self.rd.get_title()
  12. self[self.KEY_COMMENT] = self.rd.get_comment()
  13. self[self.KEY_UID_LIST_SORTED] = []
  14. for specification in self.rd.get_specifications():
  15. if specification.get(specification_key) == specification_identifier:
  16. sw_spec = specification
  17. break
  18. #
  19. self[self.KEY_ITEM_DICT] = {}
  20. for obj_id in sw_spec.children:
  21. item = self.rd.get_spec_object(obj_id)
  22. req_id = item.get('system_uid')
  23. self[self.KEY_ITEM_DICT][req_id] = item
  24. if req_id is not None:
  25. self[self.KEY_UID_LIST_SORTED].append(req_id)
  26. class reqif(object):
  27. def __init__(self, filename):
  28. self._data = xml_parser.parse(filename)
  29. def get_comment(self):
  30. return self._data._comment
  31. def get_data_types(self):
  32. return self._data._datatypes
  33. def get_relations_by_id(self, obj_id):
  34. rv = dict()
  35. rv['incomming'] = list()
  36. rv['outgoing'] = list()
  37. for relation in self._data._relations:
  38. if obj_id == relation[xml_parser.KEY_SOURCE]:
  39. rv['outgoing'].append(relation)
  40. elif obj_id == relation[xml_parser.KEY_TARGET]:
  41. rv['incomming'].append(relation)
  42. return rv
  43. def get_specifications(self):
  44. return self._data._specifications
  45. def get_specification_by_id(self, obj_id):
  46. for specification in self._data._specifications:
  47. if obj_id == specification[xml_parser.KEY_SYSTEM_UID]:
  48. return specification
  49. def get_spec_object(self, obj_id):
  50. return self._data._spec_objects[obj_id]
  51. def get_spec_types(self):
  52. return self._data._spec_types
  53. def get_title(self):
  54. return self._data._title