import optparse import os import xml_parser import reqif_conv 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 if __name__ == '__main__': parser = optparse.OptionParser("usage: %%prog reqif_file [options]") (options, args) = parser.parse_args() # # Check options and args if len(args) != 1 or not os.path.isfile(args[0]): parser.print_help() else: reqif_path = args[0] tex_path = os.path.abspath(os.path.splitext(reqif_path)[0] + '.tex') reqif_data = reqif_dict(reqif_path, 'Heading', 'Software Specification') reqif_conv.tex_gen(reqif_data, tex_path) reqif_conv.pdf_gen(tex_path)