def ComponentParser_missingport_test(): xmlfile = os.path.join(os.getcwd(), "missing_port_SendBuffComponentAi.xml") XmlComponentParser.XmlComponentParser(xmlfile) assert True
def main(): # Configures output only to stdout. Logger.connectOutputLogger(None) xmlfile = "../../test/app1a/NikonComponentAi.xml" print("Component XML parse test (%s)" % xmlfile) # # Basic usage of this factory to create the component meta-model # parsed_port_xml_list = [] the_parsed_component_xml = XmlComponentParser.XmlComponentParser(xmlfile) port_type_files_list = the_parsed_component_xml.get_port_type_files() for port_file in port_type_files_list: #print "Parsing %s" % port_file parsed_port_xml_list.append(XmlPortsParser.XmlPortsParser(port_file)) #print parsed_port_xml_list comp = CompFactory().create(the_parsed_component_xml, parsed_port_xml_list) # # End of usage and comp is the instance of model to be used. # print("Component: %s" % comp) print("Namespace: %s" % comp.get_namespace()) print("Name: %s" % comp.get_name()) print("Kind: %s" % comp.get_kind()) print("Comment: %s" % comp.get_comment()) print("Ports: %s" % comp.get_ports()) print() for port in comp.get_ports(): print("Port:") print(port.get_name(), port.get_type(), port.get_direction(), port.get_sync(), port.get_namespace()) print(port.get_comment()) print(port.get_ifcomment()) print(port.get_includes()) print(port.get_args()) for arg in port.get_args(): print("\t%s : %s # %s" % (arg.get_name(), arg.get_type(), arg.get_comment()))
def ComponentParser_manualxml_test(): implicit_port_roles = ['Cmd', 'CmdResponse', 'CmdRegistration', 'ParamGet', 'ParamSet'] xmlfile = os.path.join(os.getcwd(), "man_RecvBuffComponentAi.xml") parsed_xml = XmlComponentParser.XmlComponentParser(xmlfile) for required_port in implicit_port_roles: found = False for p in parsed_xml.get_ports(): if required_port == p.get_role(): found = True if found: assert True else: print("%s port is required but not present." % required_port) assert False
def main(): """ Main program. """ global VERBOSE global BUILD_ROOT global DEPLOYMENT # Enable printing model error output to STDOUT Logger.connectOutputLogger(None) Parser = pinit() (opt, args) = Parser.parse_args() VERBOSE = opt.verbose_flag ConfigManager.ConfigManager.getInstance() # # Handle command line arguments # # # Parse the input Topology XML filename # if len(args) == 0: print("ERROR: Usage: %s [options] xml_filename" % sys.argv[0]) return elif len(args) == 1: xml_filename = args[0] else: print("ERROR: Too many filenames, should only have one") return # # Check for BUILD_ROOT variable for XML port searches # if not opt.build_root_overwrite is None: set_build_roots(opt.build_root_overwrite) if VERBOSE: print("BUILD_ROOT set to %s" % ",".join(get_build_roots())) else: if ("BUILD_ROOT" in os.environ.keys()) == False: print("ERROR: Build root not set to root build path...") sys.exit(-1) set_build_roots(os.environ["BUILD_ROOT"]) if VERBOSE: print("BUILD_ROOT set to %s" % ",".join(get_build_roots())) # # Write test component # if not "Ai" in xml_filename: print("ERROR: Missing Ai at end of file name...") raise OSError # # Create python dictionaries # print(xml_filename) xml_type = XmlParser.XmlParser(xml_filename)() # Only Components can be inputted if xml_type == "component": if VERBOSE: print("Detected Component XML so GeneratingComponent C++ Files...") the_parsed_component_xml = XmlComponentParser.XmlComponentParser( xml_filename) component_model = parse_component(the_parsed_component_xml, xml_filename, opt) if VERBOSE: print("\nGenerating tests...") generate_impl_files(opt, component_model) else: print("ERROR: {} is used for component XML files, not {} XML files". format(sys.argv[0], xml_type)) sys.exit(-1) sys.exit(0)
def create(self, the_parsed_topology_xml, generate_list_file=True): """ Create a topology model here. """ # Instance a list of model.Component classes that are all the instanced items from parsed xml. x = the_parsed_topology_xml componentXMLNameToComponent = { } #Dictionary maps XML names to processes component objects so redundant processing is avoided components = [] for comp_xml_path in x.get_comp_type_file_header_dict(): for possible in [ os.environ.get("BUILD_ROOT"), os.environ.get("FPRIME_CORE_DIR") ]: file_path = os.path.join(possible, comp_xml_path) if os.path.exists(file_path): break processedXML = XmlComponentParser.XmlComponentParser(file_path) comp_name = processedXML.get_component().get_name() componentXMLNameToComponent[comp_name] = processedXML for instance in x.get_instances(): if instance.get_type() not in list( componentXMLNameToComponent.keys()): PRINT.info( "Component XML file type {} was not specified in the topology XML. Please specify the path using <import_component_type> tags." .format(instance.get_type())) else: instance.set_component_object( componentXMLNameToComponent[instance.get_type()]) components.append( Component.Component(instance.get_namespace(), instance.get_name(), instance.get_type(), xml_filename=x.get_xml_filename(), kind2=instance.get_kind())) #print "Assembly name: " + x.get_name(), x.get_base_id(), x.get_base_id_window() #for component in components: # print component.get_name(), component.get_base_id(), component.get_base_id_window() if self.__generate_new_IDS: # Iterate over all the model.Component classes and... instance_name_base_id_list = self.__compute_base_ids( x.get_base_id(), x.get_base_id_window(), x.get_instances(), x.get_xml_filename(), generate_list_file) else: instance_name_base_id_list = [] # Iterate over all the model.Component classes and then... # Iterate over all the connection sources and assigned output ports to each Component.. # For each output port you want to assign the connect comment, target component name, target port and type... # (Requires adding to the model.Port class ether members or a memeber called of type TargetConnection) for component in components: port_obj_list = [] for connection in x.get_connections(): if component.get_name() == connection.get_source()[0]: port = Port.Port(connection.get_source()[1], connection.get_source()[2], None, None, comment=connection.get_comment(), xml_filename=x.get_xml_filename) port.set_source_num(connection.get_source()[3]) port.set_target_comp(connection.get_target()[0]) port.set_target_port(connection.get_target()[1]) port.set_target_type(connection.get_target()[2]) port.set_target_num(connection.get_target()[3]) if connection.get_source()[1].startswith("i"): port.set_direction("input") else: port.set_direction("output") if connection.get_target()[1].startswith("i"): port.set_target_direction("input") else: port.set_target_direction("output") port_obj_list.append(port) component.set_ports(port_obj_list) # Instance a Topology class and give it namespace, comment and list of components. the_topology = Topology.Topology(x.get_namespace(), x.get_comment(), components, x.get_name(), instance_name_base_id_list, x.get_prepend_instance_name()) the_topology.set_instance_header_dict( x.get_comp_type_file_header_dict()) return the_topology
def main(): """ Main program. """ global ERROR # prevent local creation of variable global VERBOSE # prevent local creation of variable global GEN_TEST_CODE # indicate if test code should be generated global DEPLOYMENT # deployment set in topology xml only and used to install new instance dicts ERROR = False # Sets up the initial (singleton) instance ConfigManager.ConfigManager.getInstance() Parser = pinit() (opt, args) = Parser.parse_args() VERBOSE = opt.verbose_flag # Check that the specified working directory exists. Remember, the # default working directory is the current working directory which # always exists. We are basically only checking for when the user # specifies an alternate working directory. if os.path.exists(opt.work_path) == False: Parser.error(f"Specified path does not exist ({opt.work_path})!") working_dir = opt.work_path # Get the current working directory so that we can return to it when # the program completes. We always want to return to the place where # we started. starting_directory = os.getcwd() os.chdir(working_dir) # print working_dir # print os.getcwd() # Configure the logging. log_level = opt.logger.upper() log_level_dict = dict() log_level_dict["QUIET"] = None log_level_dict["DEBUG"] = logging.DEBUG log_level_dict["INFO"] = logging.INFO log_level_dict["WARNING"] = logging.WARN log_level_dict["ERROR"] = logging.ERROR log_level_dict["CRITICAL"] = logging.CRITICAL if log_level_dict[log_level] is None: stdout_enable = False else: stdout_enable = True log_fd = opt.logger_output # For now no log file Logger.connectDebugLogger(log_level_dict[log_level], log_fd, stdout_enable) Logger.connectOutputLogger(log_fd) # # Parse the input Component XML file and create internal meta-model # if len(args) == 0: PRINT.info(f"Usage: {sys.argv[0]} [options] xml_filename") return else: xml_filenames = args[0:] # # Check for BUILD_ROOT variable for XML port searches # if opt.build_root_flag == True: # Check for BUILD_ROOT env. variable if ("BUILD_ROOT" in list(os.environ.keys())) == False: PRINT.info( "ERROR: The -b command option requires that BUILD_ROOT environmental variable be set to root build path..." ) sys.exit(-1) else: set_build_roots(os.environ.get("BUILD_ROOT")) for xml_filename in xml_filenames: xml_type = XmlParser.XmlParser(xml_filename)() if xml_type == "component": DEBUG.info( "Detected Component XML so Generating Component C++ Files...") the_parsed_component_xml = XmlComponentParser.XmlComponentParser( xml_filename) generate_component(the_parsed_component_xml, os.path.basename(xml_filename), opt) dependency_parser = the_parsed_component_xml elif xml_type == "interface": DEBUG.info( "Detected Port type XML so Generating Port type C++ Files...") the_parsed_port_xml = XmlPortsParser.XmlPortsParser(xml_filename) generate_port(the_parsed_port_xml, os.path.basename(xml_filename)) dependency_parser = the_parsed_port_xml elif xml_type == "serializable": DEBUG.info( "Detected Serializable XML so Generating Serializable C++ Files..." ) the_serial_xml = XmlSerializeParser.XmlSerializeParser( xml_filename) generate_serializable(the_serial_xml, opt) dependency_parser = the_serial_xml elif xml_type == "assembly" or xml_type == "deployment": DEBUG.info( "Detected Topology XML so Generating Topology C++ Files...") the_parsed_topology_xml = XmlTopologyParser.XmlTopologyParser( xml_filename) DEPLOYMENT = the_parsed_topology_xml.get_deployment() print("Found assembly or deployment named: %s\n" % DEPLOYMENT) generate_topology(the_parsed_topology_xml, os.path.basename(xml_filename), opt) dependency_parser = the_parsed_topology_xml elif xml_type == "enum": DEBUG.info( "Detected Enum XML so Generating hpp, cpp, and py files...") curdir = os.getcwd() if EnumGenerator.generate_enum(xml_filename): ERROR = False PRINT.info( f"Completed generating files for {xml_filename} Enum XML...." ) else: ERROR = True os.chdir(curdir) elif xml_type == "array": DEBUG.info( "Detected Array XML so Generating hpp, cpp, and py files...") curdir = os.getcwd() if ArrayGenerator.generate_array(xml_filename): ERROR = False PRINT.info( f"Completed generating files for {xml_filename} Array XML..." ) else: ERROR = True os.chdir(curdir) else: PRINT.info("Invalid XML found...this format not supported") ERROR = True if opt.dependency_file is not None: if opt.build_root_flag: generate_dependency_file( opt.dependency_file, os.path.basename(xml_filename), list(get_build_roots())[0], dependency_parser, xml_type, ) # Always return to directory where we started. os.chdir(starting_directory) if ERROR == True: sys.exit(-1) else: sys.exit(0)
def __init__(self, xml_file=None): self.__root = None self.__is_topology_xml = False self.__in_connection = False self.__namespace = None self.__name = None self.__deployment = None self.__comment = "" if os.path.isfile(xml_file) == False: stri = "ERROR: Could not find specified XML file %s." % xml_file raise OSError(stri) fd = open(xml_file) xml_file = os.path.basename(xml_file) self.__xml_filename = xml_file self.__instances = [] self.__connections = [] self.__comp_type_files = [] self.__config = ConfigManager.ConfigManager.getInstance() self.__comp_type_file_header = ( {}) # used to gather header file locations. Optional arg # self.Config = self.__config self.__base_id = None self.__base_id_window = None self.__prepend_instance_name = False # Used to turn off prepending instance name in the situation where instance dicts are being generated and only one instance of an object is created element_tree = etree.parse(fd) fd.close() # Close the file, which is only used for the parsing above # Validate against schema relax_file_handler = open(ROOTDIR + self.__config.get("schema", "assembly")) relax_parsed = etree.parse(relax_file_handler) relax_file_handler.close() relax_compiled = etree.RelaxNG(relax_parsed) # 2/3 conversion if not relax_compiled.validate(element_tree): raise FprimeRngXmlValidationException(relax_compiled.error_log) self.validate_xml(xml_file, element_tree, "schematron", "top_unique") for e in element_tree.iter(): c = None if e.tag == "assembly" or e.tag == "deployment": self.__is_topology_xml = True if "namespace" in e.attrib: self.__namespace = e.attrib["namespace"] else: self.__namespace = None # if "name" in e.attrib: self.__name = e.attrib["name"] else: self.__name = None # if "base_id" in e.attrib: self.__base_id = e.attrib["base_id"] else: self.__base_id = None # if "base_id_window" in e.attrib: self.__base_id_window = e.attrib["base_id_window"] elif "base_id_range" in e.attrib: self.__base_id_window = e.attrib["base_id_range"] else: self.__base_id_window = None if "prepend_instance_name" in e.attrib: if e.attrib["prepend_instance_name"].upper() == "TRUE": self.__prepend_instance_name = True # # The deployment attribute added so that instance # dictionaries are installed in the correct place. # if "deployment" in e.attrib: self.__deployment = e.attrib["deployment"] else: self.__deployment = self.__name # elif e.tag == "import_component_type": self.__comp_type_files.append(e.text) if "header" in e.attrib: self.__comp_type_file_header[e.text] = e.attrib["header"] else: self.__comp_type_file_header[e.text] = None # elif e.tag == "connection": self.__in_connection = True n = e.attrib["name"] d = "" if e.tag == "type": d = e.attrib["type"] else: d = None connection = Connection(n, d) self.__connections.append(connection) # elif e.tag == "instance": x = e.attrib["name"] y = e.attrib["type"] z = e.attrib["namespace"] if "kind" in list(e.attrib.keys()): k = e.attrib["kind"] else: k = "active" k = k.lower() if "base_id" in e.attrib: b = e.attrib["base_id"] else: b = None # if "base_id_window" in e.attrib: bw = e.attrib["base_id_window"] elif "base_id_range" in e.attrib: bw = e.attrib["base_id_range"] else: bw = None # Short name - Used to override instance name for dict generation if "dict_short_name" in e.attrib: sn = e.attrib["dict_short_name"] else: sn = None instance_obj = Instance(x, y, z, k, b, bw, sn) self.__instances.append(instance_obj) elif e.tag == "source": x = e.attrib["component"] y = e.attrib["port"] z = e.attrib["type"] if "num" in list(e.attrib.keys()): n = int(e.attrib["num"]) else: n = 0 self.__connections[-1].set_source(x, y, z, n) elif e.tag == "target": x = e.attrib["component"] y = e.attrib["port"] z = e.attrib["type"] if "num" in list(e.attrib.keys()): n = int(e.attrib["num"]) else: n = 0 self.__connections[-1].set_target(x, y, z, n) elif e.tag == "comment": c = e.text if self.__in_connection: self.__connections[-1].set_comment(c) else: self.__comment = c elif e.tag == etree.Comment: pass else: PRINT.info("WARNING: Unrecognized topology tag! %s" % (e.tag)) # print "%s %s %s" % (e.tag, e.text, e.attrib) # # For each component xml file specified assign it to a component instance object PRINT.info("\nSearching for component XML files") for xml_file in self.__comp_type_files: try: xml_file = locate_build_root(xml_file) except BuildRootMissingException: PRINT.info("WARNING: Could not find XML file: %s" % xml_file) except BuildRootCollisionException as bre: stri = "ERROR: Could not find specified dictionary XML file. {}. Error: {}".format( xml_file, str(bre)) raise OSError(stri) if os.path.exists(xml_file) == True: PRINT.info("Found component XML file: %s" % xml_file) xml_parsed = XmlComponentParser.XmlComponentParser(xml_file) for inst in self.get_instances(): if inst.get_type() == xml_parsed.get_component().get_name( ): PRINT.info( "Populating instance %s of type %s with parser tree" % (inst.get_name(), inst.get_type())) DEBUG.info( "Populating instance %s of type %s with parser tree" % (inst.get_name(), inst.get_type())) inst.set_comp_xml(xml_parsed) # # For each instance determine if it is active or passive here... # Determine a maximum base id window required for each instance here PRINT.info( "\nDetermining kind of component and maximum required ID's for component instances" ) for inst in self.get_instances(): type = inst.get_type() name = inst.get_name() kind = inst.get_kind() xml_file = inst.get_comp_xml() if xml_file is None: PRINT.info( "WARNING: No component XML present setting instance named: %s to kind: %s, maximum ID's used is unknown" % (name, kind)) else: k = xml_file.get_component().get_kind() inst.set_kind(k) id_window = self.__max_id_window(inst) inst.set_base_max_id_window(id_window) DEBUG.info( "Setting Instance name: %s, type: %s, kind: %s, maximum ID space required: %s" % (name, type, inst.get_kind(), inst.get_base_max_id_window()))
def create(self, the_parsed_topology_xml, generate_list_file=True): """ Create a topology model here. """ # Instance a list of model.Component classes that are all the instanced items from parsed xml. x = the_parsed_topology_xml componentXMLNameToComponent = ( {} ) # Dictionary maps XML names to processes component objects so redundant processing is avoided components = [] for comp_xml_path in x.get_comp_type_file_header_dict(): try: file_path = locate_build_root(comp_xml_path) except (BuildRootMissingException, BuildRootCollisionException) as bre: stri = "ERROR: Could not find XML file {}. {}".format( comp_xml_path, str(bre), ) raise OSError(stri) processedXML = XmlComponentParser.XmlComponentParser(file_path) comp_name = processedXML.get_component().get_name() componentXMLNameToComponent[comp_name] = processedXML for instance in x.get_instances(): if instance.get_type() not in list( componentXMLNameToComponent.keys()): PRINT.info( "Component XML file type {} was not specified in the topology XML. Please specify the path using <import_component_type> tags." .format(instance.get_type())) else: instance.set_component_object( componentXMLNameToComponent[instance.get_type()]) components.append( Component.Component( instance.get_namespace(), instance.get_name(), instance.get_type(), xml_filename=x.get_xml_filename(), kind2=instance.get_kind(), )) # print "Assembly name: " + x.get_name(), x.get_base_id(), x.get_base_id_window() # for component in components: # print component.get_name(), component.get_base_id(), component.get_base_id_window() if self.__generate_new_IDS: # Iterate over all the model.Component classes and... instance_name_base_id_list = self.__compute_base_ids( x.get_base_id(), x.get_base_id_window(), x.get_instances(), x.get_xml_filename(), generate_list_file, ) else: instance_name_base_id_list = [] # Iterate over all the model.Component classes and then... # Iterate over all the connection sources and assigned output ports to each Component.. # For each output port you want to assign the connect comment, target component name, target port and type... # (Requires adding to the model.Port class ether members or a member called of type TargetConnection) for component in components: port_obj_list = [] for connection in x.get_connections(): if component.get_name() == connection.get_source()[0]: port = Port.Port( connection.get_source()[1], connection.get_source()[2], None, None, comment=connection.get_comment(), xml_filename=x.get_xml_filename, ) port.set_source_num(connection.get_source()[3]) port.set_target_comp(connection.get_target()[0]) port.set_target_port(connection.get_target()[1]) port.set_target_type(connection.get_target()[2]) port.set_target_num(connection.get_target()[3]) if connection.get_source()[1].startswith("i"): port.set_direction("input") else: port.set_direction("output") if connection.get_target()[1].startswith("i"): port.set_target_direction("input") else: port.set_target_direction("output") port_obj_list.append(port) component.set_ports(port_obj_list) # Instance a Topology class and give it namespace, comment and list of components. the_topology = Topology.Topology( x.get_namespace(), x.get_comment(), components, x.get_name(), instance_name_base_id_list, x.get_prepend_instance_name(), ) the_topology.set_instance_header_dict( x.get_comp_type_file_header_dict()) return the_topology
def __init__(self, xml_file=None): self.__root = None self.__is_topology_xml = False self.__in_connection = False self.__namespace = None self.__name = None self.__deployment = None self.__comment = "" self.__xml_filename = xml_file self.__instances = [] self.__connections = [] self.__comp_type_files = [] self.__config = ConfigManager.ConfigManager.getInstance() self.__comp_type_file_header = { } #used to gather header file locations. Optional arg # self.__base_id = None self.__base_id_window = None self.__prepend_instance_name = False #Used to turn off prepending instance name in the situation where instance dicts are being generated and only one instance of an object is created if os.path.isfile(xml_file) == False: stri = "ERROR: Could not find specified XML file %s." % xml_file PRINT.info(stri) raise IOError(stri) fd = open(xml_file, 'r') element_tree = etree.parse(fd) #Validate against schema relax_file_handler = open( ROOTDIR + self.__config.get('schema', 'assembly'), 'r') relax_parsed = etree.parse(relax_file_handler) relax_file_handler.close() relax_compiled = etree.RelaxNG(relax_parsed) try: # 2/3 conversion relax_compiled.validate(element_tree) except Exception as e: PRINT.info( "XML file {} is not valid according to schema {}.".format( xml_file, ROOTDIR + self.__config.get('schema', 'assembly'))) PRINT.info(e) PRINT.info(relax_compiled.error_log) PRINT.info(relax_compiled.error_log.last_error) raise e for e in element_tree.iter(): c = None if e.tag == 'assembly' or e.tag == 'deployment': self.__is_topology_xml = True if 'namespace' in e.attrib: self.__namespace = e.attrib['namespace'] else: self.__namespace = None # if 'name' in e.attrib: self.__name = e.attrib['name'] else: self.__name = None # if 'base_id' in e.attrib: self.__base_id = e.attrib['base_id'] else: self.__base_id = None # if 'base_id_window' in e.attrib: self.__base_id_window = e.attrib['base_id_window'] elif 'base_id_range' in e.attrib: self.__base_id_window = e.attrib['base_id_range'] else: self.__base_id_window = None if 'prepend_instance_name' in e.attrib: if e.attrib['prepend_instance_name'].upper() == "TRUE": self.__prepend_instance_name = True # # The deployment attribute added so that instance # dictionaries are install in the correct place. # if 'deployment' in e.attrib: self.__deployment = e.attrib['deployment'] else: self.__deployment = self.__name # elif e.tag == 'import_component_type': self.__comp_type_files.append(e.text) if "header" in e.attrib: self.__comp_type_file_header[e.text] = e.attrib["header"] else: self.__comp_type_file_header[e.text] = None # elif e.tag == 'connection': self.__in_connection = True n = e.attrib['name'] d = "" if e.tag == 'type': d = e.attrib['type'] else: d = None connection = Connection(n, d) self.__connections.append(connection) # elif e.tag == 'instance': x = e.attrib['name'] y = e.attrib['type'] z = e.attrib['namespace'] if 'kind' in list(e.attrib.keys()): k = e.attrib['kind'] else: k = "active" k = k.lower() if 'base_id' in e.attrib: b = e.attrib['base_id'] else: b = None # if 'base_id_window' in e.attrib: bw = e.attrib['base_id_window'] elif 'base_id_range' in e.attrib: bw = e.attrib['base_id_range'] else: bw = None #Short name - Used to override instance name for dict generation if 'dict_short_name' in e.attrib: sn = e.attrib['dict_short_name'] else: sn = None instance_obj = Instance(x, y, z, k, b, bw, sn) self.__instances.append(instance_obj) elif e.tag == 'source': x = e.attrib['component'] y = e.attrib['port'] z = e.attrib['type'] if "num" in list(e.attrib.keys()): n = int(e.attrib['num']) else: n = 0 self.__connections[-1].set_source(x, y, z, n) elif e.tag == 'target': x = e.attrib['component'] y = e.attrib['port'] z = e.attrib['type'] if "num" in list(e.attrib.keys()): n = int(e.attrib['num']) else: n = 0 self.__connections[-1].set_target(x, y, z, n) elif e.tag == 'comment': c = e.text if self.__in_connection: self.__connections[-1].set_comment(c) else: self.__comment = c elif e.tag == etree.Comment: pass else: PRINT.info("WARNING: Unrecognized topology tag! %s" % (e.tag)) #print "%s %s %s" % (e.tag, e.text, e.attrib) # # For each component xml file specified assign it to a component instance object PRINT.info("\nSearching for component XML files") for xml_file in self.__comp_type_files: core = os.environ.get("FPRIME_CORE_DIR") for possible in [ModelParser.BUILD_ROOT, core, None]: if not possible is None: checker = os.path.join(possible, xml_file) else: checker = xml_file if os.path.exists(checker): break else: PRINT.info("WARNING: Could not find XML file: %s" % xml_file) xml_file = checker.strip() if os.path.exists(xml_file) == True: PRINT.info("Found component XML file: %s" % xml_file) xml_parsed = XmlComponentParser.XmlComponentParser(xml_file) for inst in self.get_instances(): if inst.get_type() == xml_parsed.get_component().get_name( ): PRINT.info( "Populating instance %s of type %s with parser tree" % (inst.get_name(), inst.get_type())) DEBUG.info( "Populating instance %s of type %s with parser tree" % (inst.get_name(), inst.get_type())) inst.set_comp_xml(xml_parsed) # # For each instance determine if it is active or passive here... # Determine a maximum base id window required for each instance here PRINT.info( "\nDetermining kind of component and maximum reqired ID's for component instances" ) for inst in self.get_instances(): type = inst.get_type() name = inst.get_name() kind = inst.get_kind() xml_file = inst.get_comp_xml() if xml_file == None: PRINT.info( "WARNING: No component XML present setting instance named: %s to kind: %s, maximum ID's used is unknown" % (name, kind)) else: k = xml_file.get_component().get_kind() inst.set_kind(k) id_window = self.__max_id_window(inst) inst.set_base_max_id_window(id_window) DEBUG.info( "Setting Instance name: %s, type: %s, kind: %s, maximum ID space required: %s" % (name, type, inst.get_kind(), inst.get_base_max_id_window()))
def main(): """ Main program. """ global VERBOSE global BUILD_ROOT global DEPLOYMENT Parser = pinit() (opt, args) = Parser.parse_args() VERBOSE = opt.verbose_flag CONFIG = ConfigManager.ConfigManager.getInstance() # # Handle command line arguments # # # Parse the input Topology XML filename # if len(args) == 0: print("ERROR: Usage: %s [options] xml_filename" % sys.argv[0]) return elif len(args) == 1: xml_filename = args[0] else: print("ERROR: Too many filenames, should only have one") return # # Check for BUILD_ROOT variable for XML port searches # if not opt.build_root_overwrite == None: BUILD_ROOT = opt.build_root_overwrite ModelParser.BUILD_ROOT = BUILD_ROOT if VERBOSE: print("BUILD_ROOT set to %s" % BUILD_ROOT) else: if ('BUILD_ROOT' in os.environ.keys()) == False: print("ERROR: Build root not set to root build path...") sys.exit(-1) BUILD_ROOT = os.environ['BUILD_ROOT'] ModelParser.BUILD_ROOT = BUILD_ROOT if VERBOSE: print("BUILD_ROOT set to %s in environment" % BUILD_ROOT) # # Write test component # if not "Ai" in xml_filename: print("ERROR: Missing Ai at end of file name...") raise IOError # # Create python dictionaries # print(xml_filename) xml_type = XmlParser.XmlParser(xml_filename)() # Only Components can be inputted if xml_type == "component": if VERBOSE: print("Detected Component XML so GeneratingComponent C++ Files...") the_parsed_component_xml = XmlComponentParser.XmlComponentParser( xml_filename) component_model = parse_component(the_parsed_component_xml, xml_filename, opt) if VERBOSE: print("\nGenerating tests...") generate_tests(opt, component_model) else: print("ERROR: Invalid XML found...this format not supported") sys.exit(-1) sys.exit(0)