def __api_import_new_workflow(self, trans, payload, **kwd): data = payload['workflow'] raw_workflow_description = self.__normalize_workflow(trans, data) data = raw_workflow_description.as_dict import_tools = util.string_as_bool(payload.get("import_tools", False)) if import_tools and not trans.user_is_admin: raise exceptions.AdminRequiredException() from_dict_kwds = self.__import_or_update_kwds(payload) publish = util.string_as_bool(payload.get("publish", False)) # If 'publish' set, default to importable. importable = util.string_as_bool(payload.get("importable", publish)) if publish and not importable: raise exceptions.RequestParameterInvalidException("Published workflow must be importable.") from_dict_kwds["publish"] = publish workflow, missing_tool_tups = self._workflow_from_dict(trans, raw_workflow_description, **from_dict_kwds) if importable: self._make_item_accessible(trans.sa_session, workflow) trans.sa_session.flush() # galaxy workflow newly created id workflow_id = workflow.id # api encoded, id encoded_id = trans.security.encode_id(workflow_id) item = workflow.to_dict(value_mapper={'id': trans.security.encode_id}) item['annotations'] = [x.annotation for x in workflow.annotations] item['url'] = url_for('workflow', id=encoded_id) item['owner'] = workflow.user.username item['number_of_steps'] = len(workflow.latest_workflow.steps) if import_tools: tools = {} for key in data['steps']: item = data['steps'][key] if item is not None: if 'tool_shed_repository' in item: tool_shed_repository = item['tool_shed_repository'] if 'owner' in tool_shed_repository and 'changeset_revision' in tool_shed_repository and 'name' in tool_shed_repository and 'tool_shed' in tool_shed_repository: toolstr = tool_shed_repository['owner'] \ + tool_shed_repository['changeset_revision'] \ + tool_shed_repository['name'] \ + tool_shed_repository['tool_shed'] tools[toolstr] = tool_shed_repository irm = InstallRepositoryManager(self.app) for k in tools: item = tools[k] tool_shed_url = 'https://' + item['tool_shed'] + '/' name = item['name'] owner = item['owner'] changeset_revision = item['changeset_revision'] irm.install(tool_shed_url, name, owner, changeset_revision, payload) return item
def __api_import_new_workflow(self, trans, payload, **kwd): data = payload['workflow'] raw_workflow_description = self.__normalize_workflow(trans, data) data = raw_workflow_description.as_dict import_tools = util.string_as_bool(payload.get("import_tools", False)) if import_tools and not trans.user_is_admin: raise exceptions.AdminRequiredException() from_dict_kwds = self.__import_or_update_kwds(payload) publish = util.string_as_bool(payload.get("publish", False)) # If 'publish' set, default to importable. importable = util.string_as_bool(payload.get("importable", publish)) if publish and not importable: raise exceptions.RequestParameterInvalidException("Published workflow must be importable.") from_dict_kwds["publish"] = publish workflow, missing_tool_tups = self._workflow_from_dict(trans, raw_workflow_description, **from_dict_kwds) if importable: self._make_item_accessible(trans.sa_session, workflow) trans.sa_session.flush() # galaxy workflow newly created id workflow_id = workflow.id # api encoded, id encoded_id = trans.security.encode_id(workflow_id) item = workflow.to_dict(value_mapper={'id': trans.security.encode_id}) item['url'] = url_for('workflow', id=encoded_id) item['owner'] = workflow.user.username item['number_of_steps'] = len(workflow.latest_workflow.steps) if import_tools: tools = {} for key in data['steps']: item = data['steps'][key] if item is not None: if 'tool_shed_repository' in item: tool_shed_repository = item['tool_shed_repository'] if 'owner' in tool_shed_repository and 'changeset_revision' in tool_shed_repository and 'name' in tool_shed_repository and 'tool_shed' in tool_shed_repository: toolstr = tool_shed_repository['owner'] \ + tool_shed_repository['changeset_revision'] \ + tool_shed_repository['name'] \ + tool_shed_repository['tool_shed'] tools[toolstr] = tool_shed_repository irm = InstallRepositoryManager(self.app) for k in tools: item = tools[k] tool_shed_url = 'https://' + item['tool_shed'] + '/' name = item['name'] owner = item['owner'] changeset_revision = item['changeset_revision'] irm.install(tool_shed_url, name, owner, changeset_revision, payload) return item
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'] = web.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)
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="../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' ] = web.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 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 )
def install(self, trans, **kwd): """ POST /api/tool_shed_repositories/install Initiate the installation of a repository. :param install_tool_dependencies: True to install tool dependencies. :param install_repository_dependencies: True to install repository dependencies. :param tool_panel_section_id: The unique identifier for an existing tool panel section :param new_tool_panel_section_label: Create a new tool panel section with this label :param shed_tool_conf: The shed tool config file to use for this installation :param tool_shed_url: The URL for the toolshed whence this repository is being installed :param changeset: The changeset to update to after cloning the repository """ params = dict() irm = InstallRepositoryManager(self.app) changeset = kwd.get('changeset', None) tool_shed_url = kwd.get('tool_shed_url', None) params['name'] = kwd.get('name', None) params['owner'] = kwd.get('owner', None) params['tool_panel_section_id'] = kwd.get('tool_panel_section_id', None) params['new_tool_panel_section_label'] = kwd.get( 'new_tool_panel_section', None) params['tool_panel_section_mapping'] = json.loads( kwd.get('tool_panel_section', '{}')) params['install_tool_dependencies'] = util.asbool( kwd.get('install_tool_dependencies', False)) params['install_repository_dependencies'] = util.asbool( kwd.get('install_repository_dependencies', False)) params['shed_tool_conf'] = kwd.get('shed_tool_conf', None) params['tool_path'] = suc.get_tool_path_by_shed_tool_conf_filename( self.app, params['shed_tool_conf']) try: tool_shed_repositories = irm.install(tool_shed_url, params['name'], params['owner'], changeset, params) if tool_shed_repositories is None: message = "No repositories were installed, possibly because the selected repository has already been installed." return dict(status="ok", message=message) tsr_ids_for_monitoring = [ trans.security.encode_id(tsr.id) for tsr in tool_shed_repositories ] url = web.url_for( controller='admin_toolshed', action='monitor_repository_installation', tool_shed_repository_ids=','.join(tsr_ids_for_monitoring)) return url except RepositoriesInstalledException as e: log.exception(e) return dict(message=e.message, status='error')
def install( self, trans, **kwd ): """ POST /api/tool_shed_repositories/install Initiate the installation of a repository. :param install_resolver_dependencies: True to install resolvable dependencies. :param install_tool_dependencies: True to install tool dependencies. :param install_repository_dependencies: True to install repository dependencies. :param tool_panel_section_id: The unique identifier for an existing tool panel section :param new_tool_panel_section_label: Create a new tool panel section with this label :param shed_tool_conf: The shed tool config file to use for this installation :param tool_shed_url: The URL for the toolshed whence this repository is being installed :param changeset: The changeset to update to after cloning the repository """ params = dict() irm = InstallRepositoryManager( self.app ) changeset = kwd.get( 'changeset', None ) tool_shed_url = kwd.get( 'tool_shed_url', None ) params[ 'name' ] = kwd.get( 'name', None ) params[ 'owner' ] = kwd.get( 'owner', None ) params[ 'tool_panel_section_id' ] = kwd.get( 'tool_panel_section_id', None ) params[ 'new_tool_panel_section_label' ] = kwd.get( 'new_tool_panel_section', None ) params[ 'tool_panel_section_mapping' ] = json.loads( kwd.get( 'tool_panel_section', '{}' ) ) params[ 'install_resolver_dependencies' ] = util.asbool( kwd.get( 'install_resolver_dependencies', False ) ) params[ 'install_tool_dependencies' ] = util.asbool( kwd.get( 'install_tool_dependencies', False ) ) params[ 'install_repository_dependencies' ] = util.asbool( kwd.get( 'install_repository_dependencies', False ) ) params[ 'shed_tool_conf' ] = kwd.get( 'shed_tool_conf', None ) params[ 'tool_path' ] = suc.get_tool_path_by_shed_tool_conf_filename( self.app, params[ 'shed_tool_conf' ] ) try: tool_shed_repositories = irm.install( tool_shed_url, params[ 'name' ], params[ 'owner' ], changeset, params ) if tool_shed_repositories is None: message = "No repositories were installed, possibly because the selected repository has already been installed." return dict( status="ok", message=message ) tsr_ids_for_monitoring = [ trans.security.encode_id( tsr.id ) for tsr in tool_shed_repositories ] url = web.url_for( controller='admin_toolshed', action='monitor_repository_installation', tool_shed_repository_ids=','.join( tsr_ids_for_monitoring ) ) return url except RepositoriesInstalledException as e: log.exception( e ) return dict( message=e.message, status='error' )
def __api_import_new_workflow(self, trans, payload, **kwd): data = payload['workflow'] import_tools = util.string_as_bool(payload.get("import_tools", False)) if import_tools and not trans.user_is_admin(): raise exceptions.AdminRequiredException() publish = util.string_as_bool(payload.get("publish", False)) # If 'publish' set, default to importable. importable = util.string_as_bool(payload.get("importable", publish)) # Galaxy will try to upgrade tool versions that don't match exactly during import, # this prevents that. exact_tools = util.string_as_bool(payload.get("exact_tools", False)) if publish and not importable: raise exceptions.RequestParameterInvalidException("Published workflow must be importable.") from_dict_kwds = dict( source="API", publish=publish, exact_tools=exact_tools, ) workflow, missing_tool_tups = self._workflow_from_dict(trans, data, **from_dict_kwds) if importable: self._make_item_accessible(trans.sa_session, workflow) trans.sa_session.flush() # galaxy workflow newly created id workflow_id = workflow.id # api encoded, id encoded_id = trans.security.encode_id(workflow_id) # return list rval = [] item = workflow.to_dict(value_mapper={'id': trans.security.encode_id}) item['url'] = url_for('workflow', id=encoded_id) item['owner'] = workflow.user.username item['number_of_steps'] = len(workflow.latest_workflow.steps) rval.append(item) # if import_tools: tools = {} for key in data['steps']: item = data['steps'][key] if item is not None: if 'tool_shed_repository' in item: tool_shed_repository = item['tool_shed_repository'] if 'owner' in tool_shed_repository and 'changeset_revision' in tool_shed_repository and 'name' in tool_shed_repository and 'tool_shed' in tool_shed_repository: toolstr = tool_shed_repository['owner'] \ + tool_shed_repository['changeset_revision'] \ + tool_shed_repository['name'] \ + tool_shed_repository['tool_shed'] tools[toolstr] = tool_shed_repository irm = InstallRepositoryManager(self.app) for k in tools: item = tools[k] tool_shed_url = 'https://' + item['tool_shed'] + '/' name = item['name'] owner = item['owner'] changeset_revision = item['changeset_revision'] irm.install(tool_shed_url, name, owner, changeset_revision, payload) return item
def install(self, trans, **kwd): """ POST /api/tool_shed_repositories/install Initiate the installation of a repository. :param install_resolver_dependencies: True to install resolvable dependencies. :param install_tool_dependencies: True to install tool dependencies. :param install_repository_dependencies: True to install repository dependencies. :param tool_panel_section_id: The unique identifier for an existing tool panel section :param new_tool_panel_section_label: Create a new tool panel section with this label :param shed_tool_conf: The shed tool config file to use for this installation :param tool_shed_url: The URL for the toolshed whence this repository is being installed :param changeset: The changeset to update to after cloning the repository """ irm = InstallRepositoryManager(self.app) tool_shed_url = kwd.get('tool_shed_url', None) repositories = json.loads(kwd.get('repositories', '[]')) repo_info_dict = self.__get_repo_info_dict(trans, repositories, tool_shed_url) includes_tools = False includes_tools_for_display_in_tool_panel = False has_repository_dependencies = False includes_tool_dependencies = False install_resolver_dependencies = util.asbool( kwd.get('install_resolver_dependencies', False)) for encoded_repo_info_dict in repo_info_dict.get( 'repo_info_dicts', []): decoded_repo_info_dict = encoding_util.tool_shed_decode( encoded_repo_info_dict) if not includes_tools: includes_tools = util.string_as_bool( decoded_repo_info_dict.get('includes_tools', False)) if not includes_tools_for_display_in_tool_panel: includes_tools_for_display_in_tool_panel = \ util.string_as_bool( decoded_repo_info_dict.get( 'includes_tools_for_display_in_tool_panel', False ) ) if not has_repository_dependencies: has_repository_dependencies = util.string_as_bool( repo_info_dict.get('has_repository_dependencies', False)) if not includes_tool_dependencies: includes_tool_dependencies = util.string_as_bool( repo_info_dict.get('includes_tool_dependencies', False)) encoded_repo_info_dicts = util.listify( repo_info_dict.get('repo_info_dicts', [])) repo_info_dicts = [ encoding_util.tool_shed_decode(encoded_repo_info_dict) for encoded_repo_info_dict in encoded_repo_info_dicts ] tool_panel_section_id = kwd.get('tool_panel_section_id', None) new_tool_panel_section_label = kwd.get('new_tool_panel_section', None) tool_panel_section_mapping = json.loads( kwd.get('tool_panel_section', '{}')) install_tool_dependencies = util.asbool( kwd.get('install_tool_dependencies', False)) install_repository_dependencies = util.asbool( kwd.get('install_repository_dependencies', False)) shed_tool_conf = kwd.get('shed_tool_conf', None) tool_path = suc.get_tool_path_by_shed_tool_conf_filename( self.app, shed_tool_conf) installation_dict = dict( install_repository_dependencies=install_repository_dependencies, new_tool_panel_section_label=new_tool_panel_section_label, no_changes_checked=False, repo_info_dicts=repo_info_dicts, tool_panel_section_id=tool_panel_section_id, tool_path=tool_path, tool_shed_url=tool_shed_url) new_repositories, tool_panel_keys, repo_info_dicts, filtered_repos = irm.handle_tool_shed_repositories( installation_dict) if new_repositories: installation_dict = dict( created_or_updated_tool_shed_repositories=new_repositories, filtered_repo_info_dicts=filtered_repos, has_repository_dependencies=has_repository_dependencies, includes_tool_dependencies=includes_tool_dependencies, includes_tools=includes_tools, includes_tools_for_display_in_tool_panel= includes_tools_for_display_in_tool_panel, install_repository_dependencies=install_repository_dependencies, install_tool_dependencies=install_tool_dependencies, message='', new_tool_panel_section_label=new_tool_panel_section_label, tool_panel_section_mapping=tool_panel_section_mapping, install_resolver_dependencies=install_resolver_dependencies, shed_tool_conf=shed_tool_conf, status='ok', tool_panel_section_id=tool_panel_section_id, tool_panel_section_keys=tool_panel_keys, tool_path=tool_path, tool_shed_url=tool_shed_url) encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ irm.initiate_repository_installation( installation_dict ) return json.dumps( dict( operation='install', api=True, install_resolver_dependencies=install_resolver_dependencies, install_tool_dependencies=install_tool_dependencies, encoded_kwd=encoded_kwd, reinstalling=False, tool_shed_repository_ids=json.dumps( [repo[0] for repo in repositories]), repositories=[ trans.security.encode_id(repo.id) for repo in new_repositories ]))
def install( self, trans, **kwd ): """ POST /api/tool_shed_repositories/install Initiate the installation of a repository. :param install_resolver_dependencies: True to install resolvable dependencies. :param install_tool_dependencies: True to install tool dependencies. :param install_repository_dependencies: True to install repository dependencies. :param tool_panel_section_id: The unique identifier for an existing tool panel section :param new_tool_panel_section_label: Create a new tool panel section with this label :param shed_tool_conf: The shed tool config file to use for this installation :param tool_shed_url: The URL for the toolshed whence this repository is being installed :param changeset: The changeset to update to after cloning the repository """ irm = InstallRepositoryManager( self.app ) tool_shed_url = kwd.get( 'tool_shed_url', None ) repositories = json.loads( kwd.get( 'repositories', '[]' ) ) repo_info_dict = self.__get_repo_info_dict( trans, repositories, tool_shed_url ) includes_tools = False includes_tools_for_display_in_tool_panel = False has_repository_dependencies = False includes_tool_dependencies = False install_resolver_dependencies = util.asbool( kwd.get( 'install_resolver_dependencies', False ) ) for encoded_repo_info_dict in repo_info_dict.get( 'repo_info_dicts', [] ): decoded_repo_info_dict = encoding_util.tool_shed_decode( encoded_repo_info_dict ) if not includes_tools: includes_tools = util.string_as_bool( decoded_repo_info_dict.get( 'includes_tools', False ) ) if not includes_tools_for_display_in_tool_panel: includes_tools_for_display_in_tool_panel = \ util.string_as_bool( decoded_repo_info_dict.get( 'includes_tools_for_display_in_tool_panel', False ) ) if not has_repository_dependencies: has_repository_dependencies = util.string_as_bool( repo_info_dict.get( 'has_repository_dependencies', False ) ) if not includes_tool_dependencies: includes_tool_dependencies = util.string_as_bool( repo_info_dict.get( 'includes_tool_dependencies', False ) ) encoded_repo_info_dicts = util.listify( repo_info_dict.get( 'repo_info_dicts', [] ) ) repo_info_dicts = [ encoding_util.tool_shed_decode( encoded_repo_info_dict ) for encoded_repo_info_dict in encoded_repo_info_dicts ] tool_panel_section_id = kwd.get( 'tool_panel_section_id', None ) new_tool_panel_section_label = kwd.get( 'new_tool_panel_section', None ) tool_panel_section_mapping = json.loads( kwd.get( 'tool_panel_section', '{}' ) ) install_tool_dependencies = util.asbool( kwd.get( 'install_tool_dependencies', False ) ) install_repository_dependencies = util.asbool( kwd.get( 'install_repository_dependencies', False ) ) shed_tool_conf = kwd.get( 'shed_tool_conf', None ) tool_path = suc.get_tool_path_by_shed_tool_conf_filename( self.app, shed_tool_conf ) installation_dict = dict( install_repository_dependencies=install_repository_dependencies, new_tool_panel_section_label=new_tool_panel_section_label, no_changes_checked=False, repo_info_dicts=repo_info_dicts, tool_panel_section_id=tool_panel_section_id, tool_path=tool_path, tool_shed_url=tool_shed_url ) new_repositories, tool_panel_keys, repo_info_dicts, filtered_repos = irm.handle_tool_shed_repositories( installation_dict ) if new_repositories: installation_dict = dict( created_or_updated_tool_shed_repositories=new_repositories, filtered_repo_info_dicts=filtered_repos, has_repository_dependencies=has_repository_dependencies, includes_tool_dependencies=includes_tool_dependencies, includes_tools=includes_tools, includes_tools_for_display_in_tool_panel=includes_tools_for_display_in_tool_panel, install_repository_dependencies=install_repository_dependencies, install_tool_dependencies=install_tool_dependencies, message='', new_tool_panel_section_label=new_tool_panel_section_label, tool_panel_section_mapping=tool_panel_section_mapping, install_resolver_dependencies=install_resolver_dependencies, shed_tool_conf=shed_tool_conf, status='ok', tool_panel_section_id=tool_panel_section_id, tool_panel_section_keys=tool_panel_keys, tool_path=tool_path, tool_shed_url=tool_shed_url ) encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ irm.initiate_repository_installation( installation_dict ) return json.dumps( dict( operation='install', api=True, install_resolver_dependencies=install_resolver_dependencies, install_tool_dependencies=install_tool_dependencies, encoded_kwd=encoded_kwd, reinstalling=False, tool_shed_repository_ids=json.dumps( [ repo[0] for repo in repositories ] ), repositories=[ trans.security.encode_id( repo.id ) for repo in new_repositories ] ) )
def __api_import_new_workflow(self, trans, payload, **kwd): data = payload['workflow'] import_tools = util.string_as_bool(payload.get("import_tools", False)) if import_tools and not trans.user_is_admin(): raise exceptions.AdminRequiredException() publish = util.string_as_bool(payload.get("publish", False)) # If 'publish' set, default to importable. importable = util.string_as_bool(payload.get("importable", publish)) # Galaxy will try to upgrade tool versions that don't match exactly during import, # this prevents that. exact_tools = util.string_as_bool(payload.get("exact_tools", False)) if publish and not importable: raise exceptions.RequestParameterInvalidException( "Published workflow must be importable.") from_dict_kwds = dict( source="API", publish=publish, exact_tools=exact_tools, ) workflow, missing_tool_tups = self._workflow_from_dict( trans, data, **from_dict_kwds) if importable: self._make_item_accessible(trans.sa_session, workflow) trans.sa_session.flush() # galaxy workflow newly created id workflow_id = workflow.id # api encoded, id encoded_id = trans.security.encode_id(workflow_id) # return list rval = [] item = workflow.to_dict(value_mapper={'id': trans.security.encode_id}) item['url'] = url_for('workflow', id=encoded_id) item['owner'] = workflow.user.username item['number_of_steps'] = len(workflow.latest_workflow.steps) rval.append(item) # if import_tools: tools = {} for key in data['steps']: item = data['steps'][key] if item is not None: if 'tool_shed_repository' in item: tool_shed_repository = item['tool_shed_repository'] if 'owner' in tool_shed_repository and 'changeset_revision' in tool_shed_repository and 'name' in tool_shed_repository and 'tool_shed' in tool_shed_repository: toolstr = tool_shed_repository['owner'] \ + tool_shed_repository['changeset_revision'] \ + tool_shed_repository['name'] \ + tool_shed_repository['tool_shed'] tools[toolstr] = tool_shed_repository irm = InstallRepositoryManager(self.app) for k in tools: item = tools[k] tool_shed_url = 'https://' + item['tool_shed'] + '/' name = item['name'] owner = item['owner'] changeset_revision = item['changeset_revision'] irm.install(tool_shed_url, name, owner, changeset_revision, payload) return item
def setUp(self): super(InstallRepositoryManagerTestCase, self).setUp() self.irm = InstallRepositoryManager(self.app) self.app.config.enable_tool_shed_check = False self.app.update_repository_manager = UpdateRepositoryManager(self.app)
class InstallRepositoryManagerTestCase(ToolShedRepoBaseTestCase): def setUp(self): super(InstallRepositoryManagerTestCase, self).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 = { '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