コード例 #1
0
 def add_config(self, name, value, force=False):
     """
     Add a configuration key, value mapping for the project.
     """
     value = ProjectAttributes.get_processed_attribute(
         value,
         self.root,
         name
     )
     if self.config.get(name, None) is not None and not force:
         log.warning(
             'Ignoring duplicate configuration attribute ' +
             'found in project file, ' +
             str(name) +
             ' set to ' +
             str(value) + ' ' +
             'but already defined as ' +
             str(self.config[name])
         )
     else:
         log.debug(
             'Set project configuration \'' +
             str(name) +
             '\' to \'' +
             str(value) +
             '\''
         )
         self.config[name] = value
コード例 #2
0
ファイル: project.py プロジェクト: pabennett/chiptools
 def add_config(self, name, value, force=False):
     """
     Add a configuration key, value mapping for the project.
     """
     value = ProjectAttributes.get_processed_attribute(value, self.root, name)
     if self.config.get(name, None) is not None and not force:
         log.warning(
             "Ignoring duplicate configuration attribute "
             + "found in project file, "
             + str(name)
             + " set to "
             + str(value)
             + " "
             + "but already defined as "
             + str(self.config[name])
         )
     else:
         log.debug("Set project configuration '" + str(name) + "' to '" + str(value) + "'")
         self.config[name] = value
コード例 #3
0
ファイル: xml_project.py プロジェクト: pabennett/chiptools
    def parse_project(
        filepath,
        project_object,
        synthesise=None
    ):
        """Parse the XML project and update the project_dictionary or return
        a new dictionary if one is not supplied.
        """
        log.info('Parsing: ' + str(filepath) + ' synthesis=' + str(synthesise))
        start_time = time.time()
        project_root = os.path.dirname(os.path.realpath(filepath))
        try:
            xml_obj = minidom.parse(filepath)
            for project_node in xml_obj.getElementsByTagName(
                ProjectAttributes.XML_NODE_PROJECT
            ):
                # Project attributes (if any)
                # If this whole node should not be synthesised, ignore any
                # child flags otherwise get the child synthesis flag and use
                # that.
                if synthesise is None:
                    project_attribs = ProjectAttributes.process_attributes(
                        project_node.attributes,
                        project_root
                    )
                    synthesis_enabled = project_attribs.get(
                        ProjectAttributes.ATTRIBUTE_SYNTHESIS,
                        None
                    )
                else:
                    synthesis_enabled = synthesise

                for child in project_node.childNodes:
                    if child.nodeName == ProjectAttributes.XML_NODE_PROJECT:
                        attribs = ProjectAttributes.process_attributes(
                            child.attributes,
                            project_root,
                            defaults=ProjectAttributes.PROJECT_NODE_DEFAULTS
                        )
                        # If this whole node should not be synthesised, ignore
                        # any child flags otherwise get the child synthesis
                        # flag and use that.
                        if synthesis_enabled is None:
                            synthesise = attribs.get(
                                ProjectAttributes.ATTRIBUTE_SYNTHESIS,
                                None
                            )
                        else:
                            synthesise = synthesis_enabled

                        if ProjectAttributes.ATTRIBUTE_PATH in attribs:
                            log.debug(
                                'Found sub-project: ' +
                                str(
                                    attribs[
                                        ProjectAttributes.ATTRIBUTE_PATH
                                    ]
                                )
                            )
                            # Recursively call this parser with the new project
                            # path
                            XmlProjectParser.parse_project(
                                str(
                                    attribs[
                                        ProjectAttributes.ATTRIBUTE_PATH
                                    ]
                                ),
                                project_object,
                                synthesise
                            )
                    elif child.nodeName == ProjectAttributes.XML_NODE_CONFIG:
                        XmlProjectParser._add_config(
                            child,
                            project_root,
                            project_object
                        )
                    elif child.nodeName == ProjectAttributes.XML_NODE_LIBRARY:
                        XmlProjectParser._add_library(
                            child,
                            project_root,
                            project_object,
                            synthesis_enabled
                        )
                    elif child.nodeName == (
                        ProjectAttributes.XML_NODE_CONSTRAINTS
                    ):
                        XmlProjectParser._add_constraints(
                            child,
                            project_root,
                            project_object,
                        )
                    elif child.nodeName == (
                        ProjectAttributes.XML_NODE_UNITTEST
                    ):
                        XmlProjectParser._add_unittest(
                            child,
                            project_root,
                            project_object,
                        )
                    elif child.nodeName == ProjectAttributes.XML_NODE_GENERIC:
                        # Build a dictionary of generics using the attribute
                        # name and value
                        attribs = child.attributes
                        if attribs is None:
                            continue
                        attribs = dict(attribs.items())
                        for attrName, attrVal in attribs.items():
                            project_object.add_generic(
                                attrName,
                                attrVal
                            )
                    elif child.nodeName == ProjectAttributes.XML_NODE_FILE:
                        # Files should not be left unassociated with a library
                        # unless you wish to add all files to the work library.
                        # The default behavior will be to add parentless files
                        # to the work library, but a configuration option could
                        # make this post an error instead.
                        log.warning(
                            'Found file with no parent library, ' +
                            'defaulting to work library'
                        )
                        # If this whole node should not be synthesised, ignore
                        # any child flags otherwise get the child synthesis
                        # flag and use that.
                        if synthesis_enabled is None:
                            synthesise = (
                                ProjectAttributes.get_processed_attribute(
                                    child.attributes.get(
                                        ProjectAttributes.ATTRIBUTE_SYNTHESIS,
                                        None
                                    ),
                                    project_root,
                                    ProjectAttributes.ATTRIBUTE_SYNTHESIS
                                )
                            )
                        else:
                            synthesise = synthesis_enabled

                        XmlProjectParser._add_file(
                            child,
                            'work',
                            project_root,
                            project_object,
                            synthesise=synthesise
                        )
                    elif child.nodeName == ProjectAttributes.XML_NODE_TEXT:
                        pass
                    elif child.nodeName == ProjectAttributes.XML_NODE_COMMENT:
                        pass
        except xml.parsers.expat.ExpatError:
            log.error(
                'Error found in XML file, check the formatting. ' +
                'Refer to the traceback below for the line number and file.'
            )
            log.error(traceback.format_exc())
            project_object.initialise()
            return
        log.debug(filepath + ' parsed in ' + utils.time_delta_string(
            start_time,
            time.time())
        )
コード例 #4
0
    def parse_project(filepath, project_object, synthesise=None):
        """Parse the XML project and update the project_dictionary or return
        a new dictionary if one is not supplied.
        """
        log.info('Parsing: ' + str(filepath) + ' synthesis=' + str(synthesise))
        start_time = time.time()
        project_root = os.path.dirname(os.path.realpath(filepath))
        try:
            xml_obj = minidom.parse(filepath)
            for project_node in xml_obj.getElementsByTagName(
                    ProjectAttributes.XML_NODE_PROJECT):
                # Project attributes (if any)
                # If this whole node should not be synthesised, ignore any
                # child flags otherwise get the child synthesis flag and use
                # that.
                if synthesise is None:
                    project_attribs = ProjectAttributes.process_attributes(
                        project_node.attributes, project_root)
                    synthesis_enabled = project_attribs.get(
                        ProjectAttributes.ATTRIBUTE_SYNTHESIS, None)
                else:
                    synthesis_enabled = synthesise

                for child in project_node.childNodes:
                    if child.nodeName == ProjectAttributes.XML_NODE_PROJECT:
                        attribs = ProjectAttributes.process_attributes(
                            child.attributes,
                            project_root,
                            defaults=ProjectAttributes.PROJECT_NODE_DEFAULTS)
                        # If this whole node should not be synthesised, ignore
                        # any child flags otherwise get the child synthesis
                        # flag and use that.
                        if synthesis_enabled is None:
                            synthesise = attribs.get(
                                ProjectAttributes.ATTRIBUTE_SYNTHESIS, None)
                        else:
                            synthesise = synthesis_enabled

                        if ProjectAttributes.ATTRIBUTE_PATH in attribs:
                            log.debug(
                                'Found sub-project: ' +
                                str(attribs[ProjectAttributes.ATTRIBUTE_PATH]))
                            # Recursively call this parser with the new project
                            # path
                            XmlProjectParser.parse_project(
                                str(attribs[ProjectAttributes.ATTRIBUTE_PATH]),
                                project_object, synthesise)
                    elif child.nodeName == ProjectAttributes.XML_NODE_CONFIG:
                        XmlProjectParser._add_config(child, project_root,
                                                     project_object)
                    elif child.nodeName == ProjectAttributes.XML_NODE_LIBRARY:
                        XmlProjectParser._add_library(child, project_root,
                                                      project_object,
                                                      synthesis_enabled)
                    elif child.nodeName == (
                            ProjectAttributes.XML_NODE_CONSTRAINTS):
                        XmlProjectParser._add_constraints(
                            child,
                            project_root,
                            project_object,
                        )
                    elif child.nodeName == (
                            ProjectAttributes.XML_NODE_UNITTEST):
                        XmlProjectParser._add_unittest(
                            child,
                            project_root,
                            project_object,
                        )
                    elif child.nodeName == ProjectAttributes.XML_NODE_GENERIC:
                        # Build a dictionary of generics using the attribute
                        # name and value
                        attribs = child.attributes
                        if attribs is None:
                            continue
                        attribs = dict(attribs.items())
                        for attrName, attrVal in attribs.items():
                            project_object.add_generic(attrName, attrVal)
                    elif child.nodeName == ProjectAttributes.XML_NODE_FILE:
                        # Files should not be left unassociated with a library
                        # unless you wish to add all files to the work library.
                        # The default behavior will be to add parentless files
                        # to the work library, but a configuration option could
                        # make this post an error instead.
                        log.warning('Found file with no parent library, ' +
                                    'defaulting to work library')
                        # If this whole node should not be synthesised, ignore
                        # any child flags otherwise get the child synthesis
                        # flag and use that.
                        if synthesis_enabled is None:
                            synthesise = (
                                ProjectAttributes.get_processed_attribute(
                                    child.attributes.get(
                                        ProjectAttributes.ATTRIBUTE_SYNTHESIS,
                                        None), project_root,
                                    ProjectAttributes.ATTRIBUTE_SYNTHESIS))
                        else:
                            synthesise = synthesis_enabled

                        XmlProjectParser._add_file(child,
                                                   'work',
                                                   project_root,
                                                   project_object,
                                                   synthesise=synthesise)
                    elif child.nodeName == ProjectAttributes.XML_NODE_TEXT:
                        pass
                    elif child.nodeName == ProjectAttributes.XML_NODE_COMMENT:
                        pass
        except xml.parsers.expat.ExpatError:
            log.error(
                'Error found in XML file, check the formatting. ' +
                'Refer to the traceback below for the line number and file.')
            log.error(traceback.format_exc())
            project_object.initialise()
            return
        log.debug(filepath + ' parsed in ' +
                  utils.time_delta_string(start_time, time.time()))