def install_repository_revision(self, trans, payload, **kwd):
        """
        POST /api/tool_shed_repositories/install_repository_revision
        Install a specified repository revision from a specified tool shed into Galaxy.

        :param key: the current Galaxy admin user's API key

        The following parameters are included in the payload.
        :param tool_shed_url (required): the base URL of the Tool Shed from which to install the Repository
        :param name (required): the name of the Repository
        :param owner (required): the owner of the Repository
        :param changeset_revision (required): the changeset_revision of the RepositoryMetadata object associated with the Repository
        :param new_tool_panel_section_label (optional): label of a new section to be added to the Galaxy tool panel in which to load
                                                        tools contained in the Repository.  Either this parameter must be an empty string or
                                                        the tool_panel_section_id parameter must be an empty string or both must be an empty
                                                        string (both cannot be used simultaneously).
        :param tool_panel_section_id (optional): id of the Galaxy tool panel section in which to load tools contained in the Repository.
                                                 If this parameter is an empty string and the above new_tool_panel_section_label parameter is an
                                                 empty string, tools will be loaded outside of any sections in the tool panel.  Either this
                                                 parameter must be an empty string or the tool_panel_section_id parameter must be an empty string
                                                 of both must be an empty string (both cannot be used simultaneously).
        :param install_repository_dependencies (optional): Set to True if you want to install repository dependencies defined for the specified
                                                           repository being installed.  The default setting is False.
        :param install_tool_dependencies (optional): Set to True if you want to install tool dependencies defined for the specified repository being
                                                     installed.  The default setting is False.
        :param shed_tool_conf (optional): The shed-related tool panel configuration file configured in the "tool_config_file" setting in the Galaxy config file
                                          (e.g., galaxy.ini).  At least one shed-related tool panel config file is required to be configured. Setting
                                          this parameter to a specific file enables you to choose where the specified repository will be installed because
                                          the tool_path attribute of the <toolbox> from the specified file is used as the installation location
                                          (e.g., <toolbox tool_path="database/shed_tools">).  If this parameter is not set, a shed-related tool panel
                                          configuration file will be selected automatically.
        """
        # Get the information about the repository to be installed from the payload.
        tool_shed_url, name, owner, changeset_revision = self.__parse_repository_from_payload(
            payload, include_changeset=True)
        self.__ensure_can_install_repos(trans)
        irm = InstallRepositoryManager(self.app)
        installed_tool_shed_repositories = irm.install(tool_shed_url, name,
                                                       owner,
                                                       changeset_revision,
                                                       payload)

        def to_dict(tool_shed_repository):
            tool_shed_repository_dict = tool_shed_repository.as_dict(
                value_mapper=self.__get_value_mapper(trans,
                                                     tool_shed_repository))
            tool_shed_repository_dict['url'] = url_for(
                controller='tool_shed_repositories',
                action='show',
                id=trans.security.encode_id(tool_shed_repository.id))
            return tool_shed_repository_dict

        if installed_tool_shed_repositories:
            return list(map(to_dict, installed_tool_shed_repositories))
        message = "No repositories were installed, possibly because the selected repository has already been installed."
        return dict(status="ok", message=message)
Example #2
0
class InstallRepositoryManagerTestCase(ToolShedRepoBaseTestCase):

    def setUp(self):
        super().setUp()
        self.irm = InstallRepositoryManager(self.app)
        self.app.config.enable_tool_shed_check = False
        self.app.update_repository_manager = UpdateRepositoryManager(self.app)

    def test_tool_shed_repository_install(self):
        hg_util.clone_repository = MagicMock(return_value=(True, None))
        self._install_tool_shed_repository(start_status='New', end_status='Installed', changeset_revision='1')
        hg_util.clone_repository.assert_called_with(
            'github.com/repos/galaxyproject/example',
            os.path.abspath(os.path.join('../shed_tools', 'github.com/repos/galaxyproject/example/1/example')),
            '1',
        )

    def test_tool_shed_repository_update(self):
        common_util.get_tool_shed_url_from_tool_shed_registry = MagicMock(return_value='https://github.com')
        repository_util.get_tool_shed_status_for_installed_repository = MagicMock(return_value={'revision_update': 'false'})
        hg_util.pull_repository = MagicMock()
        hg_util.update_repository = MagicMock(return_value=(True, None))
        self._install_tool_shed_repository(start_status='Installed', end_status='Installed', changeset_revision='2')
        assert hg_util.pull_repository.call_args[0][0].endswith('github.com/repos/galaxyproject/example/1/example')
        assert hg_util.pull_repository.call_args[0][1] == 'https://github.com/repos/galaxyproject/example'
        assert hg_util.pull_repository.call_args[0][2] == '2'
        assert hg_util.update_repository.call_args[0][0].endswith('github.com/repos/galaxyproject/example/1/example')
        assert hg_util.update_repository.call_args[0][1] == '2'

    def _install_tool_shed_repository(self, start_status, end_status, changeset_revision):
        repository = self._setup_repository()
        repository.status = start_status
        repo_info_dict: Dict[str, Any] = {
            'example': (
                'description', 'github.com/repos/galaxyproject/example', changeset_revision, changeset_revision, 'galaxyproject', [], [],
            )
        }
        self.irm.install_tool_shed_repository(
            repository,
            repo_info_dict,
            'section_key',
            self.app.config.tool_configs[0],
            '../shed_tools',
            False,
            False,
            reinstalling=False,
        )
        assert repository.status == end_status
        assert repository.changeset_revision == changeset_revision
Example #3
0
 def setUp(self):
     super().setUp()
     self.irm = InstallRepositoryManager(self.app)
     self.app.config.enable_tool_shed_check = False
     self.app.update_repository_manager = UpdateRepositoryManager(self.app)