def tvm(self): return tool_version_manager.ToolVersionManager(self.app)
def install_repository(self, repository_elem, tool_shed_repository, install_dependencies, is_repository_dependency=False): """Install a single repository, loading contained tools into the tool panel.""" # Install path is of the form: <tool path>/<tool shed>/repos/<repository owner>/<repository name>/<installed changeset revision> relative_clone_dir = os.path.join( tool_shed_repository.tool_shed, 'repos', tool_shed_repository.owner, tool_shed_repository.name, tool_shed_repository.installed_changeset_revision) clone_dir = os.path.join(self.tool_path, relative_clone_dir) cloned_ok = self.__iscloned(clone_dir) is_installed = False # Any of the following states should count as installed in this context. if tool_shed_repository.status in [ self.app.install_model.ToolShedRepository.installation_status. INSTALLED, self.app.install_model.ToolShedRepository. installation_status.ERROR, self.app.install_model. ToolShedRepository.installation_status.UNINSTALLED, self.app.install_model.ToolShedRepository.installation_status. DEACTIVATED ]: is_installed = True if cloned_ok and is_installed: log.info( "Skipping automatic install of repository '%s' because it has already been installed in location %s", tool_shed_repository.name, clone_dir) else: irm = install_manager.InstallRepositoryManager(self.app, self.tpm) repository_clone_url = os.path.join(self.tool_shed_url, 'repos', tool_shed_repository.owner, tool_shed_repository.name) relative_install_dir = os.path.join(relative_clone_dir, tool_shed_repository.name) install_dir = os.path.join(clone_dir, tool_shed_repository.name) ctx_rev = suc.get_ctx_rev( self.app, self.tool_shed_url, tool_shed_repository.name, tool_shed_repository.owner, tool_shed_repository.installed_changeset_revision) if not cloned_ok: irm.update_tool_shed_repository_status( tool_shed_repository, self.app.install_model. ToolShedRepository.installation_status.CLONING) cloned_ok, error_message = hg_util.clone_repository( repository_clone_url, os.path.abspath(install_dir), ctx_rev) if cloned_ok and not is_installed: self.handle_repository_contents( tool_shed_repository=tool_shed_repository, repository_clone_url=repository_clone_url, relative_install_dir=relative_install_dir, repository_elem=repository_elem, install_dependencies=install_dependencies, is_repository_dependency=is_repository_dependency) self.app.install_model.context.refresh(tool_shed_repository) metadata_dict = tool_shed_repository.metadata if 'tools' in metadata_dict: # Initialize the ToolVersionManager. tvm = tool_version_manager.ToolVersionManager(self.app) irm.update_tool_shed_repository_status( tool_shed_repository, self.app.install_model.ToolShedRepository. installation_status.SETTING_TOOL_VERSIONS) # Get the tool_versions from the tool shed for each tool in the installed change set. params = dict(name=tool_shed_repository.name, owner=self.repository_owner, changeset_revision=tool_shed_repository. installed_changeset_revision) pathspec = ['repository', 'get_tool_versions'] text = util.url_get( self.tool_shed_url, password_mgr=self.app.tool_shed_registry.url_auth( self.tool_shed_url), pathspec=pathspec, params=params) if text: tool_version_dicts = json.loads(text) tvm.handle_tool_versions(tool_version_dicts, tool_shed_repository) else: # Set the tool versions since they seem to be missing # for this repository in the tool shed. CRITICAL NOTE: # These default settings may not properly handle all # parent/child associations. for tool_dict in metadata_dict['tools']: tool_id = tool_dict['guid'] old_tool_id = tool_dict['id'] tool_version_using_old_id = tvm.get_tool_version( old_tool_id) tool_version_using_guid = tvm.get_tool_version( tool_id) if not tool_version_using_old_id: tool_version_using_old_id = self.app.install_model.ToolVersion( tool_id=old_tool_id, tool_shed_repository=tool_shed_repository) self.app.install_model.context.add( tool_version_using_old_id) self.app.install_model.context.flush() if not tool_version_using_guid: tool_version_using_guid = self.app.install_model.ToolVersion( tool_id=tool_id, tool_shed_repository=tool_shed_repository) self.app.install_model.context.add( tool_version_using_guid) self.app.install_model.context.flush() # Associate the two versions as parent / child. tool_version_association = tvm.get_tool_version_association( tool_version_using_old_id, tool_version_using_guid) if not tool_version_association: tool_version_association = \ self.app.install_model.ToolVersionAssociation( tool_id=tool_version_using_guid.id, parent_id=tool_version_using_old_id.id ) self.app.install_model.context.add( tool_version_association) self.app.install_model.context.flush() irm.update_tool_shed_repository_status( tool_shed_repository, self.app.install_model. ToolShedRepository.installation_status.INSTALLED) else: log.error('Error attempting to clone repository %s: %s', str(tool_shed_repository.name), str(error_message)) irm.update_tool_shed_repository_status( tool_shed_repository, self.app.install_model.ToolShedRepository. installation_status.ERROR, error_message=error_message)