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)
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)