'Return a folder hierarchy containing tool dependencies.'

def build_tool_dependencies_folder(self, folder_id, tool_dependencies, label='Tool    dependencies', missing=False, new_install=False, reinstalling=False):

    if tool_dependencies:
        tool_dependency_id = 0
        folder_id += 1
        tool_dependencies_root_folder = Folder(id=folder_id, key='root', label='root', parent=None)
        folder_id += 1
        folder = Folder(id=folder_id, key='tool_dependencies', label=label, parent=tool_dependencies_root_folder)
        if (self.app.name == 'galaxy'):
            if (new_install or reinstalling):
                folder.description = 'repository    tools    require    handling    of    these    dependencies'
            elif (missing and (not new_install) and (not reinstalling)):
                folder.description = 'click    the    name    to    install    the    missing    dependency'
            else:
                folder.description = 'click    the    name    to    browse    the    dependency    installation    directory'
        tool_dependencies_root_folder.folders.append(folder)
        tool_dependency_id += 1
        if (self.app.name == 'galaxy'):
            tool_dependency = ToolDependency(id=tool_dependency_id, name='Name', version='Version', type='Type', readme=None, installation_status='Installation    status', repository_id=None, tool_dependency_id=None)
        else:
            tool_dependency = ToolDependency(id=tool_dependency_id, name='Name', version='Version', type='Type', readme=None, installation_status=None, repository_id=None, tool_dependency_id=None)
        folder.tool_dependencies.append(tool_dependency)
        for (dependency_key, requirements_dict) in tool_dependencies.items():
            tool_dependency_id += 1
            if (dependency_key in ['set_environment']):
                for set_environment_dict in requirements_dict:
                    try:
                        name = set_environment_dict.get('name', None)
                        type = set_environment_dict['type']
                        repository_id = set_environment_dict.get('repository_id', None)
                        td_id = set_environment_dict.get('tool_dependency_id', None)
                    except Exception as e:
                        name = str(e)
                        type = 'unknown'
                        repository_id = 'unknown'
                        td_id = 'unknown'
                    if (self.app.name == 'galaxy'):
                        try:
                            installation_status = set_environment_dict.get('status', 'Never    installed')
                        except Exception as e:
                            installation_status = str(e)
                    else:
                        installation_status = None
                    tool_dependency = ToolDependency(id=tool_dependency_id, name=name, version=None, type=type, readme=None, installation_status=installation_status, repository_id=repository_id, tool_dependency_id=td_id)
                    folder.tool_dependencies.append(tool_dependency)
            else:
                try:
                    name = requirements_dict['name']
                    version = requirements_dict['version']
                    type = requirements_dict['type']
                    repository_id = requirements_dict.get('repository_id', None)
                    td_id = requirements_dict.get('tool_dependency_id', None)
                except Exception as e:
                    name = str(e)
                    version = 'unknown'
                    type = 'unknown'
                    repository_id = 'unknown'
                    td_id = 'unknown'
                if (self.app.name == 'galaxy'):
                    try:
                        installation_status = requirements_dict.get('status', 'Never    installed')
                    except Exception as e:
                        installation_status = str(e)
                else:
                    installation_status = None
                tool_dependency = ToolDependency(id=tool_dependency_id, name=name, version=version, type=type, readme=None, installation_status=installation_status, repository_id=repository_id, tool_dependency_id=td_id)
                folder.tool_dependencies.append(tool_dependency)
    else:
        tool_dependencies_root_folder = None
    return (folder_id, tool_dependencies_root_folder)
