'Generate the metadata for the installed tool shed repository, among other things.
This method is called when an administrator is installing a new repository or
reinstalling an uninstalled repository.'

def __handle_repository_contents(self, tool_shed_repository, tool_path, repository_clone_url, relative_install_dir, tool_shed=None, tool_section=None, shed_tool_conf=None, reinstalling=False, tool_panel_section_mapping={}):

    shed_config_dict = self.app.toolbox.get_shed_config_dict_by_filename(shed_tool_conf)
    tdtm = data_table_manager.ToolDataTableManager(self.app)
    irmm = InstalledRepositoryMetadataManager(app=self.app, tpm=self.tpm, repository=tool_shed_repository, changeset_revision=tool_shed_repository.changeset_revision, repository_clone_url=repository_clone_url, shed_config_dict=shed_config_dict, relative_install_dir=relative_install_dir, repository_files_dir=None, resetting_all_metadata_on_repository=False, updating_installed_repository=False, persist=True)
    irmm.generate_metadata_for_changeset_revision()
    irmm_metadata_dict = irmm.get_metadata_dict()
    tool_shed_repository.metadata = irmm_metadata_dict
    tool_shed_status_dict = repository_util.get_tool_shed_status_for_installed_repository(self.app, tool_shed_repository)
    if tool_shed_status_dict:
        tool_shed_repository.tool_shed_status = tool_shed_status_dict
    self.install_model.context.add(tool_shed_repository)
    self.install_model.context.flush()
    if (('tool_dependencies' in irmm_metadata_dict) and (not reinstalling)):
        tool_dependency_util.create_tool_dependency_objects(self.app, tool_shed_repository, relative_install_dir, set_status=True)
    if ('sample_files' in irmm_metadata_dict):
        sample_files = irmm_metadata_dict.get('sample_files', [])
        tool_index_sample_files = tdtm.get_tool_index_sample_files(sample_files)
        (tool_data_table_conf_filename, tool_data_table_elems) = tdtm.install_tool_data_tables(tool_shed_repository, tool_index_sample_files)
        if tool_data_table_elems:
            self.app.tool_data_tables.add_new_entries_from_config_file(tool_data_table_conf_filename, None, self.app.config.shed_tool_data_table_config, persist=True)
    if ('tools' in irmm_metadata_dict):
        self.update_tool_shed_repository_status(tool_shed_repository, self.install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS)
        tool_version_dicts = fetch_tool_versions(self.app, tool_shed_repository)
        tvm = tool_version_manager.ToolVersionManager(self.app)
        tvm.handle_tool_versions(tool_version_dicts, tool_shed_repository)
        tool_panel_dict = self.tpm.generate_tool_panel_dict_for_new_install(irmm_metadata_dict['tools'], tool_section)
        sample_files = irmm_metadata_dict.get('sample_files', [])
        tool_index_sample_files = tdtm.get_tool_index_sample_files(sample_files)
        tool_util.copy_sample_files(self.app, tool_index_sample_files, tool_path=tool_path)
        sample_files_copied = [str(s) for s in tool_index_sample_files]
        repository_tools_tups = irmm.get_repository_tools_tups()
        if repository_tools_tups:
            repository_tools_tups = tdtm.handle_missing_data_table_entry(relative_install_dir, tool_path, repository_tools_tups)
            (repository_tools_tups, sample_files_copied) = tool_util.handle_missing_index_file(self.app, tool_path, sample_files, repository_tools_tups, sample_files_copied)
            tool_util.copy_sample_files(self.app, sample_files, tool_path=tool_path, sample_files_copied=sample_files_copied)
            self.tpm.add_to_tool_panel(repository_name=tool_shed_repository.name, repository_clone_url=repository_clone_url, changeset_revision=tool_shed_repository.installed_changeset_revision, repository_tools_tups=repository_tools_tups, owner=tool_shed_repository.owner, shed_tool_conf=shed_tool_conf, tool_panel_dict=tool_panel_dict, new_install=True, tool_panel_section_mapping=tool_panel_section_mapping)
    if ('data_manager' in irmm_metadata_dict):
        dmh = data_manager.DataManagerHandler(self.app)
        dmh.install_data_managers(self.app.config.shed_data_manager_config_file, irmm_metadata_dict, shed_config_dict, relative_install_dir, tool_shed_repository, repository_tools_tups)
    if ('datatypes' in irmm_metadata_dict):
        self.update_tool_shed_repository_status(tool_shed_repository, self.install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES)
        if (not tool_shed_repository.includes_datatypes):
            tool_shed_repository.includes_datatypes = True
        self.install_model.context.add(tool_shed_repository)
        self.install_model.context.flush()
        files_dir = relative_install_dir
        if shed_config_dict.get('tool_path'):
            files_dir = os.path.join(shed_config_dict['tool_path'], files_dir)
        datatypes_config = hg_util.get_config_from_disk(suc.DATATYPES_CONFIG_FILENAME, files_dir)
        cdl = custom_datatype_manager.CustomDatatypeLoader(self.app)
        (converter_path, display_path) = cdl.alter_config_and_load_prorietary_datatypes(datatypes_config, files_dir, override=False)
        if (converter_path or display_path):
            repository_dict = cdl.create_repository_dict_for_proprietary_datatypes(tool_shed=tool_shed, name=tool_shed_repository.name, owner=tool_shed_repository.owner, installed_changeset_revision=tool_shed_repository.installed_changeset_revision, tool_dicts=irmm_metadata_dict.get('tools', []), converter_path=converter_path, display_path=display_path)
        if converter_path:
            self.app.datatypes_registry.load_datatype_converters(self.app.toolbox, installed_repository_dict=repository_dict, use_cached=True)
        if display_path:
            self.app.datatypes_registry.load_display_applications(self.app, installed_repository_dict=repository_dict)
