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.

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