Beispiel #1
0
 def read(new_text, project):
     section_map = {"NODE": project.nodes_groups(),
                    "LINK": project.links_groups()}
     disposable_tags = Section()
     disposable_tags.SECTION_NAME = "[TAGS]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_tags, line)
         fields = line.split()
         if len(fields) > 2:
             object_type_name = fields[0].upper()
             object_name = fields[1].upper()
             tag = ' '.join(fields[2:])
             sections = section_map[object_type_name]
             found = False
             for section in sections:
                 for candidate in section.values:
                     if candidate.name.upper() == object_name:
                         candidate.tag = tag
                         found = True
                         # print "Tagged: " + type(candidate).__name__ + ' ' + candidate.name + ' = ' + tag
                         break
                 if found:
                     break
             if not found:
                 print "Tag not applied: " + line
    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 #3
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)
Beispiel #4
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[EMITTERS]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None)
         if len(fields) > 1:
             node_name = fields[0]
             emitter_coefficient = fields[1]
             for node in project.junctions.value:
                 if node.name == node_name:
                     node.setattr_keep_type("emitter_coefficient", emitter_coefficient)
                     break
Beispiel #5
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[STATUS]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None)
         if len(fields) > 1:
             link_name = fields[0]
             status = fields[1]
             for link in project.all_links():
                 if link.name == link_name:
                     link.setattr_keep_type("initial_status", status)
                     break
Beispiel #6
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[QUALITY]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None, 1)
         if len(fields) > 1:
             node_name = fields[0]
             initial_quality = fields[1]
             for nodes in (project.junctions.value, project.reservoirs.value, project.tanks.value):
                 for node in nodes:
                     if node.name == node_name:
                         node.setattr_keep_type("initial_quality", initial_quality)
                         break
Beispiel #7
0
 def read(new_text, project):
     links = project.all_links()
     if links:
         disposable_section = Section()
         disposable_section.SECTION_NAME = "[VERTICES]"
         for line in new_text.splitlines():
             line = SectionReader.set_comment_check_section(disposable_section, line)
             coordinate = CoordinateReader.read(line)
             if coordinate:
                 try:
                     link = links[coordinate.name]
                     link.vertices.append(coordinate)
                 except Exception:
                     print("Link not found in model for vertex " + coordinate.name)
Beispiel #8
0
 def read(new_text, project):
     all_nodes = project.all_nodes()
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[COORDINATES]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         coordinate = CoordinateReader.read(line)
         if coordinate:
             try:
                 node = all_nodes[coordinate.name]
                 node.x = coordinate.x
                 node.y = coordinate.y
             except:
                 print("Node not found in model for coordinate " + coordinate.name)
    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 #10
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
Beispiel #11
0
 def read(new_text, project):
     disposable_section = Section()
     disposable_section.SECTION_NAME = "[MIXING]"
     for line in new_text.splitlines():
         line = SectionReader.set_comment_check_section(disposable_section, line)
         fields = line.split(None)
         if len(fields) > 1:
             node_name = fields[0]
             mixing_model = MixingModel[fields[1].upper().replace("2", "TWO_")]
             if len(fields) > 2:
                 mixing_fraction = fields[2]
             for tank in (project.tanks.value):
                 if tank.name == node_name:
                     tank.setattr_keep_type("mixing_model", mixing_model)
                     if len(fields) > 2:
                         tank.setattr_keep_type("mixing_fraction", mixing_fraction)
                 break