def __init__(self, language, is_cpp_api, class_object): self.language = language self.cap_language = language.upper() self.package = class_object['package'] self.class_name = class_object['name'] self.is_cpp_api = is_cpp_api if is_cpp_api: self.object_name = class_object['name'] else: self.object_name = class_object['name'] + '_t' self.concretes = class_object['concretes'] self.base_class = class_object['baseClass'] self.attributes = query.get_unique_attributes(class_object['attribs']) self.is_list_of = False if class_object['name'].startswith('ListOf'): self.is_list_of = True self.has_children = class_object['has_children'] self.child_elements = class_object['child_elements'] self.overwrites_children = class_object['overwrites_children'] if 'elementName' in class_object and class_object['elementName'] != '': self.xml_name = \ strFunctions.lower_first(class_object['elementName']) else: self.xml_name = strFunctions.lower_first(class_object['name']) self.is_plugin = False if 'is_plugin' in class_object: self.is_plugin = class_object['is_plugin'] self.is_doc_plugin = False if 'is_doc_plugin' in class_object: self.is_doc_plugin = class_object['is_doc_plugin'] self.document = False if 'document' in class_object: self.document = class_object['document']
def get_element_name_value(self, node, name): xml_element_name = '' temp = self.get_value(node, name) # we expect this to be camel case starting with lower if temp is not None: xml_element_name = strFunctions.lower_first(temp) return xml_element_name
def __init__(self, object_desc, spec_name, number, package, pkg_ref): # members from object self.name = object_desc['name'] self.fullname = spec_name self.number = number self.package = package.lower() self.pkg_ref = pkg_ref self.up_package = strFunctions.upper_first(self.package) # useful repeated text strings self.valid = '\\validRule{' self.start_b = '{' self.end_b = '}' self.lower_name = strFunctions.lower_first(strFunctions.remove_prefix(self.name)) self.formatted_name = '\{0}'.format(strFunctions.remove_prefix(self.name)) self.indef = strFunctions.get_indefinite(self.lower_name) self.indef_u = strFunctions.upper_first(self.indef) self.reqd_att = [] self.opt_att = [] self.reqd_elem = [] self.opt_elem = [] self.reqd_child_lo_elem = [] self.opt_child_lo_elem = [] self.parse_attributes(self, object_desc['attribs']) self.parse_elements(self, object_desc['attribs'], object_desc['root']) self.rules = [] self.tc = 'TBC'
def write_lo_class_definition(self, new_class): lo_name = strFunctions.lower_first(strFunctions.cap_list_of_name(new_class['name'])) comment = self.doc.createComment('definition of {0}'.format(lo_name)) self.doc.documentElement.appendChild(comment) element = self.doc.createElement('define') element.setAttribute('name', '{0}.datatype'.format(lo_name)) element.setAttribute('combine', 'interleave') interleave = self.doc.createElement('interleave') base = self.get_base_class(new_class['baseClass'], False) interleave.appendChild(base) child_elements = self.get_lo_children(strFunctions.lower_first(new_class['name'])) for attrib in new_class['lo_attribs']: attribute = self.get_attribute(attrib) interleave.appendChild(attribute) interleave.appendChild(child_elements) element.appendChild(interleave) return element
def adjust_line(line): lowerlibname = global_variables.library_name.lower() nonlibname = lowerlibname if lowerlibname.startswith('lib'): nonlibname = lowerlibname[3:] line = re.sub('nonlibsbml', nonlibname, line) line = re.sub('SBase', global_variables.std_base, line) line = re.sub('LIBSBML', global_variables.library_name.upper(), line) line = re.sub('LibSBML', strFunctions.upper_first(global_variables.library_name), line) line = re.sub('libSBML', strFunctions.lower_first(global_variables.library_name), line) line = re.sub('libsbml', lowerlibname, line) if lowerlibname.startswith('lib'): line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname[3:]), line) else: line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname), line) doctype = '{0}_DOCUMENT'.format(global_variables.language.upper()) if global_variables.document_class != 'SedDocument': doctype = 'LIB_{0}_{1}'.format(strFunctions.get_library_suffix(global_variables.library_name).upper(), strFunctions.remove_prefix(global_variables.document_class).upper()) line = re.sub('SBML_DOCUMENT', doctype, line) line = re.sub('SBMLDocument', global_variables.document_class, line) line = re.sub('toplevelname', strFunctions.lower_first(global_variables.top_level_element_name), line) line = re.sub('CAT_SBML', 'CAT_{0}'.format(global_variables.language.upper()), line) line = re.sub('SBML_Lang', '{0}'.format(global_variables.language.upper()), line) line = re.sub('SBML_', '{0}_'.format(global_variables.language.upper()), line) # hack for SedML if global_variables.prefix == 'Sed': line = re.sub('readSBML', 'read{0}ML'.format(global_variables.prefix), line) line = re.sub('writeSBML', 'write{0}ML'.format(global_variables.prefix), line) else: line = re.sub('readSBML', 'read{0}'.format(global_variables.language.upper()), line) line = re.sub('writeSBML', 'write{0}'.format(global_variables.language.upper()), line) line = re.sub('sbml', global_variables.language, line) line = re.sub('SBMLSBML', '{0}{1}'.format(strFunctions.upper_first(global_variables.language), global_variables.prefix), line) line = re.sub('SBML', global_variables.prefix, line) line = re.sub('ListOf', '{0}ListOf'.format(global_variables.prefix), line) line = re.sub('SPEC_NAMESPACE', '\"{0}\"'.format(global_variables.namespaces[0]['namespace']), line) line = re.sub('language_', '{0}'.format(global_variables.language.lower()), line) line = re.sub('LANGUAGE', '{0}'.format(global_variables.language.upper()), line) return line
def write_lo_class_definition(self, new_class): lo_name = strFunctions.lower_first( strFunctions.cap_list_of_name(new_class['name'])) comment = self.doc.createComment('definition of {0}'.format(lo_name)) self.doc.documentElement.appendChild(comment) element = self.doc.createElement('define') element.setAttribute('name', '{0}.datatype'.format(lo_name)) element.setAttribute('combine', 'interleave') interleave = self.doc.createElement('interleave') base = self.get_base_class(new_class['baseClass'], False) interleave.appendChild(base) child_elements = self.get_lo_children( strFunctions.lower_first(new_class['name'])) for attrib in new_class['lo_attribs']: attribute = self.get_attribute(attrib) interleave.appendChild(attribute) interleave.appendChild(child_elements) element.appendChild(interleave) return element
def get_mapping(self, node): name = '' package = '' temp = self.get_value(node, 'name') # expect camelcase with upper first if temp is not None: name = strFunctions.upper_first(temp) temp = self.get_value(node, 'package') # expect lower first if temp is not None: package = strFunctions.lower_first(temp) return [name, package]
def get_lo_element(self, attrib): lo_name = strFunctions.lower_first(strFunctions.cap_list_of_name(attrib['name'])) attrib_node = self.doc.createElement('element') attrib_node.setAttribute('name', '{0}'.format(lo_name)) ref = self.doc.createElement('ref') ref.setAttribute('name', '{0}.datatype'.format(lo_name)) attrib_node.appendChild(ref) if attrib['reqd']: return attrib_node else: optional = self.doc.createElement('optional') optional.appendChild(attrib_node) return optional
def create_object(self, parent): if 'base' in parent: name = strFunctions.lower_first(parent['base']) elif 'name' in parent: name = strFunctions.lower_first(parent['name']) else: name = 'FIXME' if 'ext' in parent: ext = parent['ext'] else: ext = self.pkg if name == 'math': return self.create_math_element() if ext != 'core': name = '{0}:{1}'.format(self.pkg, name) attribs = [] if 'attribs' in parent: attribs = self.get_attributes(parent['attribs'], ext) return self.create_element(name, attribs, parent)
def create_object(self, parent): if 'base' in parent: name = strFunctions.lower_first(parent['base']) elif 'name' in parent: name = strFunctions.lower_first(parent['name']) else: name = 'FIXME' if 'ext' in parent: ext = parent['ext'] else: ext = self.pkg if name == 'math': return self.create_math_element() if ext != 'core': name = '{0}:{1}'.format(self.pkg, name) attribs = [] if 'attribs' in parent: attribs = self.get_attributes(parent['attribs'], ext) return self.create_element(name, attribs, parent)
def get_lo_element(self, attrib): lo_name = strFunctions.lower_first( strFunctions.cap_list_of_name(attrib['name'])) attrib_node = self.doc.createElement('element') attrib_node.setAttribute('name', '{0}'.format(lo_name)) ref = self.doc.createElement('ref') ref.setAttribute('name', '{0}.datatype'.format(lo_name)) attrib_node.appendChild(ref) if attrib['reqd']: return attrib_node else: optional = self.doc.createElement('optional') optional.appendChild(attrib_node) return optional
def __init__(self, pkg_object): self.name = '{0}_example1'.format(pkg_object['name']) self.brief_description = \ 'Implementation of the example code for the {0} package' \ '.'.format(pkg_object['name']) BaseCppFile.BaseCppFile.__init__(self, self.name, 'cpp', None) self.package = strFunctions.lower_first(pkg_object['name']) self.package_up = strFunctions.upper_first(pkg_object['name']) self.reqd = 'true' if not pkg_object['required']: self.reqd = 'false' self.object_tree = query.create_object_tree(pkg_object)
def get_id(self, attrib, use_name=None): if 'parent' in attrib: name = strFunctions.lower_first(attrib['parent']['name']) elif use_name: name = use_name else: name = 'id' [found, index] = self.match_id_name(name) if not found: number = 1 self.start_id.append(dict({'name': name, 'number': number})) else: number = self.start_id[index]['number'] + 1 self.start_id[index]['number'] = number value = '{0}_{1}'.format(name, number) return value
def get_id_ref(self, attrib): name = attrib['name'] [found, index] = self.match_id_name(name) if found: number = self.start_id[index]['number'] elif 'element' in attrib and len(attrib['element']) > 0: name = strFunctions.lower_first(attrib['element']) [found, index] = self.match_id_name(name) if found: number = self.start_id[index]['number'] else: number = 1 else: number = 1 value = '{0}_{1}'.format(name, number) return value
def write_extended_element(self, plugin): name = strFunctions.lower_first(plugin['sbase']) comment = self.doc.createComment('extended of {0}'.format(name)) self.doc.documentElement.appendChild(comment) element = self.doc.createElement('define') element.setAttribute('name', '{0}.datatype'.format(name)) element.setAttribute('combine', 'interleave') interleave = self.doc.createElement('interleave') for lo_extension in plugin['lo_extension']: lo_extension['reqd'] = False child = self.get_lo_element(lo_extension) interleave.appendChild(child) for attrib in plugin['attribs']: attribute = self.get_attribute(attrib) interleave.appendChild(attribute) element.appendChild(interleave) return element
def write_extended_element(self, plugin): name = strFunctions.lower_first(plugin['sbase']) comment = self.doc.createComment('extended of {0}'.format(name)) self.doc.documentElement.appendChild(comment) element = self.doc.createElement('define') element.setAttribute('name', '{0}.datatype'.format(name)) element.setAttribute('combine', 'interleave') interleave = self.doc.createElement('interleave') for lo_extension in plugin['lo_extension']: lo_extension['reqd'] = False child = self.get_lo_element(lo_extension) interleave.appendChild(child) for attrib in plugin['attribs']: attribute = self.get_attribute(attrib) interleave.appendChild(attribute) element.appendChild(interleave) return element
def get_attribute_description(self, node, version_count): version_info = [] for i in range(0, self.num_versions): version_info.append(False) version_info[version_count] = True attr_name = self.get_value(node, 'name') if not attr_name: self.report_error( global_variables.return_codes['missing required information'], 'An attribute must have a Name') required = self.get_bool_value(self, node, 'required') attr_type = self.get_type_value(self, node) if not attr_type: self.report_error( global_variables.return_codes['missing required information'], 'An attribute must have a Type') attr_abstract = self.get_bool_value(self, node, 'abstract') attr_element = self.get_element_value(self, node) # if the type if lo_element we actually want the name to be # just that of the element if attr_type == 'lo_element': attr_name = strFunctions.lower_first(attr_element) # xml name defaults to name attr_xml_name = self.get_value(node, 'xmlName') if not attr_xml_name: attr_xml_name = attr_name attribute_dict = dict({ 'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract, 'xml_name': attr_xml_name, 'num_versions': self.num_versions, 'version': version_count, 'version_info': version_info }) if attr_abstract: attribute_dict['concrete'] = self.concrete_dict[attr_element] return attribute_dict
def get_attribute_description(self, node, pkg_version): version_info = [] for i in range(0, self.num_versions): version_info.append(False) version_info[pkg_version-1] = True attr_name = self.get_value(node, 'name') if not attr_name: self.report_error(global_variables .return_codes['missing required information'], 'An attribute must have a Name') required = self.get_bool_value(self, node, 'required') attr_type = self.get_type_value(self, node) if not attr_type: self.report_error(global_variables .return_codes['missing required information'], 'An attribute must have a Type') attr_abstract = self.get_bool_value(self, node, 'abstract') attr_element = self.get_element_value(self, node) # if the type if lo_element we actually want the name to be # just that of the element if attr_type == 'lo_element': attr_name = strFunctions.lower_first(attr_element) # xml name defaults to name attr_xml_name = self.get_value(node, 'xmlName') if not attr_xml_name: attr_xml_name = attr_name attribute_dict = dict({'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract, 'xml_name': attr_xml_name, 'num_versions': self.num_versions, 'version': pkg_version, 'version_info': version_info }) if attr_abstract: attribute_dict['concrete'] = self.concrete_dict[attr_element] return attribute_dict
def write_code_for_plugin(self, i, code): parent = self.object_tree[i]['base'] parent_name = strFunctions.lower_first(parent) abbrev = strFunctions.abbrev_name(parent) plugin_class = '{0}{1}Plugin'.format(self.package_up, parent) plugin_name = '{0}plugin'.format(abbrev) code.append(self.create_code_block('line', ['{0}* {1} = document->create{0}()' ''.format(parent, parent_name)])) code.append(self.create_code_block('line', ['{0}* {1} = static_cast<{0}*>' '({2}->getPlugin(\"{3}\"))' ''.format(plugin_class, plugin_name, parent_name, self.package)])) for j in range(0, len(self.object_tree[i]['children'])): self.write_code_for_children(plugin_name, self.object_tree[i]['children'][j], code)
def create_lo_other_child_element_class(self, name, parent): capname = strFunctions.upper_first(name) element = dict({'isArray': False, 'name': strFunctions.lower_first(capname), 'attTypeCode': capname + '*', 'CType': capname + '_t *', 'capAttName': capname, 'attType': 'element', 'memberName': 'm' + capname, 'isNumber': False, 'type': 'element', 'default': 'NULL', 'element': capname, 'is_ml': False, 'children_overwrite': False, 'abstract': False}) child_class = dict({'name': parent, 'package': self.package, 'class_attributes': [], 'child_elements': [element]}) return child_class
def get_id_ref(self, attrib): """ :param attrib: dictionary structure representing an <attribute> node?? :return: """ name = attrib['name'] [found, index] = self.match_id_name(name) if found: number = self.start_id[index]['number'] elif 'element' in attrib and len(attrib['element']) > 0: name = strFunctions.lower_first(attrib['element']) [found, index] = self.match_id_name(name) if found: number = self.start_id[index]['number'] else: number = 1 else: number = 1 value = '{0}_{1}'.format(name, number) return value
def write_get_fieldname_function(self, functionType): length = len(functionType) if not functionType.endswith('s'): length += 1 self.write_line( 'function [found, fhandle] = get{0}{1}Function(typecode)'.format( self.up_pack, functionType[0:length - 1])) self.up_indent() self.write_line('found = 1;') self.write_line('switch (typecode)') self.up_indent() for sbmlclass in self.sbml_classes: self.write_line_verbatim( 'case {0}\'{1}\', \'{3}\', \'{4}\', \'{6}_{4}\'{5}'.format( self.open_br, sbmlclass['typecode'], sbmlclass['name'].upper(), sbmlclass['name'], strFunctions.lower_first(sbmlclass['name']), self.close_br, self.package)) self.up_indent() self.write_line('fhandle = str2func(\'get{0}{1}\');'.format( sbmlclass['name'], functionType)) self.down_indent() for plugin in self.plugins: self.write_line_verbatim( 'case {0}\'SBML_{1}_{2}\', \'{1}{3}\', \'SBML_{2}\', \'{3}\', \'{4}\'{5}' .format(self.open_br, self.up_pack, plugin['sbase'].upper(), plugin['sbase'], plugin['sbase'].lower(), self.close_br)) self.up_indent() self.write_line('fhandle = str2func(\'get{0}{1}{2}\');'.format( self.up_pack, plugin['sbase'], functionType)) self.down_indent() self.write_line('otherwise') self.up_indent() self.write_line('fhandle = str2func(\'disp\');') self.write_line('found = 0;') self.down_indent() self.down_indent() self.write_line('end;') self.down_indent()
def __init__(self, lib_object, verbose=False): # members from object self.lib_object = lib_object self.verbose = verbose self.package = strFunctions.lower_first(lib_object['name']) self.reqd = 'false' if lib_object['required']: self.reqd = 'true' self.offset = lib_object['offset'] self.sbml_classes = lib_object['baseElements'] self.enums = lib_object['enums'] self.plugins = lib_object['plugins'] self.fullname = lib_object['fullname'] self.level = lib_object['base_level'] self.version = lib_object['base_version'] self.pkg_version = lib_object['pkg_version'] self.pkg_ref = 'NA' self.reqd_status = lib_object['required'] self.tree = query.create_object_tree(lib_object, False) self.class_rules = []
def __init__(self, lib_object, verbose=False): # members from object self.lib_object = lib_object self.verbose = verbose self.package = strFunctions.lower_first(lib_object['name']) self.reqd = 'false' if lib_object['required']: self.reqd = 'true' self.offset = lib_object['offset'] self.sbml_classes = lib_object['baseElements'] self.enums = lib_object['enums'] self.plugins = lib_object['plugins'] self.fullname = lib_object['fullname'] self.level = lib_object['base_level'] self.version = lib_object['base_version'] self.pkg_version = lib_object['pkg_version'] self.pkg_ref = 'NA' self.reqd_status = lib_object['required'] self.tree = query.create_object_tree(lib_object, False) self.class_rules = []
def __init__(self, object_desc, spec_name, number, package, pkg_ref): # members from object self.name = strFunctions.remove_prefix(object_desc['name'], remove_doc_prefix=True) self.fullname = spec_name self.number = number self.package = package.lower() self.pkg_ref = pkg_ref self.up_package = strFunctions.upper_first(self.package) # useful repeated text strings self.valid = '\\validRule{' self.start_b = '{' self.end_b = '}' self.lower_name = strFunctions.lower_first( strFunctions.remove_prefix(self.name)) self.formatted_name = '\{0}'.format( strFunctions.remove_prefix(self.name)) self.indef = strFunctions.get_indefinite(self.lower_name) self.indef_u = strFunctions.upper_first(self.indef) self.reqd_att = [] self.opt_att = [] self.reqd_elem = [] self.opt_elem = [] self.reqd_child_lo_elem = [] self.opt_child_lo_elem = [] self.lo_reqd_att = [] self.lo_opt_att = [] self.parse_attributes(self, object_desc['attribs'], object_desc['lo_attribs']) self.parse_elements(self, object_desc['attribs'], object_desc['root']) self.rules = [] self.tc = 'TBC'
def get_tests(self, rule): passes = [] tc = rule['typecode'] test_needed = [] if tc.endswith('Unknown'): test_needed = [] elif tc.endswith('NSUndeclared'): test_needed = [ dict({'name': 'missing_ns'}), dict({'name': 'incorrect_ns'}) ] elif tc.endswith('AttributeRequiredMissing'): test_needed = [dict({'name': 'missing_reqd'})] elif tc.endswith('AttributeRequiredMustBeBoolean'): test_needed = [dict({'name': 'incorrect_type_reqd'})] elif tc.endswith('AttributeRequiredMustHaveValue'): test_needed = [dict({'name': 'incorrect_value_reqd'})] elif tc.endswith('EmptyLOElements'): for element in rule['lo_object']: loname = element['listOfClassName'] test_needed.append( dict({ 'name': 'empty_lo', 'object': rule['object'], 'lo_child': loname })) elif tc.endswith('AllowedElements'): for element in rule['opt']: name = self.get_name(element) test_needed.append( dict({ 'name': 'duplicate_element', 'object': rule['object'], 'child': name })) for element in rule['reqd']: name = self.get_name(element) test_needed.append( dict({ 'name': 'remove_element', 'object': rule['object'], 'child': name })) test_needed.append( dict({ 'name': 'duplicate_element', 'object': rule['object'], 'child': name })) elif tc.endswith('AllowedCoreElements'): if self.is_lo_rule(rule): for element in rule['opt']: name = self.get_name(element) test_needed.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': name })) passes.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'annotation' })) passes.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'notes' })) for element in rule['reqd']: name = self.get_name(element) test_needed.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': name })) passes.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'annotation' })) passes.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'notes' })) else: test_needed.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': rule['object'] })) passes.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': rule['object'], 'type': 'annotation' })) passes.append( dict({ 'name': 'add_core_element', 'object': rule['object'], 'child': rule['object'], 'type': 'notes' })) elif tc.endswith('AllowedCoreAttributes'): if self.is_lo_rule(rule): for element in rule['opt']: name = self.get_name(element) test_needed.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': name })) passes.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'metaid' })) passes.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'sboTerm' })) for element in rule['reqd']: name = self.get_name(element) test_needed.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': name })) passes.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'metaid' })) passes.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'sboTerm' })) else: test_needed.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': rule['object'] })) passes.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': rule['object'], 'type': 'metaid' })) passes.append( dict({ 'name': 'add_core_attribute', 'object': rule['object'], 'child': rule['object'], 'type': 'sboTerm' })) elif tc.endswith('AllowedAttributes'): if self.is_lo_rule(rule): test_needed.append( dict({ 'name': 'add_pkg_attribute', 'object': rule['object'], 'child': rule['lo_object'] })) for attribute in rule['opt']: name = attribute['name'] passes.append( dict({ 'name': 'remove_attribute', 'object': rule['object'], 'child': rule['lo_object'], 'attrib': name })) for attribute in rule['reqd']: name = attribute['name'] test_needed.append( dict({ 'name': 'remove_attribute', 'object': rule['object'], 'child': rule['lo_object'], 'attrib': name })) else: test_needed.append( dict({ 'name': 'add_pkg_attribute', 'object': rule['object'], 'child': rule['object'] })) for attribute in rule['opt']: name = attribute['name'] passes.append( dict({ 'name': 'remove_attribute', 'object': rule['object'], 'child': rule['object'], 'attrib': name })) for attribute in rule['reqd']: name = attribute['name'] test_needed.append( dict({ 'name': 'remove_attribute', 'object': rule['object'], 'child': rule['object'], 'attrib': name })) elif self.is_attribute_type_rule(tc): test_needed.append( dict({ 'name': 'replace_attribute', 'object': rule['object'], 'child': rule['object'], 'attrib': strFunctions.lower_first(rule['attrib']), 'att_type': rule['attrib_type'] })) else: print(tc + ' not done') print(tc + ' done ' + str(rule['number'])) return [test_needed, passes]
def adjust_line(line): """ Replace certain items in a line of code. :param line: the line before replacement(s) :return: the line after replacement(s) """ lowerlibname = gv.library_name.lower() nonlibname = lowerlibname if lowerlibname.startswith('lib'): nonlibname = lowerlibname[3:] # Remove leading "lib" line = re.sub('nonlibsbml', nonlibname, line) line = re.sub('SBase', gv.std_base, line) line = re.sub('LIBSBML', gv.library_name.upper(), line) line = re.sub('LibSBML', SF.upper_first(gv.library_name), line) line = re.sub('libSBML', SF.lower_first(gv.library_name), line) line = re.sub('libsbml', lowerlibname, line) if lowerlibname.startswith('lib'): line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname[3:]), line) else: line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname), line) doctype = '{0}_DOCUMENT'.format(gv.language.upper()) # if gv.document_class != 'SedDocument': # doctype = 'LIB_{0}_{1}'. # format(SF.get_library_suffix(gv.library_name).upper(), # SF.remove_prefix(gv.document_class).upper()) line = re.sub('SBML_DOCUMENT', doctype, line) line = re.sub('SBMLDocument', gv.document_class, line) line = re.sub('toplevelname', gv.top_level_element_name, line) line = re.sub('CAT_SBML', 'CAT_{0}'.format(gv.language.upper()), line) line = re.sub('SBML_Lang', '{0}'.format(gv.language.upper()), line) line = re.sub('SBML_', '{0}_'.format(gv.language.upper()), line) # hack for SedML if gv.prefix == 'Sed': line = re.sub('readSBML', 'read{0}ML'.format(gv.prefix), line) line = re.sub('writeSBML', 'write{0}ML'.format(gv.prefix), line) else: line = re.sub('readSBML', 'read{0}'.format(gv.language.upper()), line) line = re.sub('writeSBML', 'write{0}'.format(gv.language.upper()), line) line = re.sub('sbml', gv.language, line) line = re.sub('SBMLSBML', '{0}{1}'.format(SF.upper_first(gv.language), gv.prefix), line) line = re.sub('SBML', gv.prefix, line) line = re.sub('ListOf', '{0}ListOf'.format(gv.prefix), line) line = re.sub('<SPEC_NAMESPACE>', '\"{0}\"'.format(gv.namespaces[-1]['namespace']), line) line = re.sub('language_', '{0}'.format(gv.language.lower()), line) line = re.sub('LANGUAGE', '{0}'.format(gv.language.upper()), line) if gv.namespaces is not None and len(gv.namespaces) > 0 \ and 'level' in gv.namespaces[-1]: line = re.sub('<SPEC_LEVEL>', '{0}'.format(gv.namespaces[-1]['level']), line) line = re.sub('<SPEC_VERSION>', '{0}'.format(gv.namespaces[-1]['version']), line) if gv.annot_element is not None: line = re.sub('<Annotation>', gv.annot_element, line) line = re.sub('<annotation_variable>', '\"{0}\"'.format(SF.lower_first(gv.annot_element)), line) if gv.notes_element is not None: line = re.sub('<Notes>', gv.notes_element, line) line = re.sub('<notes_variable>', '\"{0}\"'.format(SF.lower_first(gv.notes_element)), line) line = re.sub('<NS>', 'LIBSBML_CPP_NAMESPACE_QUALIFIER ', line) return line
def write_create_object(self): if not self.is_cpp_api: return elif self.is_list_of: return if len(self.elements) == 0: return # create comment parts params = [] return_lines = [] additional = [] title_line = 'Creates and returns an new "elementName" object in this {0}.' \ .format(self.class_name) params.append('@param elementName, the name of the element to create.') return_lines.append('@return pointer to the element created.') # create the function declaration function = 'createChildObject' # if self.is_plugin: return_type = '{0}*'.format(global_variables.baseClass) arguments = ['const std::string& elementName'] code = [] # create the function implementation if self.is_plugin: first_line = ['{0}* obj = NULL'.format(global_variables.baseClass)] else: first_line = ['{0}* obj = NULL'.format(self.base_class)] last_line = ['return obj'] if not self.has_elements_with_same_xml_name(): first = True block = [] if_block = [] for elem in self.elements: if elem['concrete']: for conc in elem['concrete']: if not first: block.append('else if') else: first = False concname = conc['name'] concelem = conc['name'] if conc['name'].lower() != conc['element'].lower(): concelem = strFunctions.lower_first( strFunctions.remove_prefix(conc['element'])) # hack for render if self.package == 'Render' or self.package == 'render': remove_prefix = True prefix_to_remove = strFunctions.upper_first( self.package) concelem = strFunctions.remove_prefix( conc['element'], False, remove_prefix, prefix_to_remove) block.append('elementName == \"{0}\"'.format(concname)) block.append('return create{0}()'.format( strFunctions.upper_first(concelem))) if len(block) > 2: if_block = self.create_code_block('else_if', block) else: if_block = self.create_code_block('if', block) else: if not first: block.append('else if') else: first = False block.append('elementName == \"{0}\"'.format(elem['name'])) [elem_name, unused] = strFunctions.remove_hyphens(elem['name']) block.append('return create{0}()'.format( strFunctions.upper_first(elem_name))) if len(block) > 2: if_block = self.create_code_block('else_if', block) else: if_block = self.create_code_block('if', block) code = [ self.create_code_block('line', first_line), if_block, self.create_code_block('line', last_line) ] else: code = [ self.create_code_block('line', first_line), self.create_code_block('comment', ['TO DO']), self.create_code_block('line', last_line) ] # return the parts return dict({ 'title_line': title_line, 'params': params, 'return_lines': return_lines, 'additional': additional, 'function': function, 'return_type': return_type, 'arguments': arguments, 'constant': False, 'virtual': True, 'object_name': self.struct_name, 'implementation': code })
def write_jsbml_constants(self): self.up_indent() base_level = self.original_package['base_level'] base_version = self.original_package['base_version'] package_version = self.original_package['pkg_version'] package_name = self.original_package['name'] title_line = 'The namespace URI of this parser for SBML level {0}, version {1} \ and package version {2}.'.format(base_level, base_version, package_version) self.write_brief_header(title_line) self.namespace_uri = 'namespaceURI_L{0}V{1}V{2}'.format(base_level, base_version, package_version) line = 'public static final String {0} = "http://www.sbml.org/sbml/level{1}/version{2}/{4}/version{3}"'.\ format(self.namespace_uri, base_level, base_version, package_version, package_name) self.write_jsbml_line_verbatim(line) title_line = 'The latest namespace URI of this parser, this value can change between releases.' self.write_brief_header(title_line) line = 'public static final String namespaceURI = {0}'.format(self.namespace_uri) self.write_jsbml_line_verbatim(line) # This part is for write ResourceBundle variable # self.write_variable_comment() # line = 'public static final ResourceBundle bundle = ResourceManager' \ # '.getBundle("org.sbml.jsbml.ext.{0}.Messages")'.format(package_name) # # self.write_line(line) # self.write_jsbml_line_verbatim(line) self.write_variable_comment() line = 'public static final String shortLabel = "{0}"'.format(package_name) # self.write_line(line) self.write_jsbml_line_verbatim(line) self.write_variable_comment() line = 'public static final int MIN_SBML_LEVEL = {0}'.format(base_level) # self.write_line(line) self.write_jsbml_line_verbatim(line) self.write_variable_comment() line = 'public static final int MIN_SBML_VERSION = {0}'.format(base_version) # self.write_line(line) self.write_jsbml_line_verbatim(line) self.write_variable_comment() line = 'public static final int PACKAGE_VERSION = {0}'.format(package_version) # self.write_line(line) self.write_jsbml_line_verbatim(line) self.write_variable_comment() line = 'public static final List<String> namespaces' self.write_jsbml_line_verbatim(line) self.write_variable_comment() full_name = self.original_package['fullname'] line = 'public static final String packageName = "{0}"'.format(full_name) self.write_jsbml_line_verbatim(line) #Write static self.write_static(self.namespace_uri) # Attributes part self.write_serial_version_comment() # TODO need to change serialVersionUID line = 'private static final long serialVersionUID = {0}L'.format(self.serialVersionUID) self.write_jsbml_line_verbatim(line) # write attributes, but make sure that there are no duplicates attribs_to_write = [] attribs_name_to_write = [] base_elements = self.original_package['baseElements'] for element in base_elements: attributes = element['attribs'] for attribute in attributes: # print(attribute['memberName']) name = attribute['name'] if str(name) != 'id' and str(name) != 'name': if name not in attribs_name_to_write: attribs_to_write.append(attribute) attribs_name_to_write.append(name) elements = self.original_package['elements'] for element in elements: # print(attribute['memberName']) name = strFunctions.lower_first(element['name']) if str(name) != 'id' and str(name) != 'name': if name not in attribs_name_to_write: attribs_to_write.append(element) attribs_name_to_write.append(name) plugin_elements = self.original_package['plugins'] for element in plugin_elements: attributes = element['attribs'] for attribute in attributes: # print(attribute['memberName']) name = attribute['name'] if str(name) != 'id' and str(name) != 'name': if name not in attribs_name_to_write: attribs_to_write.append(attribute) attribs_name_to_write.append(name) for attribute in attribs_to_write: self.write_variable_comment() name = attribute['name'] write_name = strFunctions.lower_first(name) line = 'public static final String {0} = "{1}"'.format(write_name, write_name) self.write_jsbml_line_verbatim(line) if 'type' in list(attribute.keys()): if attribute['type'] == 'lo_element': self.write_variable_comment() write_name = strFunctions.upper_first(name) line = 'public static final String listOf{0}s = "listOf{0}s"'.format(write_name) self.write_jsbml_line_verbatim(line) self.down_indent() get_namespace_uri_func = self.get_namespace_uri() self.write_function_implementation(get_namespace_uri_func) self.up_indent() self.down_indent()
def write_attribute_type_rule(self, attribute, lo=None): if lo: formatted_name = lo['formatted_name'] refname = lo['name'] abbrev = strFunctions.abbrev_lo_name(refname) else: formatted_name = self.formatted_name refname = self.name abbrev = self.name att_type = attribute['type'] [att_name_no_hyphen, unused] = strFunctions.remove_hyphens(attribute['name']) att_name = strFunctions.upper_first(att_name_no_hyphen) name = strFunctions.wrap_token(attribute['texname'], self.package) rule_type = 'String' if att_type == 'SId': return elif att_type == 'SIdRef': [ref_name, ref_type] = \ strFunctions.get_sid_refs(attribute['element']) # hack for render if ref_name == 'StartHead' or ref_name == 'EndHead': ref_name = 'LineEnding' if ref_name == 'SBase': text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing object derived from the \SBase class and defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, formatted_name, ref_name) else: text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing \{3} object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, formatted_name, ref_name) rule_type = ref_type elif att_type == 'string': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('string')) elif att_type == 'ID': text = 'The attribute {0} on {1} {2} must have a value of XML data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('ID')) elif att_type == 'IDREF': text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the \'metaid\' of an existing \SBase object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, formatted_name) rule_type = 'SBase' elif att_type == 'int' or att_type == 'uint': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}{4}'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('integer'), '.' if att_type == 'int' else ', and must be non negative.') rule_type = 'Integer' if att_type == 'int' else 'NonNegativeInteger' elif att_type == 'double': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('double')) rule_type = 'Double' elif att_type == 'boolean' or att_type == 'bool': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token('boolean')) rule_type = 'Boolean' elif att_type == 'UnitSId' or att_type == 'UnitSIdRef': text = 'The value of the attribute {0} on {1} {2} must have a ' \ 'taken from the following: the identifier of a ' \ '\\UnitDefinition object in the enclosing \Model, or one ' \ 'of the base units in SBML.'.format(name, self.indef, formatted_name) rule_type = 'UnitSId' elif att_type == 'enum': enum_name = strFunctions.texify(attribute['element']) enums = attribute['parent']['root']['enums'] enum_values = self.parse_enum_values(attribute['element'], enums) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type {3} and ' \ 'may only take on the allowed values of {3} defined ' \ 'in SBML; that is, the value must be one of the ' \ 'following: {4}.'.format(name, self.indef, formatted_name, strFunctions.wrap_enum(enum_name), enum_values) rule_type = '{0}Enum'.format(attribute['element']) elif att_type == 'array': array_type = strFunctions.lower_first(attribute['element']) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'be an array of values of type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token(array_type)) elif att_type == 'vector': array_type = strFunctions.lower_first(attribute['element']) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'be an vector of values of type {3}.'\ .format(name, self.indef, formatted_name, strFunctions.wrap_token(array_type)) elif att_type == 'element' and attribute['element'] == 'RelAbsVector': text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type \\RelAbsVector, ' \ 'i.e., a string encoding optionally an absolute number ' \ 'followed by an optional relative number followed ' \ 'by a \\% sign. Adding spaces between the ' \ 'coordinates is encouraged, but not required.'\ .format(name, self.indef, formatted_name) else: text = 'FIXME: Encountered an unknown attribute type {0} in ' \ 'ValidationRulesForClass'\ .format(att_type) # global_variables.code_returned = \ # global_variables.return_codes['unknown type used'] ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(refname)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) if att_type == 'SIdRef' or att_type == 'IDREF': short = 'The attribute \'{0}\' must point to {1} object.'.format( strFunctions.lower_first(att_name), rule_type) else: short = 'The \'{0}\' attribute must be {1}.'.format( strFunctions.lower_first(att_name), rule_type) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}{2}MustBe{3}'.format(self.up_package, abbrev, att_name, rule_type) return dict({ 'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'object': refname, 'attrib': att_name, 'attrib_type': att_type })
def write_attribute_type_rule(self, attribute, lo=None): if lo: formatted_name = lo['formatted_name'] refname = lo['name'] abbrev = strFunctions.abbrev_lo_name(refname) else: formatted_name = self.formatted_name refname = self.name abbrev = self.name att_type = attribute['type'] att_name = strFunctions.upper_first(attribute['name']) name = strFunctions.wrap_token(attribute['texname'], self.package) rule_type = 'String' if att_type == 'SId': return elif att_type == 'SIdRef': [ref_name, ref_type] = \ strFunctions.get_sid_refs(attribute['element']) # hack for render if ref_name == 'StartHead' or ref_name == 'EndHead': ref_name = 'LineEnding' if ref_name == 'SBase': text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing object derived from the \SBase class and defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, self.formatted_name, ref_name) else: text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the identifier of an existing \{3} object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, self.formatted_name, ref_name) rule_type = ref_type elif att_type == 'string': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('string')) elif att_type == 'ID': text = 'The attribute {0} on {1} {2} must have a value of XML data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('ID')) elif att_type == 'IDREF': text = 'The value of the attribute {0} of {1} {2} object must be ' \ 'the \'metaid\' of an existing \SBase object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, formatted_name) rule_type = 'SBase' elif att_type == 'int' or att_type == 'uint': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}{4}'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('integer'), '.' if att_type == 'int' else ', and must be non negative.') rule_type = 'Integer' if att_type == 'int' else 'NonNegativeInteger' elif att_type == 'double': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('double')) rule_type = 'Double' elif att_type == 'bool' or att_type == 'boolean': text = 'The attribute {0} on {1} {2} must have a value of data ' \ 'type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('boolean')) rule_type = 'Boolean' elif att_type == 'UnitSId' or att_type == 'UnitSIdRef': text = 'The value of the attribute {0} on {1} {2} must have a ' \ 'taken from the following: the identifier of a ' \ '\\UnitDefinition object in the enclosing \Model, or one ' \ 'of the base units in SBML.'.format(name, self.indef, formatted_name) rule_type = 'UnitSId' elif att_type == 'enum': enum_name = attribute['element'] enums = attribute['parent']['root']['enums'] enum_values = self.parse_enum_values(enum_name, enums) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type {3} and ' \ 'may only take on the allowed values of {3} defined ' \ 'in SBML; that is, the value must be one of the ' \ 'following {4}.'.format(name, self.indef, self.formatted_name, strFunctions.wrap_enum(enum_name), enum_values) rule_type = '{0}Enum'.format(attribute['element']) elif att_type == 'array': array_type = strFunctions.lower_first(attribute['element']) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'be an array of values of type {3}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token(array_type)) else: text = 'FIX ME: Encountered an unknown attribute type {0} in ' \ 'ValidationRulesForClass:write_attribute_type_rule'\ .format(att_type) add_extended = True if self.package == 'render': add_extended = False ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name, True, add_extended)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = '{0} attribute must be {1}.'.format(att_name, rule_type) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}{2}MustBe{3}'.format(self.up_package, self.name, att_name, rule_type) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'plugin': True, 'object': self.name, 'lo': False, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'attrib': attribute['name'], 'attrib_type': att_type})
def create_top_object(self, tree): name = strFunctions.lower_first(tree['base']) if tree['ext'] == 'core': element = self.create_object(tree) return element
def parse_deviser_xml(filename): """ Parses the given filename and returns a dictionary with the definition contained in it """ sbml_elements = [] elements = [] plugins = [] enums = [] dom = parse(filename) temp = get_value(dom.documentElement, 'name') # we expect this to be lower case package_name = temp.lower() number = to_int(get_value(dom.documentElement, 'number')) offset = to_int(get_value(dom.documentElement, 'offset')) fullname = get_value(dom.documentElement, 'fullname') required = to_bool(get_value(dom.documentElement, 'required')) # get package information (assume we want the first only) sbml_level = 3 sbml_version = 1 pkg_version = 1 for node in dom.getElementsByTagName('pkgVersion'): sbml_level = to_int(get_value(node, 'level')) sbml_version = to_int(get_value(node, 'version')) pkg_version = to_int(get_value(node, 'pkg_version')) break concrete_dict = dict({}) # read concrete versions of abstract classes and fill dictionary for node in dom.getElementsByTagName('element'): element_name = get_value(node, 'name') concrete_list = [] for concrete in node.getElementsByTagName('concrete'): concrete_list.append( dict( {'name': get_value(concrete, "name"), 'element': get_value(concrete, "element")} )) concrete_dict[element_name] = concrete_list # read element for node in dom.getElementsByTagName('element'): element_name = get_value(node, 'name') base_class = get_value(node, 'baseClass') type_code = get_value(node, 'typeCode') has_math = to_bool(get_value(node, 'hasMath')) has_children = to_bool(get_value(node, 'hasChildren')) has_list_of = to_bool(get_value(node, 'hasListOf')) abstract = to_bool(get_value(node, 'abstract')) children_overwrite_element_name = to_bool( get_value(node, 'childrenOverwriteElementName')) temp = get_value(node, 'elementName') # we expect this to be camel case starting with lower if temp is not None: xml_element_name = strFunctions.lower_first(temp) else: xml_element_name = '' temp = get_value(node, 'listOfName') # we expect this to be camel case starting with lower if temp is not None: xml_lo_element_name = strFunctions.lower_first(temp) else: xml_lo_element_name = '' temp = get_value(node, 'listOfClassName') # we expect this to be camel case starting with upper if temp is not None: lo_class_name = strFunctions.upper_first(temp) else: lo_class_name = '' add_decls = get_value(node, 'additionalDecls') add_defs = get_value(node, 'additionalDefs') attributes = [] # add attributes for attr in node.getElementsByTagName('attribute'): attr_name = get_value(attr, 'name') required = to_bool(get_value(attr, 'required')) attr_type = standardize_types(get_value(attr, 'type')) attr_abstract = to_bool(get_value(attr, 'abstract')) temp = get_value(attr, 'element') # expect this to be uppercase if temp is not None: attr_element = strFunctions.standard_element_name(temp) else: attr_element = '' attribute_dict = dict({'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract, }) if attr_abstract: attribute_dict['concrete'] = concrete_dict[attr_element] attributes.append(attribute_dict) lo_attributes = [] # add attributes for attr in node.getElementsByTagName('listOfAttribute'): attr_name = get_value(attr, 'name') required = to_bool(get_value(attr, 'required')) attr_type = get_value(attr, 'type') attr_abstract = to_bool(get_value(attr, 'abstract')) attr_element = get_value(attr, 'element') attribute_dict = dict({'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract}) if attr_abstract: attribute_dict['concrete'] = concrete_dict[attr_element] lo_attributes.append(attribute_dict) # construct element element = dict({'name': element_name, 'package': package_name, 'typecode': type_code, 'hasListOf': has_list_of, 'attribs': attributes, 'lo_attribs': lo_attributes, 'hasChildren': has_children, 'hasMath': has_math, 'childrenOverwriteElementName': children_overwrite_element_name, 'baseClass': base_class, 'abstract': abstract }) if xml_element_name is not None: element['elementName'] = xml_element_name if xml_lo_element_name is not None: element['lo_elementName'] = xml_lo_element_name if lo_class_name is not None: element['lo_class_name'] = lo_class_name if add_decls is not None: temp = os.path.dirname(filename) + '//' + add_decls if os.path.exists(temp): add_decls = os.path.abspath(temp) element['addDecls'] = add_decls if add_defs is not None: if os.path.exists(os.path.dirname(filename) + '/' + add_defs): add_defs += os.path.abspath(filename) + '/' element['addDefs'] = add_defs if abstract: element['concrete'] = concrete_dict[element_name] elements.append(dict({'name': element_name, 'typecode': type_code, 'isListOf': has_list_of, 'listOfName': xml_lo_element_name if xml_lo_element_name is not None else '', 'listOfClassName': lo_class_name if lo_class_name is not None else ''})) sbml_elements.append(element) for node in dom.getElementsByTagName('plugin'): plug_elements = [] plug_lo_elements = [] ext_point = get_value(node, 'extensionPoint') add_decls = get_value(node, 'additionalDecls') add_defs = get_value(node, 'additionalDefs') # read references to elements for reference in node.getElementsByTagName('reference'): temp = find_element(elements, get_value(reference, 'name')) if temp is not None: plug_elements.append(temp) # look for references to ListOf elements for reference in node.getElementsByTagName('reference'): temp = find_lo_element(elements, get_value(reference, 'name')) if temp is not None: plug_lo_elements.append(temp) attributes = [] # read additional attributes for attr in node.getElementsByTagName('attribute'): attr_name = get_value(attr, 'name') required = to_bool(get_value(attr, 'required')) attr_type = get_value(attr, 'type') attr_abstract = to_bool(get_value(attr, 'abstract')) attr_element = get_value(attr, 'element') attribute_dict = dict({'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract }) if attr_abstract: attribute_dict['concrete'] = concrete_dict[attr_element] attributes.append(attribute_dict) plugin_dict = dict({'sbase': ext_point, 'extension': plug_elements, 'attribs': attributes, 'lo_extension': plug_lo_elements}) if add_decls is not None: if os.path.exists(os.path.dirname(filename) + '/' + add_decls): add_decls += os.path.dirname(filename) + '/' plugin_dict['addDecls'] = add_decls if add_defs is not None: if os.path.exists(os.path.dirname(filename) + '/' + add_defs): add_defs += os.path.dirname(filename) + '/' plugin_dict['addDefs'] = add_defs plugins.append(plugin_dict) for node in dom.getElementsByTagName('enum'): values = [] enum_name = get_value(node, 'name') for val in node.getElementsByTagName('enumValue'): values.append(dict({'name': get_value(val, 'name'), 'value': get_value(val, 'value')})) enums.append(dict({'name': enum_name, 'values': values})) package = dict({'name': package_name, 'elements': elements, 'plugins': plugins, 'number': number, 'sbmlElements': sbml_elements, 'enums': enums, 'offset': offset, 'fullname': fullname, 'sbml_level': sbml_level, 'sbml_version': sbml_version, 'pkg_version': pkg_version, 'required': required }) # link elements for elem in package['elements']: elem['root'] = package if 'attribs' in elem: for attr in elem['attribs']: attr['parent'] = elem attr['root'] = package for elem in package['sbmlElements']: elem['root'] = package if 'attribs' in elem: for attr in elem['attribs']: attr['parent'] = elem attr['root'] = package if 'concrete' in elem: for attr in elem['concrete']: attr['parent'] = elem attr['root'] = package return package
def write_lochild_attribute_rule(self, child, lo_info): child_class = query.get_class(child['element'], child['root']) if not child_class or len(child_class['lo_attribs']) == 0: return # if these are all elements we dont need this num = len(child_class['lo_attribs']) count = 0 for attrib in child_class['lo_attribs']: if self.is_element(attrib['type']): count += 1 if count == num: return attributes = [] if len(child_class['lo_class_name']) == 0: child_class['lo_class_name'] = strFunctions.list_of_name(child_class['name']) formatted_name = '\\' + child_class['lo_class_name'] name = child_class['name'] child_reqd = [] child_opt = [] for attrib in child_class['lo_attribs']: attributes.append(attrib) if attrib['reqd']: child_reqd.append(attrib) else: child_opt.append(attrib) lo_info.append(dict({'formatted_name': formatted_name, 'name': child_class['lo_class_name'], 'attributes': attributes})) reqd = self.parse_required(self, child_reqd) opt = self.parse_optional(self, child_opt) no_other_statement = 'No other attributes from the SBML Level 3 {0} ' \ 'namespaces are permitted on {1} {2} object. '\ .format(self.fullname, self.indef, formatted_name) if len(opt) == 0 and len(reqd) > 0: text = '{0} {1} object must have {2}. {3}'\ .format(self.indef_u, formatted_name, reqd, no_other_statement) elif len(reqd) == 0 and len(opt) > 0: text = '{0} {1} object may have {2}. {3}'\ .format(self.indef_u, formatted_name, opt, no_other_statement) else: text = '{0} {1} object must have {2}, and may have {3}. {4}'\ .format(self.indef_u, formatted_name, reqd, opt, no_other_statement) ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(child_class['lo_class_name'])) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Attributes allowed on <{0}>.'.format(strFunctions.lower_first(child_class['lo_class_name'])) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}LO{2}AllowedAttributes'.format(self.up_package, self.name, strFunctions.plural(name)) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': False, 'object': self.name, 'lo': True, 'reqd': child_reqd, 'opt': child_opt, 'lo_object': lo_info[0]['name']})
def get_tests(self, rule): passes = [] tc = rule['typecode'] test_needed = [] if tc.endswith('Unknown'): test_needed = [] elif tc.endswith('NSUndeclared'): test_needed = [dict({'name': 'missing_ns'}), dict({'name': 'incorrect_ns'})] elif tc.endswith('AttributeRequiredMissing'): test_needed = [dict({'name': 'missing_reqd'})] elif tc.endswith('AttributeRequiredMustBeBoolean'): test_needed = [dict({'name': 'incorrect_type_reqd'})] elif tc.endswith('AttributeRequiredMustHaveValue'): test_needed = [dict({'name': 'incorrect_value_reqd'})] elif tc.endswith('EmptyLOElements'): for element in rule['lo_object']: loname = element['listOfClassName'] test_needed.append(dict({'name': 'empty_lo', 'object': rule['object'], 'lo_child': loname})) elif tc.endswith('AllowedElements'): for element in rule['opt']: if element['isListOf']: name = element['listOfClassName'] else: name = element['name'] test_needed.append(dict({'name': 'duplicate_element', 'object': rule['object'], 'child': name})) for element in rule['reqd']: if element['isListOf']: name = element['listOfClassName'] else: name = element['name'] test_needed.append(dict({'name': 'remove_element', 'object': rule['object'], 'child': name})) elif tc.endswith('AllowedCoreElements'): if self.is_lo_rule(rule): for element in rule['opt']: if element['isListOf']: name = element['listOfClassName'] else: name = element['name'] test_needed.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': name})) passes.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'annotation'})) passes.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'notes'})) for element in rule['reqd']: if element['isListOf']: name = element['listOfClassName'] else: name = element['name'] test_needed.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': name})) passes.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'annotation'})) passes.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': name, 'type': 'notes'})) else: test_needed.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': rule['object']})) passes.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': rule['object'], 'type': 'annotation'})) passes.append(dict({'name': 'add_core_element', 'object': rule['object'], 'child': rule['object'], 'type': 'notes'})) elif tc.endswith('AllowedCoreAttributes'): if self.is_lo_rule(rule): for element in rule['opt']: name = self.get_name(element) test_needed.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': name})) passes.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'metaid'})) passes.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'sboTerm'})) for element in rule['reqd']: name = self.get_name(element) test_needed.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': name})) passes.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'metaid'})) passes.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': name, 'type': 'sboTerm'})) else: test_needed.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': rule['object']})) passes.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': rule['object'], 'type': 'metaid'})) passes.append(dict({'name': 'add_core_attribute', 'object': rule['object'], 'child': rule['object'], 'type': 'sboTerm'})) elif tc.endswith('AllowedAttributes'): if self.is_lo_rule(rule): test_needed.append(dict({'name': 'add_pkg_attribute', 'object': rule['object'], 'child': rule['lo_object']})) for attribute in rule['opt']: name = attribute['name'] passes.append(dict({'name': 'remove_attribute', 'object': rule['object'], 'child': rule['lo_object'], 'attrib': name})) for attribute in rule['reqd']: name = attribute['name'] test_needed.append(dict({'name': 'remove_attribute', 'object': rule['object'], 'child': rule['lo_object'], 'attrib': name})) else: test_needed.append(dict({'name': 'add_pkg_attribute', 'object': rule['object'], 'child': rule['object']})) for attribute in rule['opt']: name = attribute['name'] passes.append(dict({'name': 'remove_attribute', 'object': rule['object'], 'child': rule['object'], 'attrib': name})) for attribute in rule['reqd']: name = attribute['name'] test_needed.append(dict({'name': 'remove_attribute', 'object': rule['object'], 'child': rule['object'], 'attrib': name})) elif self.is_attribute_type_rule(tc): test_needed.append(dict({'name': 'replace_attribute', 'object': rule['object'], 'child': rule['object'], 'attrib': strFunctions.lower_first(rule['attrib']), 'att_type': rule['attrib_type']})) else: print(tc) return [test_needed, passes]
def adjust_line(line): lowerlibname = global_variables.library_name.lower() nonlibname = lowerlibname if lowerlibname.startswith('lib'): nonlibname = lowerlibname[3:] line = re.sub('nonlibsbml', nonlibname, line) line = re.sub('SBase', global_variables.std_base, line) line = re.sub('LIBSBML', global_variables.library_name.upper(), line) line = re.sub('LibSBML', strFunctions.upper_first(global_variables.library_name), line) line = re.sub('libSBML', strFunctions.lower_first(global_variables.library_name), line) line = re.sub('libsbml', lowerlibname, line) if lowerlibname.startswith('lib'): line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname[3:]), line) else: line = re.sub('sbmlfwd', '{0}fwd'.format(lowerlibname), line) doctype = '{0}_DOCUMENT'.format(global_variables.language.upper()) if global_variables.document_class != 'SedDocument': doctype = 'LIB_{0}_{1}'.format( strFunctions.get_library_suffix( global_variables.library_name).upper(), strFunctions.remove_prefix( global_variables.document_class).upper()) line = re.sub('SBML_DOCUMENT', doctype, line) line = re.sub('SBMLDocument', global_variables.document_class, line) line = re.sub( 'toplevelname', strFunctions.lower_first(global_variables.top_level_element_name), line) line = re.sub('CAT_SBML', 'CAT_{0}'.format(global_variables.language.upper()), line) line = re.sub('SBML_Lang', '{0}'.format(global_variables.language.upper()), line) line = re.sub('SBML_', '{0}_'.format(global_variables.language.upper()), line) # hack for SedML if global_variables.prefix == 'Sed': line = re.sub('readSBML', 'read{0}ML'.format(global_variables.prefix), line) line = re.sub('writeSBML', 'write{0}ML'.format(global_variables.prefix), line) else: line = re.sub('readSBML', 'read{0}'.format(global_variables.language.upper()), line) line = re.sub('writeSBML', 'write{0}'.format(global_variables.language.upper()), line) line = re.sub('sbml', global_variables.language, line) line = re.sub( 'SBMLSBML', '{0}{1}'.format( strFunctions.upper_first(global_variables.language), global_variables.prefix), line) line = re.sub('SBML', global_variables.prefix, line) line = re.sub('ListOf', '{0}ListOf'.format(global_variables.prefix), line) line = re.sub( 'SPEC_NAMESPACE', '\"{0}\"'.format(global_variables.namespaces[0]['namespace']), line) line = re.sub('language_', '{0}'.format(global_variables.language.lower()), line) line = re.sub('LANGUAGE', '{0}'.format(global_variables.language.upper()), line) return line
def expand_attributes(self, attributes): for i in range(0, len(attributes)): capname = strFunctions.upper_first(attributes[i]['name']) attributes[i]['name'] = strFunctions.lower_first(capname) attributes[i]['capAttName'] = capname attributes[i]['memberName'] = 'm' + capname attributes[i]['pluralName'] = \ strFunctions.plural(attributes[i]['name']) attributes[i]['isEnum'] = False attributes[i]['isArray'] = False attributes[i]['isVector'] = False attributes[i]['children_overwrite'] = False att_type = attributes[i]['type'] if att_type == 'SId' or att_type == 'SIdRef' or att_type == 'IDREF': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'UnitSId' or att_type == 'UnitSIdRef': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'string': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'double': attributes[i]['attType'] = 'double' attributes[i]['attTypeCode'] = 'double' attributes[i]['CType'] = 'double' attributes[i]['isNumber'] = True attributes[i]['default'] = 'util_NaN()' elif att_type == 'int': attributes[i]['attType'] = 'integer' attributes[i]['attTypeCode'] = 'int' attributes[i]['CType'] = 'int' attributes[i]['isNumber'] = True attributes[i]['default'] = '{0}_INT_' \ 'MAX'.format(self.cap_language) elif att_type == 'uint': attributes[i]['attType'] = 'unsigned integer' attributes[i]['attTypeCode'] = 'unsigned int' attributes[i]['CType'] = 'unsigned int' attributes[i]['isNumber'] = True attributes[i]['default'] = '{0}_INT_' \ 'MAX'.format(self.cap_language) elif att_type == 'bool' or att_type == 'boolean': attributes[i]['attType'] = 'boolean' attributes[i]['attTypeCode'] = 'bool' attributes[i]['CType'] = 'int' attributes[i]['isNumber'] = False attributes[i]['default'] = 'false' elif att_type == 'enum': attributes[i]['isEnum'] = True attributes[i]['attType'] = 'enum' attributes[i]['attTypeCode'] = attributes[i]['element'] + '_t' attributes[i]['CType'] = attributes[i]['element'] + '_t' attributes[i]['isNumber'] = False attributes[i]['default'] = \ query.get_default_enum_value(attributes[i]) elif att_type == 'element': el_name = attributes[i]['element'] at_name = attributes[i]['name'] attributes[i]['attType'] = 'element' if attributes[i]['name'] == 'math': if global_variables.is_package: attributes[i]['attTypeCode'] = 'ASTNode*' attributes[i]['CType'] = 'ASTNode_t*' else: attributes[i]['attTypeCode'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER ASTNode*' attributes[i]['CType'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER ASTNode_t*' else: attributes[i]['attTypeCode'] = attributes[i]['element']+'*' attributes[i]['CType'] = attributes[i]['element']+'_t*' if attributes[i]['attTypeCode'] == 'XMLNode*' and not global_variables.is_package: attributes[i]['attTypeCode'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER {0}*'.format(attributes[i]['element']) attributes[i]['CType'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER {0}_t*'.format(attributes[i]['element']) attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' if strFunctions.compare_no_case(strFunctions.remove_prefix(el_name), at_name): attributes[i]['children_overwrite'] = False else: attributes[i]['children_overwrite'] = True elif att_type == 'lo_element' or att_type == 'inline_lo_element': name = strFunctions.list_of_name(attributes[i]['element']) plural = strFunctions.plural_no_prefix(attributes[i]['element']) attributes[i]['attType'] = 'lo_element' attributes[i]['attTypeCode'] = name attributes[i]['CType'] = 'ListOf_t' attributes[i]['memberName'] = 'm' + plural attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' elif att_type == 'array': attributes[i]['isArray'] = True attributes[i]['element'] = \ strFunctions.lower_first(attributes[i]['element']) attributes[i]['attType'] = 'array' attributes[i]['attTypeCode'] = attributes[i]['element'] + '*' attributes[i]['CType'] = attributes[i]['attTypeCode'] attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' elif att_type == 'vector': attributes[i]['isVector'] = True attributes[i]['element'] = \ strFunctions.lower_first(attributes[i]['element']) attributes[i]['attType'] = 'vector' attributes[i]['attTypeCode'] = 'std::vector<{0}>'.format(attributes[i]['element']) attributes[i]['CType'] = attributes[i]['attTypeCode'] attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' else: global_variables.code_returned \ = global_variables.return_codes['unknown type used'] attributes[i]['attType'] = 'FIXME_{0}'.format(att_type) attributes[i]['attTypeCode'] = 'FIXME_{0}'.format(att_type) attributes[i]['CType'] = 'FIXME_{0}'.format(att_type) attributes[i]['isNumber'] = False attributes[i]['default'] = 'FIXME_{0}'.format(att_type) return attributes
def parse_deviser_xml(filename): """ Parses the given filename and returns a dictionary with the definition contained in it """ sbml_elements = [] elements = [] plugins = [] enums = [] dom = parse(filename) temp = get_value(dom.documentElement, 'name') # we expect this to be lower case package_name = temp.lower() number = to_int(get_value(dom.documentElement, 'number')) offset = to_int(get_value(dom.documentElement, 'offset')) fullname = get_value(dom.documentElement, 'fullname') required = to_bool(get_value(dom.documentElement, 'required')) # get package information (assume we want the first only) sbml_level = 3 sbml_version = 1 pkg_version = 1 for node in dom.getElementsByTagName('pkgVersion'): sbml_level = to_int(get_value(node, 'level')) sbml_version = to_int(get_value(node, 'version')) pkg_version = to_int(get_value(node, 'pkg_version')) break concrete_dict = dict({}) # read concrete versions of abstract classes and fill dictionary for node in dom.getElementsByTagName('element'): element_name = get_value(node, 'name') concrete_list = [] for concrete in node.getElementsByTagName('concrete'): concrete_list.append( dict({ 'name': get_value(concrete, "name"), 'element': get_value(concrete, "element") })) concrete_dict[element_name] = concrete_list # read element for node in dom.getElementsByTagName('element'): element_name = get_value(node, 'name') base_class = get_value(node, 'baseClass') type_code = get_value(node, 'typeCode') has_math = to_bool(get_value(node, 'hasMath')) has_children = to_bool(get_value(node, 'hasChildren')) has_list_of = to_bool(get_value(node, 'hasListOf')) abstract = to_bool(get_value(node, 'abstract')) children_overwrite_element_name = to_bool( get_value(node, 'childrenOverwriteElementName')) temp = get_value(node, 'elementName') # we expect this to be camel case starting with lower if temp is not None: xml_element_name = strFunctions.lower_first(temp) else: xml_element_name = '' temp = get_value(node, 'listOfName') # we expect this to be camel case starting with lower if temp is not None: xml_lo_element_name = strFunctions.lower_first(temp) else: xml_lo_element_name = '' temp = get_value(node, 'listOfClassName') # we expect this to be camel case starting with upper if temp is not None: lo_class_name = strFunctions.upper_first(temp) else: lo_class_name = '' add_decls = get_value(node, 'additionalDecls') add_defs = get_value(node, 'additionalDefs') attributes = [] # add attributes for attr in node.getElementsByTagName('attribute'): attr_name = get_value(attr, 'name') required = to_bool(get_value(attr, 'required')) attr_type = standardize_types(get_value(attr, 'type')) attr_abstract = to_bool(get_value(attr, 'abstract')) temp = get_value(attr, 'element') # expect this to be uppercase if temp is not None: attr_element = strFunctions.standard_element_name(temp) else: attr_element = '' attribute_dict = dict({ 'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract, }) if attr_abstract: attribute_dict['concrete'] = concrete_dict[attr_element] attributes.append(attribute_dict) lo_attributes = [] # add attributes for attr in node.getElementsByTagName('listOfAttribute'): attr_name = get_value(attr, 'name') required = to_bool(get_value(attr, 'required')) attr_type = get_value(attr, 'type') attr_abstract = to_bool(get_value(attr, 'abstract')) attr_element = get_value(attr, 'element') attribute_dict = dict({ 'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract }) if attr_abstract: attribute_dict['concrete'] = concrete_dict[attr_element] lo_attributes.append(attribute_dict) # construct element element = dict({ 'name': element_name, 'package': package_name, 'typecode': type_code, 'hasListOf': has_list_of, 'attribs': attributes, 'lo_attribs': lo_attributes, 'hasChildren': has_children, 'hasMath': has_math, 'childrenOverwriteElementName': children_overwrite_element_name, 'baseClass': base_class, 'abstract': abstract }) if xml_element_name is not None: element['elementName'] = xml_element_name if xml_lo_element_name is not None: element['lo_elementName'] = xml_lo_element_name if lo_class_name is not None: element['lo_class_name'] = lo_class_name if add_decls is not None: temp = os.path.dirname(filename) + '//' + add_decls if os.path.exists(temp): add_decls = os.path.abspath(temp) element['addDecls'] = add_decls if add_defs is not None: if os.path.exists(os.path.dirname(filename) + '/' + add_defs): add_defs += os.path.abspath(filename) + '/' element['addDefs'] = add_defs if abstract: element['concrete'] = concrete_dict[element_name] elements.append( dict({ 'name': element_name, 'typecode': type_code, 'isListOf': has_list_of, 'listOfName': xml_lo_element_name if xml_lo_element_name is not None else '', 'listOfClassName': lo_class_name if lo_class_name is not None else '' })) sbml_elements.append(element) for node in dom.getElementsByTagName('plugin'): plug_elements = [] plug_lo_elements = [] ext_point = get_value(node, 'extensionPoint') add_decls = get_value(node, 'additionalDecls') add_defs = get_value(node, 'additionalDefs') # read references to elements for reference in node.getElementsByTagName('reference'): temp = find_element(elements, get_value(reference, 'name')) if temp is not None: plug_elements.append(temp) # look for references to ListOf elements for reference in node.getElementsByTagName('reference'): temp = find_lo_element(elements, get_value(reference, 'name')) if temp is not None: plug_lo_elements.append(temp) attributes = [] # read additional attributes for attr in node.getElementsByTagName('attribute'): attr_name = get_value(attr, 'name') required = to_bool(get_value(attr, 'required')) attr_type = get_value(attr, 'type') attr_abstract = to_bool(get_value(attr, 'abstract')) attr_element = get_value(attr, 'element') attribute_dict = dict({ 'type': attr_type, 'reqd': required, 'name': attr_name, 'element': attr_element, 'abstract': attr_abstract }) if attr_abstract: attribute_dict['concrete'] = concrete_dict[attr_element] attributes.append(attribute_dict) plugin_dict = dict({ 'sbase': ext_point, 'extension': plug_elements, 'attribs': attributes, 'lo_extension': plug_lo_elements }) if add_decls is not None: if os.path.exists(os.path.dirname(filename) + '/' + add_decls): add_decls += os.path.dirname(filename) + '/' plugin_dict['addDecls'] = add_decls if add_defs is not None: if os.path.exists(os.path.dirname(filename) + '/' + add_defs): add_defs += os.path.dirname(filename) + '/' plugin_dict['addDefs'] = add_defs plugins.append(plugin_dict) for node in dom.getElementsByTagName('enum'): values = [] enum_name = get_value(node, 'name') for val in node.getElementsByTagName('enumValue'): values.append( dict({ 'name': get_value(val, 'name'), 'value': get_value(val, 'value') })) enums.append(dict({'name': enum_name, 'values': values})) package = dict({ 'name': package_name, 'elements': elements, 'plugins': plugins, 'number': number, 'sbmlElements': sbml_elements, 'enums': enums, 'offset': offset, 'fullname': fullname, 'sbml_level': sbml_level, 'sbml_version': sbml_version, 'pkg_version': pkg_version, 'required': required }) # link elements for elem in package['elements']: elem['root'] = package if 'attribs' in elem: for attr in elem['attribs']: attr['parent'] = elem attr['root'] = package for elem in package['sbmlElements']: elem['root'] = package if 'attribs' in elem: for attr in elem['attribs']: attr['parent'] = elem attr['root'] = package if 'concrete' in elem: for attr in elem['concrete']: attr['parent'] = elem attr['root'] = package return package
def create_top_object(self, tree): name = strFunctions.lower_first(tree['base']) if tree['ext'] == 'core': element = self.create_object(tree) return element