'Check tool settings in tool_shed_install_config and install all repositories
that are not already installed.  The tool panel configuration file is the received
migrated_tools_config, which is the reserved file named migrated_tools_conf.xml.'

def __init__(self, app, latest_migration_script_number, tool_shed_install_config, migrated_tools_config, install_dependencies):

    self.app = app
    self.toolbox = self.app.toolbox
    self.migrated_tools_config = migrated_tools_config
    self.tpm = tool_panel_manager.ToolPanelManager(self.app)
    if (install_dependencies and (app.config.tool_dependency_dir is None)):
        message = 'You    are    attempting    to    install    tool    dependencies    but    do    not    have    a    value    '
        message += 'for    "tool_dependency_dir"    set    in    your    galaxy.ini    file.        Set    this    '
        message += 'location    value    to    the    path    where    you    want    tool    dependencies    installed    and    '
        message += 'rerun    the    migration    script.'
        raise Exception(message)
    self.proprietary_tool_confs = self.non_shed_tool_panel_configs
    self.proprietary_tool_panel_elems = self.get_proprietary_tool_panel_elems(latest_migration_script_number)
    (tree, error_message) = xml_util.parse_xml(migrated_tools_config)
    if (tree is None):
        log.error(error_message)
    else:
        root = tree.getroot()
        self.tool_path = root.get('tool_path')
        log.debug('Repositories    will    be    installed    into    configured    tool_path    location    ', str(self.tool_path))
        self.tool_shed_install_config = tool_shed_install_config
        (tree, error_message) = xml_util.parse_xml(tool_shed_install_config)
        if (tree is None):
            log.error(error_message)
        else:
            root = tree.getroot()
            defined_tool_shed_url = root.get('name')
            self.tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(self.app, defined_tool_shed_url)
            self.tool_shed = common_util.remove_protocol_and_port_from_tool_shed_url(self.tool_shed_url)
            self.repository_owner = common_util.REPOSITORY_OWNER
            self.shed_config_dict = self.tpm.get_shed_tool_conf_dict(self.migrated_tools_config)
            tool_shed_accessible = False
            tool_panel_configs = common_util.get_non_shed_tool_panel_configs(app)
            if tool_panel_configs:
                (tool_shed_accessible, missing_tool_configs_dict) = common_util.check_for_missing_tools(app, tool_panel_configs, latest_migration_script_number)
            else:
                tool_shed_accessible = True
                missing_tool_configs_dict = odict()
            if tool_shed_accessible:
                if (len(self.proprietary_tool_confs) == 1):
                    plural = ''
                    file_names = self.proprietary_tool_confs[0]
                else:
                    plural = 's'
                    file_names = ',    '.join(self.proprietary_tool_confs)
                if missing_tool_configs_dict:
                    for proprietary_tool_conf in self.proprietary_tool_confs:
                        shutil.copy(proprietary_tool_conf, ('%s-pre-stage-%04d' % (proprietary_tool_conf, latest_migration_script_number)))
                    for repository_elem in root:
                        if self.__is_valid_repository_tag(repository_elem):
                            name = repository_elem.get('name')
                            changeset_revision = repository_elem.get('changeset_revision')
                            (tool_shed_accessible, repository_dependencies_dict) = common_util.get_repository_dependencies(app, self.tool_shed_url, name, self.repository_owner, changeset_revision)
                            created_tool_shed_repositories = self.create_or_update_tool_shed_repository_records(name, changeset_revision, repository_dependencies_dict)
                            ordered_tool_shed_repositories = self.order_repositories_for_installation(created_tool_shed_repositories, repository_dependencies_dict)
                            for tool_shed_repository in ordered_tool_shed_repositories:
                                is_repository_dependency = self.__is_repository_dependency(name, changeset_revision, tool_shed_repository)
                                self.install_repository(repository_elem, tool_shed_repository, install_dependencies, is_repository_dependency=is_repository_dependency)
                else:
                    message = ('\nNo    tools    associated    with    migration    stage    %s    are    defined    in    your    ' % str(latest_migration_script_number))
                    message += ('file%s    named    %s,\nso    no    repositories    will    be    installed    on    disk.\n' % (plural, file_names))
                    log.info(message)
            else:
                message = ('\nThe    main    Galaxy    tool    shed    is    not    currently    available,    so    skipped    migration    stage    %s.\n' % str(latest_migration_script_number))
                message += 'Try    again    later.\n'
                log.error(message)
