68 řádky
2.2 KiB
Python
68 řádky
2.2 KiB
Python
import os
|
|
from reqif import xml_parser
|
|
|
|
|
|
class reqif_dict(dict):
|
|
KEY_TITLE = 'titel'
|
|
KEY_COMMENT = 'comment'
|
|
KEY_ITEM_DICT = 'item_dict'
|
|
KEY_UID_LIST_SORTED = 'uid_list_sorted'
|
|
|
|
def __init__(self, filename, specification_key, specification_identifier):
|
|
dict.__init__(self)
|
|
self.rd = reqif(filename)
|
|
self[self.KEY_TITLE] = self.rd.get_title()
|
|
self[self.KEY_COMMENT] = self.rd.get_comment()
|
|
self[self.KEY_UID_LIST_SORTED] = []
|
|
for specification in self.rd.get_specifications():
|
|
if specification.get(specification_key) == specification_identifier:
|
|
sw_spec = specification
|
|
break
|
|
#
|
|
self[self.KEY_ITEM_DICT] = {}
|
|
for obj_id in sw_spec.children:
|
|
item = self.rd.get_spec_object(obj_id)
|
|
req_id = item.get('system_uid')
|
|
self[self.KEY_ITEM_DICT][req_id] = item
|
|
if req_id is not None:
|
|
self[self.KEY_UID_LIST_SORTED].append(req_id)
|
|
|
|
|
|
class reqif(object):
|
|
def __init__(self, filename):
|
|
self._data = xml_parser.parse(filename)
|
|
|
|
def get_comment(self):
|
|
return self._data._comment
|
|
|
|
def get_data_types(self):
|
|
return self._data._datatypes
|
|
|
|
def get_relations_by_id(self, obj_id):
|
|
rv = dict()
|
|
rv['incomming'] = list()
|
|
rv['outgoing'] = list()
|
|
for relation in self._data._relations:
|
|
if obj_id == relation[xml_parser.KEY_SOURCE]:
|
|
rv['outgoing'].append(relation)
|
|
elif obj_id == relation[xml_parser.KEY_TARGET]:
|
|
rv['incomming'].append(relation)
|
|
return rv
|
|
|
|
def get_specifications(self):
|
|
return self._data._specifications
|
|
|
|
def get_specification_by_id(self, obj_id):
|
|
for specification in self._data._specifications:
|
|
if obj_id == specification[xml_parser.KEY_SYSTEM_UID]:
|
|
return specification
|
|
|
|
def get_spec_object(self, obj_id):
|
|
return self._data._spec_objects[obj_id]
|
|
|
|
def get_spec_types(self):
|
|
return self._data._spec_types
|
|
|
|
def get_title(self):
|
|
return self._data._title
|