'Keep track of the section in the tool panel in which this repository\'s
tools will be contained by parsing the shed_tool_conf in which the
repository\'s tools are defined and storing the tool panel definition
of each tool in the repository. This method is called only when the
repository is being deactivated or un-installed and allows for
activation or re-installation using the original layout.'

def generate_tool_panel_dict_from_shed_tool_conf_entries(self, repository):

    tool_panel_dict = {}
    (shed_tool_conf, tool_path, relative_install_dir) = suc.get_tool_panel_config_tool_path_install_dir(self.app, repository)
    metadata = repository.metadata
    guids_and_configs = {}
    if ('tools' in metadata):
        for tool_dict in metadata['tools']:
            guid = tool_dict['guid']
            tool_config = tool_dict['tool_config']
            file_name = basic_util.strip_path(tool_config)
            guids_and_configs[guid] = file_name
    (tree, error_message) = xml_util.parse_xml(shed_tool_conf)
    if (tree is None):
        return tool_panel_dict
    root = tree.getroot()
    for elem in root:
        if (elem.tag == 'tool'):
            guid = elem.get('guid')
            if (guid in guids_and_configs):
                tool_section_dict = dict(tool_config=guids_and_configs[guid], id='', name='', version='')
                if (guid in tool_panel_dict):
                    tool_panel_dict[guid].append(tool_section_dict)
                else:
                    tool_panel_dict[guid] = [tool_section_dict]
        elif (elem.tag == 'section'):
            section_id = (elem.get('id') or '')
            section_name = (elem.get('name') or '')
            section_version = (elem.get('version') or '')
            for section_elem in elem:
                if (section_elem.tag == 'tool'):
                    guid = section_elem.get('guid')
                    if (guid in guids_and_configs):
                        tool_section_dict = dict(tool_config=guids_and_configs[guid], id=section_id, name=section_name, version=section_version)
                        if (guid in tool_panel_dict):
                            tool_panel_dict[guid].append(tool_section_dict)
                        else:
                            tool_panel_dict[guid] = [tool_section_dict]
    return tool_panel_dict
