'Generate a list of ElementTree Element objects for each section or tool.'

def generate_tool_panel_elem_list(self, repository_name, repository_clone_url, changeset_revision, tool_panel_dict, repository_tools_tups, owner=''):

    elem_list = []
    tool_elem = None
    cleaned_repository_clone_url = common_util.remove_protocol_and_user_from_clone_url(repository_clone_url)
    if (not owner):
        owner = repository_util.get_repository_owner(cleaned_repository_clone_url)
    tool_shed = cleaned_repository_clone_url.split('/repos/')[0].rstrip('/')
    for (guid, tool_section_dicts) in tool_panel_dict.items():
        for tool_section_dict in tool_section_dicts:
            tool_section = None
            inside_section = False
            section_in_elem_list = False
            if tool_section_dict['id']:
                inside_section = True
                for (index, elem) in enumerate(elem_list):
                    if (elem.tag == 'section'):
                        section_id = elem.get('id', None)
                        if (section_id == tool_section_dict['id']):
                            section_in_elem_list = True
                            tool_section = elem
                            break
                if (tool_section is None):
                    tool_section = self.generate_tool_section_element_from_dict(tool_section_dict)
            for repository_tool_tup in repository_tools_tups:
                (tool_file_path, tup_guid, tool) = repository_tool_tup
                if (tup_guid == guid):
                    break
            tool_elem = self.generate_tool_elem(tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, (tool_section if inside_section else None))
            if inside_section:
                if section_in_elem_list:
                    elem_list[index] = tool_section
                else:
                    elem_list.append(tool_section)
            else:
                elem_list.append(tool_elem)
    return elem_list
