def read_section(self, project, section_name, section_text):
        """ Read the section named section_name whose complete text is section_text into project. """

        old_section = project.find_section(section_name)
        #if old_section:
        #    project.sections.remove(old_section)
        new_section = None
        attr_name = project.format_as_attribute_name(section_name)
        reader_name = "read_" + attr_name
        if hasattr(self, reader_name):
            reader = self.__getattribute__(reader_name)
            try:
                new_section = reader.read(section_text)
            except Exception as e:
                print("Exception calling " + reader_name + " for " + section_name + ":\n" + str(e) +
                      '\n' + str(traceback.print_exc()))

        if new_section is None:
            print("Default Section for " + section_name)
            new_section = Section()
            new_section.SECTION_NAME = section_name
            if not section_name == section_text:
                new_section.value = section_text

        if "REACTION" in new_section.SECTION_NAME.upper() and old_section:
            for vmdata in old_section.metadata:
                old_section.__setattr__(vmdata.attribute, new_section.__getattribute__(vmdata.attribute))
            if new_section.value and len(new_section.value) > 0:
                for spec in new_section.value:
                    old_section.value.append(spec)
        else:
            project.__setattr__(attr_name, new_section)

        if old_section is None: #new_section not in project.sections:
            project.sections.append(new_section)
Beispiel #2
0
    def read_section(self, project, section_name, section_text):
        """ Read the section named section_name whose complete text is section_text into project. """

        # old_section = project.find_section(section_name)
        # if old_section:
        #     project.sections.remove(old_section)
        new_section = None
        attr_name = project.format_as_attribute_name(section_name)
        reader_name = "read_" + attr_name
        if hasattr(self, reader_name):
            reader = self.__getattribute__(reader_name)
            try:
                new_section = reader.read(section_text)
            except Exception as e:
                print("Exception calling " + reader_name + " for " +
                      section_name + ":\n" + str(e) + '\n' +
                      str(traceback.print_exc()))

        if new_section is None:
            print("Default Section for " + section_name)
            new_section = Section()
            new_section.SECTION_NAME = section_name
            new_section.value = section_text

        project.__setattr__(attr_name, new_section)
        if new_section not in project.sections:
            project.sections.append(new_section)
    def read_section(self, project, section_name, section_text):
        """ Read the section named section_name whose complete text is section_text into project. """

        old_section = project.find_section(section_name)
        #if old_section:
        #    project.sections.remove(old_section)
        new_section = None
        attr_name = project.format_as_attribute_name(section_name)

        # special case for section 'lid_controls', because of multi-line structure, must strip out comment lines
        if attr_name == "lid_controls":
            # strip comment lines from section_text
            section_text_list = section_text.split('\n')
            string_without_comments = ""
            for line in section_text_list:
                if line[0] != ";":
                    string_without_comments += line + '\n'
            section_text = string_without_comments[:-1]

        reader_name = "read_" + attr_name
        if hasattr(self, reader_name):
            reader = self.__getattribute__(reader_name)
            try:
                new_section = reader.read(section_text)
            except Exception as e:
                print("Exception calling " + reader_name + " for " + section_name + ":\n" + str(e) +
                      '\n' + str(traceback.print_exc()))

        if new_section is None:
            if not section_name == '[END]':
                self.input_err_msg += '\n' + 'Unrecognized keyword (' + section_name + ').'
            print("Default Section for " + section_name)
            new_section = Section()
            new_section.SECTION_NAME = section_name
            if not section_name == section_text:
                new_section.value = section_text

        if "REACTION" in new_section.SECTION_NAME.upper() and old_section:
            for vmdata in old_section.metadata:
                old_section.__setattr__(vmdata.attribute, new_section.__getattribute__(vmdata.attribute))
            if new_section.value and len(new_section.value) > 0:
                for spec in new_section.value:
                    old_section.value.append(spec)
        else:
            project.__setattr__(attr_name, new_section)

        if old_section is None: #new_section not in project.sections:
            project.sections.append(new_section)
Beispiel #4
0
 def read(self, new_text):
     section = self._init_section()
     for line in new_text.splitlines(
     )[1:]:  # process each line after the first one [section name]
         # if row starts with semicolon or is blank, add as a comment
         if line.lstrip().startswith(';') or not line.strip():
             if section.value:  # If we have already added items to this section, add comment as a Section
                 comment = Section()
                 comment.SECTION_NAME = "Comment"
                 comment.value = line
                 section.value.append(comment)
             else:  # If we are still at the beginning of the section, set comment instead of adding a Section
                 self.set_comment_check_section(section, line)
         else:
             self.read_item(section, line)
     return section