10 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/d10fc2e9a14d/ Changeset: d10fc2e9a14d User: jmchilton Date: 2014-06-09 16:13:39 Summary: Refactoring toward allowing tool shed installs outside of web threads. Continuing work started by Greg, nearly all the helpers called from "install_repository_revision" in tool_shed_repositry API take in app instead of trans. This was 36 fairly atomic commits that I have rebased into 1 (even for me that is a lot of commits for absolutely no new functionality). One can track the invidual steps and check work here: https://github.com/jmchilton/galaxy-central/compare/tool_shed_hacking. Affected #: 9 files diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -347,7 +347,7 @@ tool_shed_url=tool_shed_url ) # Create the tool_shed_repository database records and gather additional information for repository installation. created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_util.handle_tool_shed_repositories( trans, installation_dict, using_api=True ) + repository_util.handle_tool_shed_repositories( trans.app, installation_dict, using_api=True ) if created_or_updated_tool_shed_repositories: # Build the dictionary of information necessary for installing the repositories. installation_dict = dict( created_or_updated_tool_shed_repositories=created_or_updated_tool_shed_repositories, @@ -370,12 +370,12 @@ # changeset_revision, there may be multiple repositories for installation at this point because repository dependencies may have added # additional repositories for installation along with the single specified repository. encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ - repository_util.initiate_repository_installation( trans, installation_dict ) + repository_util.initiate_repository_installation( trans.app, installation_dict ) # Some repositories may have repository dependencies that are required to be installed before the dependent repository, so we'll # order the list of tsr_ids to ensure all repositories install in the required order. tsr_ids = [ trans.security.encode_id( tool_shed_repository.id ) for tool_shed_repository in tool_shed_repositories ] ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ - repository_util.order_components_for_installation( trans, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) + repository_util.order_components_for_installation( trans.app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) # Install the repositories, keeping track of each one for later display. for index, tsr_id in enumerate( ordered_tsr_ids ): tool_shed_repository = trans.install_model.context.query( trans.install_model.ToolShedRepository ).get( trans.security.decode_id( tsr_id ) ) @@ -384,7 +384,7 @@ repo_info_dict = ordered_repo_info_dicts[ index ] tool_panel_section_key = ordered_tool_panel_section_keys[ index ] - repository_util.install_tool_shed_repository( trans, + repository_util.install_tool_shed_repository( trans.app, tool_shed_repository, repo_info_dict, tool_panel_section_key, diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -47,7 +47,7 @@ repository_id = kwd[ 'id' ] repository = suc.get_installed_tool_shed_repository( trans, repository_id ) try: - common_install_util.activate_repository( trans, repository ) + common_install_util.activate_repository( trans.app, repository ) except Exception, e: error_message = "Error activating repository %s: %s" % ( repository.name, str( e ) ) log.exception( error_message ) @@ -107,7 +107,7 @@ # repository dependencies and tool dependencies will be current. Only allow selecting a different section # in the tool panel if the repository was uninstalled and it contained tools that should be displayed in # the tool panel. - changeset_revision_dict = repository_util.get_update_to_changeset_revision_and_ctx_rev( trans, repository ) + changeset_revision_dict = repository_util.get_update_to_changeset_revision_and_ctx_rev( trans.app, repository ) current_changeset_revision = changeset_revision_dict.get( 'changeset_revision', None ) current_ctx_rev = changeset_revision_dict.get( 'ctx_rev', None ) if current_changeset_revision and current_ctx_rev: @@ -517,7 +517,7 @@ tmp_clone_url = common_util.url_join( tool_shed_url, 'repos', owner, name ) tmp_repo_info_tuple = ( None, tmp_clone_url, latest_downloadable_revision, None, owner, None, None ) installed_repository, installed_changeset_revision = \ - suc.repository_was_previously_installed( trans, tool_shed_url, name, tmp_repo_info_tuple, from_tip=False ) + suc.repository_was_previously_installed( trans.app, tool_shed_url, name, tmp_repo_info_tuple, from_tip=False ) if installed_repository: current_changeset_revision = str( installed_repository.changeset_revision ) message = 'Revision <b>%s</b> of repository <b>%s</b> owned by <b>%s</b> has already been installed.' % \ @@ -629,7 +629,7 @@ for index, tool_shed_repository in enumerate( tool_shed_repositories ): repo_info_dict = repo_info_dicts[ index ] tool_panel_section_key = tool_panel_section_keys[ index ] - repository_util.install_tool_shed_repository( trans, + repository_util.install_tool_shed_repository( trans.app, tool_shed_repository, repo_info_dict, tool_panel_section_key, @@ -692,7 +692,7 @@ # dependent repository, so we'll order the list of tsr_ids to ensure all repositories install in the # required order. ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ - repository_util.order_components_for_installation( trans, + repository_util.order_components_for_installation( trans.app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) @@ -1070,7 +1070,7 @@ tool_path=tool_path, tool_shed_url=tool_shed_url ) created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_util.handle_tool_shed_repositories( trans, installation_dict, using_api=False ) + repository_util.handle_tool_shed_repositories( trans.app, installation_dict, using_api=False ) if created_or_updated_tool_shed_repositories: installation_dict = dict( created_or_updated_tool_shed_repositories=created_or_updated_tool_shed_repositories, filtered_repo_info_dicts=filtered_repo_info_dicts, @@ -1089,7 +1089,7 @@ tool_path=tool_path, tool_shed_url=tool_shed_url ) encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ - repository_util.initiate_repository_installation( trans, installation_dict ) + repository_util.initiate_repository_installation( trans.app, installation_dict ) return trans.fill_template( 'admin/tool_shed_repository/initiate_repository_installation.mako', encoded_kwd=encoded_kwd, query=query, @@ -1287,7 +1287,7 @@ if tool_shed_repository.includes_tools_for_display_in_tool_panel: # Handle the selected tool panel location for loading tools included in the tool shed repository. tool_section, tool_panel_section_key = \ - tool_util.handle_tool_panel_selection( trans=trans, + tool_util.handle_tool_panel_selection( toolbox=trans.app.toolbox, metadata=metadata, no_changes_checked=no_changes_checked, tool_panel_section_id=tool_panel_section_id, @@ -1345,7 +1345,7 @@ repo_info_dicts.append( repo_info_dict ) # Make sure all tool_shed_repository records exist. created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_dependency_util.create_repository_dependency_objects( trans=trans, + repository_dependency_util.create_repository_dependency_objects( app=trans.app, tool_path=tool_path, tool_shed_url=tool_shed_url, repo_info_dicts=repo_info_dicts, @@ -1713,7 +1713,7 @@ """An error occurred while cloning the repository, so reset everything necessary to enable another attempt.""" repository = suc.get_installed_tool_shed_repository( trans, kwd[ 'id' ] ) if kwd.get( 'reset_repository', False ): - repository_util.set_repository_attributes( trans, + repository_util.set_repository_attributes( trans.app, repository, status=trans.install_model.ToolShedRepository.installation_status.NEW, error_message=None, diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/tool_shed/galaxy_install/repository_util.py --- a/lib/tool_shed/galaxy_install/repository_util.py +++ b/lib/tool_shed/galaxy_install/repository_util.py @@ -135,13 +135,13 @@ prior_install_required_dict[ tsr_id ] = [] # Inspect the repository dependencies for each repository about to be installed and populate the dictionary. for repo_info_dict in repo_info_dicts: - repository, repository_dependencies = suc.get_repository_and_repository_dependencies_from_repo_info_dict( trans, repo_info_dict ) + repository, repository_dependencies = suc.get_repository_and_repository_dependencies_from_repo_info_dict( trans.app, repo_info_dict ) if repository: encoded_repository_id = trans.security.encode_id( repository.id ) if encoded_repository_id in tsr_ids: # We've located the database table record for one of the repositories we're about to install, so find out if it has any repository # dependencies that require prior installation. - prior_install_ids = suc.get_repository_ids_requiring_prior_import_or_install( trans, tsr_ids, repository_dependencies ) + prior_install_ids = suc.get_repository_ids_requiring_prior_import_or_install( trans.app, tsr_ids, repository_dependencies ) prior_install_required_dict[ encoded_repository_id ] = prior_install_ids return prior_install_required_dict @@ -174,7 +174,7 @@ tool_panel_section_keys.append( tool_panel_section_key ) repo_info_dicts.append( repo_info_dict ) ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ - order_components_for_installation( trans, + order_components_for_installation( trans.app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) @@ -264,7 +264,7 @@ tool_panel_section_name = section_dict[ 'name' ] if tool_panel_section_id: tool_panel_section_key, tool_panel_section = \ - tool_util.get_or_create_tool_section( trans, + tool_util.get_or_create_tool_section( trans.app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=tool_panel_section_name ) else: @@ -314,16 +314,16 @@ '' return [] -def get_update_to_changeset_revision_and_ctx_rev( trans, repository ): +def get_update_to_changeset_revision_and_ctx_rev( app, repository ): """Return the changeset revision hash to which the repository can be updated.""" changeset_revision_dict = {} - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, str( repository.tool_shed ) ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( repository.tool_shed ) ) params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( repository.name ), str( repository.owner ), str( repository.installed_changeset_revision ) ) url = common_util.url_join( tool_shed_url, 'repository/get_changeset_revision_and_ctx_rev%s' % params ) try: - encoded_update_dict = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + encoded_update_dict = common_util.tool_shed_get( app, tool_shed_url, url ) if encoded_update_dict: update_dict = encoding_util.tool_shed_decode( encoded_update_dict ) includes_data_managers = update_dict.get( 'includes_data_managers', False ) @@ -360,15 +360,16 @@ changeset_revision_dict[ 'ctx_rev' ] = None return changeset_revision_dict -def handle_repository_contents( trans, tool_shed_repository, tool_path, repository_clone_url, relative_install_dir, +def handle_repository_contents( app, tool_shed_repository, tool_path, repository_clone_url, relative_install_dir, tool_shed=None, tool_section=None, shed_tool_conf=None, reinstalling=False ): """ Generate the metadata for the installed tool shed repository, among other things. This method is called from Galaxy (never the tool shed) when an administrator is installing a new repository or reinstalling an uninstalled repository. """ - shed_config_dict = trans.app.toolbox.get_shed_config_dict_by_filename( shed_tool_conf ) + install_model = app.install_model + shed_config_dict = app.toolbox.get_shed_config_dict_by_filename( shed_tool_conf ) metadata_dict, invalid_file_tups = \ - metadata_util.generate_metadata_for_changeset_revision( app=trans.app, + metadata_util.generate_metadata_for_changeset_revision( app=app, repository=tool_shed_repository, changeset_revision=tool_shed_repository.changeset_revision, repository_clone_url=repository_clone_url, @@ -380,13 +381,13 @@ persist=True ) tool_shed_repository.metadata = metadata_dict # Update the tool_shed_repository.tool_shed_status column in the database. - tool_shed_status_dict = suc.get_tool_shed_status_for_installed_repository( trans.app, tool_shed_repository ) + tool_shed_status_dict = suc.get_tool_shed_status_for_installed_repository( app, tool_shed_repository ) if tool_shed_status_dict: tool_shed_repository.tool_shed_status = tool_shed_status_dict - trans.install_model.context.add( tool_shed_repository ) - trans.install_model.context.flush() + install_model.context.add( tool_shed_repository ) + install_model.context.flush() if 'tool_dependencies' in metadata_dict and not reinstalling: - tool_dependencies = tool_dependency_util.create_tool_dependency_objects( trans.app, + tool_dependencies = tool_dependency_util.create_tool_dependency_objects( app, tool_shed_repository, relative_install_dir, set_status=True ) @@ -394,36 +395,36 @@ sample_files = metadata_dict.get( 'sample_files', [] ) tool_index_sample_files = tool_util.get_tool_index_sample_files( sample_files ) tool_data_table_conf_filename, tool_data_table_elems = \ - tool_util.install_tool_data_tables( trans.app, tool_shed_repository, tool_index_sample_files ) + tool_util.install_tool_data_tables( app, tool_shed_repository, tool_index_sample_files ) if tool_data_table_elems: - trans.app.tool_data_tables.add_new_entries_from_config_file( tool_data_table_conf_filename, + app.tool_data_tables.add_new_entries_from_config_file( tool_data_table_conf_filename, None, - trans.app.config.shed_tool_data_table_config, + app.config.shed_tool_data_table_config, persist=True ) if 'tools' in metadata_dict: tool_panel_dict = tool_util.generate_tool_panel_dict_for_new_install( metadata_dict[ 'tools' ], tool_section ) sample_files = metadata_dict.get( 'sample_files', [] ) tool_index_sample_files = tool_util.get_tool_index_sample_files( sample_files ) - tool_util.copy_sample_files( trans.app, tool_index_sample_files, tool_path=tool_path ) + tool_util.copy_sample_files( app, tool_index_sample_files, tool_path=tool_path ) sample_files_copied = [ str( s ) for s in tool_index_sample_files ] - repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata_dict ) + repository_tools_tups = suc.get_repository_tools_tups( app, metadata_dict ) if repository_tools_tups: # Handle missing data table entries for tool parameters that are dynamically generated select lists. - repository_tools_tups = tool_util.handle_missing_data_table_entry( trans.app, + repository_tools_tups = tool_util.handle_missing_data_table_entry( app, relative_install_dir, tool_path, repository_tools_tups ) # Handle missing index files for tool parameters that are dynamically generated select lists. repository_tools_tups, sample_files_copied = \ - tool_util.handle_missing_index_file( trans.app, + tool_util.handle_missing_index_file( app, tool_path, sample_files, repository_tools_tups, sample_files_copied ) # Copy remaining sample files included in the repository to the ~/tool-data directory of the # local Galaxy instance. - tool_util.copy_sample_files( trans.app, sample_files, tool_path=tool_path, sample_files_copied=sample_files_copied ) - tool_util.add_to_tool_panel( app=trans.app, + tool_util.copy_sample_files( app, sample_files, tool_path=tool_path, sample_files_copied=sample_files_copied ) + tool_util.add_to_tool_panel( app=app, repository_name=tool_shed_repository.name, repository_clone_url=repository_clone_url, changeset_revision=tool_shed_repository.installed_changeset_revision, @@ -433,26 +434,26 @@ tool_panel_dict=tool_panel_dict, new_install=True ) if 'data_manager' in metadata_dict: - new_data_managers = data_manager_util.install_data_managers( trans.app, - trans.app.config.shed_data_manager_config_file, + new_data_managers = data_manager_util.install_data_managers( app, + app.config.shed_data_manager_config_file, metadata_dict, shed_config_dict, relative_install_dir, tool_shed_repository, repository_tools_tups ) if 'datatypes' in metadata_dict: - tool_shed_repository.status = trans.install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES + tool_shed_repository.status = install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES if not tool_shed_repository.includes_datatypes: tool_shed_repository.includes_datatypes = True - trans.install_model.context.add( tool_shed_repository ) - trans.install_model.context.flush() + install_model.context.add( tool_shed_repository ) + 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 ) # Load data types required by tools. converter_path, display_path = \ - datatype_util.alter_config_and_load_prorietary_datatypes( trans.app, datatypes_config, files_dir, override=False ) + datatype_util.alter_config_and_load_prorietary_datatypes( app, datatypes_config, files_dir, override=False ) if converter_path or display_path: # Create a dictionary of tool shed repository related information. repository_dict = \ @@ -465,12 +466,12 @@ display_path=display_path ) if converter_path: # Load proprietary datatype converters - trans.app.datatypes_registry.load_datatype_converters( trans.app.toolbox, installed_repository_dict=repository_dict ) + app.datatypes_registry.load_datatype_converters( app.toolbox, installed_repository_dict=repository_dict ) if display_path: # Load proprietary datatype display applications - trans.app.datatypes_registry.load_display_applications( installed_repository_dict=repository_dict ) + app.datatypes_registry.load_display_applications( installed_repository_dict=repository_dict ) -def handle_tool_shed_repositories( trans, installation_dict, using_api=False ): +def handle_tool_shed_repositories( app, installation_dict, using_api=False ): # The following installation_dict entries are all required. install_repository_dependencies = installation_dict[ 'install_repository_dependencies' ] new_tool_panel_section_label = installation_dict[ 'new_tool_panel_section_label' ] @@ -480,7 +481,7 @@ tool_path = installation_dict[ 'tool_path' ] tool_shed_url = installation_dict[ 'tool_shed_url' ] created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_dependency_util.create_repository_dependency_objects( trans=trans, + repository_dependency_util.create_repository_dependency_objects( app=app, tool_path=tool_path, tool_shed_url=tool_shed_url, repo_info_dicts=repo_info_dicts, @@ -490,7 +491,8 @@ new_tool_panel_section_label=new_tool_panel_section_label ) return created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts -def initiate_repository_installation( trans, installation_dict ): +def initiate_repository_installation( app, installation_dict ): + install_model = app.install_model # The following installation_dict entries are all required. created_or_updated_tool_shed_repositories = installation_dict[ 'created_or_updated_tool_shed_repositories' ] filtered_repo_info_dicts = installation_dict[ 'filtered_repo_info_dicts' ] @@ -511,13 +513,13 @@ # Handle contained tools. if includes_tools_for_display_in_tool_panel and ( new_tool_panel_section_label or tool_panel_section_id ): tool_panel_section_key, tool_section = \ - tool_util.handle_tool_panel_section( trans, + tool_util.handle_tool_panel_section( app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) else: tool_panel_section_key = None tool_section = None - encoded_repository_ids = [ trans.security.encode_id( tsr.id ) for tsr in created_or_updated_tool_shed_repositories ] + encoded_repository_ids = [ app.security.encode_id( tsr.id ) for tsr in created_or_updated_tool_shed_repositories ] new_kwd = dict( includes_tools=includes_tools, includes_tools_for_display_in_tool_panel=includes_tools_for_display_in_tool_panel, has_repository_dependencies=has_repository_dependencies, @@ -536,19 +538,20 @@ tsr_ids = [ r.id for r in created_or_updated_tool_shed_repositories ] tool_shed_repositories = [] for tsr_id in tsr_ids: - tsr = trans.install_model.context.query( trans.install_model.ToolShedRepository ).get( tsr_id ) + tsr = install_model.context.query( install_model.ToolShedRepository ).get( tsr_id ) tool_shed_repositories.append( tsr ) clause_list = [] for tsr_id in tsr_ids: - clause_list.append( trans.install_model.ToolShedRepository.table.c.id == tsr_id ) - query = trans.install_model.context.query( trans.install_model.ToolShedRepository ).filter( or_( *clause_list ) ) + clause_list.append( install_model.ToolShedRepository.table.c.id == tsr_id ) + query = install_model.context.query( install_model.ToolShedRepository ).filter( or_( *clause_list ) ) return encoded_kwd, query, tool_shed_repositories, encoded_repository_ids -def install_tool_shed_repository( trans, tool_shed_repository, repo_info_dict, tool_panel_section_key, shed_tool_conf, tool_path, +def install_tool_shed_repository( app, tool_shed_repository, repo_info_dict, tool_panel_section_key, shed_tool_conf, tool_path, install_tool_dependencies, reinstalling=False ): + install_model = app.install_model if tool_panel_section_key: try: - tool_section = trans.app.toolbox.tool_panel[ tool_panel_section_key ] + tool_section = app.toolbox.tool_panel[ tool_panel_section_key ] except KeyError: log.debug( 'Invalid tool_panel_section_key "%s" specified. Tools will be loaded outside of sections in the tool panel.', str( tool_panel_section_key ) ) @@ -558,31 +561,30 @@ if isinstance( repo_info_dict, basestring ): repo_info_dict = encoding_util.tool_shed_decode( repo_info_dict ) # Clone each repository to the configured location. - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.CLONING ) + install_model.ToolShedRepository.installation_status.CLONING ) repo_info_tuple = repo_info_dict[ tool_shed_repository.name ] description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = repo_info_tuple relative_clone_dir = suc.generate_tool_shed_repository_install_dir( repository_clone_url, tool_shed_repository.installed_changeset_revision ) - clone_dir = os.path.join( tool_path, relative_clone_dir ) relative_install_dir = os.path.join( relative_clone_dir, tool_shed_repository.name ) install_dir = os.path.join( tool_path, relative_install_dir ) cloned_ok, error_message = hg_util.clone_repository( repository_clone_url, os.path.abspath( install_dir ), ctx_rev ) if cloned_ok: if reinstalling: # Since we're reinstalling the repository we need to find the latest changeset revision to which it can be updated. - changeset_revision_dict = get_update_to_changeset_revision_and_ctx_rev( trans, tool_shed_repository ) + changeset_revision_dict = get_update_to_changeset_revision_and_ctx_rev( app, tool_shed_repository ) current_changeset_revision = changeset_revision_dict.get( 'changeset_revision', None ) current_ctx_rev = changeset_revision_dict.get( 'ctx_rev', None ) if current_ctx_rev != ctx_rev: - repo = hg_util.get_repo_for_repository( trans.app, + repo = hg_util.get_repo_for_repository( app, repository=None, repo_path=os.path.abspath( install_dir ), create=False ) pull_repository( repo, repository_clone_url, current_changeset_revision ) hg_util.update_repository( repo, ctx_rev=current_ctx_rev ) - handle_repository_contents( trans, + handle_repository_contents( app, tool_shed_repository=tool_shed_repository, tool_path=tool_path, repository_clone_url=repository_clone_url, @@ -591,23 +593,23 @@ tool_section=tool_section, shed_tool_conf=shed_tool_conf, reinstalling=reinstalling ) - trans.install_model.context.refresh( tool_shed_repository ) + install_model.context.refresh( tool_shed_repository ) metadata = tool_shed_repository.metadata if 'tools' in metadata: # Get the tool_versions from the tool shed for each tool in the installed change set. - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS ) - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, str( tool_shed_repository.tool_shed ) ) + install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( tool_shed_repository.tool_shed ) ) params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( tool_shed_repository.name ), str( tool_shed_repository.owner ), str( tool_shed_repository.changeset_revision ) ) url = common_util.url_join( tool_shed_url, '/repository/get_tool_versions%s' % params ) - text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + text = common_util.tool_shed_get( app, tool_shed_url, url ) if text: tool_version_dicts = json.from_json_string( text ) - tool_util.handle_tool_versions( trans.app, tool_version_dicts, tool_shed_repository ) + tool_util.handle_tool_versions( app, tool_version_dicts, tool_shed_repository ) else: if not error_message: error_message = "" @@ -617,29 +619,29 @@ if install_tool_dependencies and tool_shed_repository.tool_dependencies and 'tool_dependencies' in metadata: work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-itsr" ) # Install tool dependencies. - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES ) + install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES ) # Get the tool_dependencies.xml file from the repository. tool_dependencies_config = hg_util.get_config_from_disk( 'tool_dependencies.xml', install_dir ) installed_tool_dependencies = \ - common_install_util.install_specified_tool_dependencies( app=trans.app, + common_install_util.install_specified_tool_dependencies( app=app, tool_shed_repository=tool_shed_repository, tool_dependencies_config=tool_dependencies_config, tool_dependencies=tool_shed_repository.tool_dependencies, from_tool_migration_manager=False ) basic_util.remove_dir( work_dir ) - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.INSTALLED ) - if trans.app.config.manage_dependency_relationships: + install_model.ToolShedRepository.installation_status.INSTALLED ) + if app.config.manage_dependency_relationships: # Add the installed repository and any tool dependencies to the in-memory dictionaries in the installed_repository_manager. - trans.app.installed_repository_manager.handle_repository_install( tool_shed_repository ) + app.installed_repository_manager.handle_repository_install( tool_shed_repository ) else: # An error occurred while cloning the repository, so reset everything necessary to enable another attempt. - set_repository_attributes( trans, + set_repository_attributes( app, tool_shed_repository, - status=trans.install_model.ToolShedRepository.installation_status.ERROR, + status=install_model.ToolShedRepository.installation_status.ERROR, error_message=error_message, deleted=False, uninstalled=False, @@ -722,7 +724,7 @@ lock.release() return new_containers_dict -def order_components_for_installation( trans, tsr_ids, repo_info_dicts, tool_panel_section_keys ): +def order_components_for_installation( app, tsr_ids, repo_info_dicts, tool_panel_section_keys ): """ Some repositories may have repository dependencies that are required to be installed before the dependent repository. This method will inspect the list of repositories about to be installed and make sure to order them appropriately. @@ -737,7 +739,7 @@ # Create a dictionary whose keys are the received tsr_ids and whose values are a list of tsr_ids, each of which is # contained in the received list of tsr_ids and whose associated repository must be installed prior to the repository # associated with the tsr_id key. - prior_install_required_dict = suc.get_prior_import_or_install_required_dict( trans, tsr_ids, repo_info_dicts ) + prior_install_required_dict = suc.get_prior_import_or_install_required_dict( app, tsr_ids, repo_info_dicts ) processed_tsr_ids = [] while len( processed_tsr_ids ) != len( prior_install_required_dict.keys() ): tsr_id = suc.get_next_prior_import_or_install_required_dict_entry( prior_install_required_dict, processed_tsr_ids ) @@ -825,7 +827,7 @@ repair_dict = {} if repository.status in [ trans.install_model.ToolShedRepository.installation_status.DEACTIVATED ]: try: - common_install_util.activate_repository( trans, repository ) + common_install_util.activate_repository( trans.app, repository ) except Exception, e: error_message = "Error activating repository %s: %s" % ( repository.name, str( e ) ) log.debug( error_message ) @@ -835,7 +837,7 @@ # Reset the repository attributes to the New state for installation. if metadata: tool_section, tool_panel_section_key = \ - tool_util.handle_tool_panel_selection( trans, + tool_util.handle_tool_panel_selection( trans.app.toolbox, metadata, no_changes_checked=True, tool_panel_section_id=None, @@ -843,14 +845,14 @@ else: # The tools will be loaded outside of any sections in the tool panel. tool_panel_section_key = None - set_repository_attributes( trans, + set_repository_attributes( trans.app, repository, status=trans.install_model.ToolShedRepository.installation_status.NEW, error_message=None, deleted=False, uninstalled=False, remove_from_disk=True ) - install_tool_shed_repository( trans, + install_tool_shed_repository( trans.app, repository, repo_info_dict, tool_panel_section_key, @@ -893,9 +895,9 @@ suc.update_tool_shed_repository_status( trans.app, repository, trans.install_model.ToolShedRepository.installation_status.INSTALLED ) return repair_dict -def set_repository_attributes( trans, repository, status, error_message, deleted, uninstalled, remove_from_disk=False ): +def set_repository_attributes( app, repository, status, error_message, deleted, uninstalled, remove_from_disk=False ): if remove_from_disk: - relative_install_dir = repository.repo_path( trans.app ) + relative_install_dir = repository.repo_path( app ) if relative_install_dir: clone_dir = os.path.abspath( relative_install_dir ) try: @@ -907,8 +909,8 @@ repository.status = status repository.deleted = deleted repository.uninstalled = uninstalled - trans.install_model.context.add( repository ) - trans.install_model.context.flush() + app.install_model.context.add( repository ) + app.install_model.context.flush() def update_repository_record( trans, repository, updated_metadata_dict, updated_changeset_revision, updated_ctx_rev ): """ diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/tool_shed/util/common_install_util.py --- a/lib/tool_shed/util/common_install_util.py +++ b/lib/tool_shed/util/common_install_util.py @@ -22,18 +22,19 @@ log = logging.getLogger( __name__ ) -def activate_repository( trans, repository ): +def activate_repository( app, repository ): """Activate an installed tool shed repository that has been marked as deactivated.""" - repository_clone_url = common_util.generate_clone_url_for_installed_repository( trans.app, repository ) - shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( trans.app, repository ) + install_model = app.install_model + repository_clone_url = common_util.generate_clone_url_for_installed_repository( app, repository ) + shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( app, repository ) repository.deleted = False - repository.status = trans.install_model.ToolShedRepository.installation_status.INSTALLED + repository.status = install_model.ToolShedRepository.installation_status.INSTALLED if repository.includes_tools_for_display_in_tool_panel: metadata = repository.metadata - repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata ) + repository_tools_tups = suc.get_repository_tools_tups( app, metadata ) # Reload tools into the appropriate tool panel section. tool_panel_dict = repository.metadata[ 'tool_panel_section' ] - tool_util.add_to_tool_panel( trans.app, + tool_util.add_to_tool_panel( app, repository.name, repository_clone_url, repository.installed_changeset_revision, @@ -43,32 +44,32 @@ tool_panel_dict, new_install=False ) if repository.includes_data_managers: - tp, data_manager_relative_install_dir = repository.get_tool_relative_path( trans.app ) + tp, data_manager_relative_install_dir = repository.get_tool_relative_path( app ) # Hack to add repository.name here, which is actually the root of the installed repository data_manager_relative_install_dir = os.path.join( data_manager_relative_install_dir, repository.name ) - new_data_managers = data_manager_util.install_data_managers( trans.app, - trans.app.config.shed_data_manager_config_file, + new_data_managers = data_manager_util.install_data_managers( app, + app.config.shed_data_manager_config_file, metadata, - repository.get_shed_config_dict( trans.app ), + repository.get_shed_config_dict( app ), data_manager_relative_install_dir, repository, repository_tools_tups ) - trans.install_model.context.add( repository ) - trans.install_model.context.flush() + install_model.context.add( repository ) + install_model.context.flush() if repository.includes_datatypes: if tool_path: repository_install_dir = os.path.abspath( os.path.join( tool_path, relative_install_dir ) ) else: repository_install_dir = os.path.abspath( relative_install_dir ) # Activate proprietary datatypes. - installed_repository_dict = datatype_util.load_installed_datatypes( trans.app, repository, repository_install_dir, deactivate=False ) + installed_repository_dict = datatype_util.load_installed_datatypes( app, repository, repository_install_dir, deactivate=False ) if installed_repository_dict: converter_path = installed_repository_dict.get( 'converter_path' ) if converter_path is not None: - datatype_util.load_installed_datatype_converters( trans.app, installed_repository_dict, deactivate=False ) + datatype_util.load_installed_datatype_converters( app, installed_repository_dict, deactivate=False ) display_path = installed_repository_dict.get( 'display_path' ) if display_path is not None: - datatype_util.load_installed_display_applications( trans.app, installed_repository_dict, deactivate=False ) + datatype_util.load_installed_display_applications( app, installed_repository_dict, deactivate=False ) def get_dependencies_for_repository( trans, tool_shed_url, repo_info_dict, includes_tool_dependencies, updating=False ): """ @@ -107,7 +108,7 @@ installed_rd, missing_rd = \ get_installed_and_missing_repository_dependencies_for_new_or_updated_install( trans, repo_info_tuple ) # Discover all repository dependencies and retrieve information for installing them. - all_repo_info_dict = get_required_repo_info_dicts( trans, tool_shed_url, util.listify( repo_info_dict ) ) + all_repo_info_dict = get_required_repo_info_dicts( trans.app, tool_shed_url, util.listify( repo_info_dict ) ) has_repository_dependencies = all_repo_info_dict.get( 'has_repository_dependencies', False ) has_repository_dependencies_only_if_compiling_contained_td = \ all_repo_info_dict.get( 'has_repository_dependencies_only_if_compiling_contained_td', False ) @@ -145,7 +146,7 @@ missing_td[ td_key ] = td_dict else: # We have a single repository with (possibly) no defined repository dependencies. - all_repo_info_dict = get_required_repo_info_dicts( trans, tool_shed_url, util.listify( repo_info_dict ) ) + all_repo_info_dict = get_required_repo_info_dicts( trans.app, tool_shed_url, util.listify( repo_info_dict ) ) has_repository_dependencies = all_repo_info_dict.get( 'has_repository_dependencies', False ) has_repository_dependencies_only_if_compiling_contained_td = \ all_repo_info_dict.get( 'has_repository_dependencies_only_if_compiling_contained_td', False ) @@ -261,7 +262,7 @@ # repository_dependencies, installed_td ) tmp_clone_url = common_util.generate_clone_url_from_repo_info_tup( trans, rd_tup ) tmp_repo_info_tuple = ( None, tmp_clone_url, changeset_revision, None, owner, None, None ) - repository, installed_changeset_revision = suc.repository_was_previously_installed( trans, + repository, installed_changeset_revision = suc.repository_was_previously_installed( trans.app, tool_shed, name, tmp_repo_info_tuple, @@ -380,7 +381,7 @@ missing_tool_dependencies[ td_key ] = val return installed_tool_dependencies, missing_tool_dependencies -def get_required_repo_info_dicts( trans, tool_shed_url, repo_info_dicts ): +def get_required_repo_info_dicts( app, tool_shed_url, repo_info_dicts ): """ Inspect the list of repo_info_dicts for repository dependencies and append a repo_info_dict for each of them to the list. All repository_dependencies entries in each of the received repo_info_dicts includes @@ -444,9 +445,9 @@ encoded_required_repository_tups.append( encoding_util.encoding_sep.join( required_repository_tup ) ) encoded_required_repository_str = encoding_util.encoding_sep2.join( encoded_required_repository_tups ) encoded_required_repository_str = encoding_util.tool_shed_encode( encoded_required_repository_str ) - if trans.webapp.name == 'galaxy': + if suc.is_tool_shed_client( app ): # Handle secure / insecure Tool Shed URL protocol changes and port changes. - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed_url ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed_url ) url = common_util.url_join( tool_shed_url, '/repository/get_required_repo_info_dict' ) # Fix for handling 307 redirect not being handled nicely by urllib2.urlopen when the urllib2.Request has data provided url = urllib2.urlopen( urllib2.Request( url ) ).geturl() diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/tool_shed/util/export_util.py --- a/lib/tool_shed/util/export_util.py +++ b/lib/tool_shed/util/export_util.py @@ -262,7 +262,7 @@ str( repository.user.username ), repository_dependencies, None ) - all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( trans, tool_shed_url, [ repo_info_dict ] ) + all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( trans.app, tool_shed_url, [ repo_info_dict ] ) all_repo_info_dicts = all_required_repo_info_dict.get( 'all_repo_info_dicts', [] ) return all_repo_info_dicts @@ -320,7 +320,7 @@ # Create a dictionary whose keys are the received repository_ids and whose values are a list of # repository_ids, each of which is contained in the received list of repository_ids and whose associated # repository must be imported prior to the repository associated with the repository_id key. - prior_import_required_dict = suc.get_prior_import_or_install_required_dict( trans, repository_ids, repo_info_dicts ) + prior_import_required_dict = suc.get_prior_import_or_install_required_dict( trans.app, repository_ids, repo_info_dicts ) processed_repository_ids = [] # Process the list of repository dependencies defined for the repository associated with the received # primary_repository_id. diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/tool_shed/util/repository_dependency_util.py --- a/lib/tool_shed/util/repository_dependency_util.py +++ b/lib/tool_shed/util/repository_dependency_util.py @@ -16,12 +16,13 @@ log = logging.getLogger( __name__ ) -def build_repository_dependency_relationships( trans, repo_info_dicts, tool_shed_repositories ): +def build_repository_dependency_relationships( app, repo_info_dicts, tool_shed_repositories ): """ Build relationships between installed tool shed repositories and other installed tool shed repositories upon which they depend. These relationships are defined in the repository_dependencies entry for each dictionary in the received list of repo_info_dicts. Each of these dictionaries is associated with a repository in the received tool_shed_repositories list. """ + install_model = app.install_model log.debug( "Building repository dependency relationships..." ) for repo_info_dict in repo_info_dicts: for name, repo_info_tuple in repo_info_dict.items(): @@ -45,7 +46,7 @@ break if d_repository is None: # The dependent repository is not in the received list so look in the database. - d_repository = suc.get_or_create_tool_shed_repository( trans, d_toolshed, d_name, d_owner, d_changeset_revision ) + d_repository = suc.get_or_create_tool_shed_repository( app, d_toolshed, d_name, d_owner, d_changeset_revision ) # Process each repository_dependency defined for the current dependent repository. for repository_dependency_components_list in val: required_repository = None @@ -60,7 +61,7 @@ break if required_repository is None: # The required repository is not in the received list so look in the database. - required_repository = suc.get_or_create_tool_shed_repository( trans, + required_repository = suc.get_or_create_tool_shed_repository( app, rd_toolshed, rd_name, rd_owner, @@ -73,20 +74,20 @@ break if not rrda: # Make sure required_repository is in the repository_dependency table. - repository_dependency = get_repository_dependency_by_repository_id( trans, required_repository.id ) + repository_dependency = get_repository_dependency_by_repository_id( install_model, required_repository.id ) if not repository_dependency: log.debug( 'Creating new repository_dependency record for installed revision %s of repository: %s owned by %s.' % \ ( str( required_repository.installed_changeset_revision ), str( required_repository.name ), str( required_repository.owner ) ) ) - repository_dependency = trans.install_model.RepositoryDependency( tool_shed_repository_id=required_repository.id ) - trans.install_model.context.add( repository_dependency ) - trans.install_model.context.flush() + repository_dependency = install_model.RepositoryDependency( tool_shed_repository_id=required_repository.id ) + install_model.context.add( repository_dependency ) + install_model.context.flush() # Build the relationship between the d_repository and the required_repository. - rrda = trans.install_model.RepositoryRepositoryDependencyAssociation( tool_shed_repository_id=d_repository.id, - repository_dependency_id=repository_dependency.id ) - trans.install_model.context.add( rrda ) - trans.install_model.context.flush() + rrda = install_model.RepositoryRepositoryDependencyAssociation( tool_shed_repository_id=d_repository.id, + repository_dependency_id=repository_dependency.id ) + install_model.context.add( rrda ) + install_model.context.flush() def can_add_to_key_rd_dicts( key_rd_dict, key_rd_dicts ): """Handle the case where an update to the changeset revision was done.""" @@ -101,7 +102,7 @@ return False return True -def create_repository_dependency_objects( trans, tool_path, tool_shed_url, repo_info_dicts, install_repository_dependencies=False, +def create_repository_dependency_objects( app, tool_path, tool_shed_url, repo_info_dicts, install_repository_dependencies=False, no_changes_checked=False, tool_panel_section_id=None, new_tool_panel_section_label=None ): """ Discover all repository dependencies and make sure all tool_shed_repository and associated repository_dependency @@ -110,6 +111,7 @@ in the all_repo_info_dicts list will be processed. However, if repository dependencies are not to be installed, only those items contained in the received repo_info_dicts list will be processed. """ + install_model = app.install_model log.debug( "Creating repository dependency objects..." ) # The following list will be maintained within this method to contain all created or updated tool shed repositories, # including repository dependencies that may not be installed. @@ -125,7 +127,7 @@ # Discover all repository dependencies and retrieve information for installing them. Even if the user elected # to not install repository dependencies we have to make sure all repository dependency objects exist so that # the appropriate repository dependency relationships can be built. - all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( trans, tool_shed_url, repo_info_dicts ) + all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( app, tool_shed_url, repo_info_dicts ) all_repo_info_dicts = all_required_repo_info_dict.get( 'all_repo_info_dicts', [] ) if not all_repo_info_dicts: # No repository dependencies were discovered so process the received repositories. @@ -142,14 +144,14 @@ suc.get_repo_info_tuple_contents( repo_info_tuple ) # See if the repository has an existing record in the database. repository_db_record, installed_changeset_revision = \ - suc.repository_was_previously_installed( trans, tool_shed_url, name, repo_info_tuple, from_tip=False ) + suc.repository_was_previously_installed( app, tool_shed_url, name, repo_info_tuple, from_tip=False ) if repository_db_record: - if repository_db_record.status in [ trans.install_model.ToolShedRepository.installation_status.INSTALLED, - trans.install_model.ToolShedRepository.installation_status.CLONING, - trans.install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS, - trans.install_model.ToolShedRepository.installation_status.INSTALLING_REPOSITORY_DEPENDENCIES, - trans.install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES, - trans.install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES ]: + if repository_db_record.status in [ install_model.ToolShedRepository.installation_status.INSTALLED, + install_model.ToolShedRepository.installation_status.CLONING, + install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS, + install_model.ToolShedRepository.installation_status.INSTALLING_REPOSITORY_DEPENDENCIES, + install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES, + install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES ]: debug_msg = "Skipping installation of revision %s of repository '%s' because it was installed " % \ ( str( changeset_revision ), str( repository_db_record.name ) ) debug_msg += "with the (possibly updated) revision %s and its current installation status is '%s'." % \ @@ -157,26 +159,26 @@ log.debug( debug_msg ) can_update_db_record = False else: - if repository_db_record.status in [ trans.install_model.ToolShedRepository.installation_status.ERROR, - trans.install_model.ToolShedRepository.installation_status.NEW, - trans.install_model.ToolShedRepository.installation_status.UNINSTALLED ]: + if repository_db_record.status in [ install_model.ToolShedRepository.installation_status.ERROR, + install_model.ToolShedRepository.installation_status.NEW, + install_model.ToolShedRepository.installation_status.UNINSTALLED ]: # The current tool shed repository is not currently installed, so we can update its record in the database. name = repository_db_record.name installed_changeset_revision = repository_db_record.installed_changeset_revision metadata_dict = repository_db_record.metadata dist_to_shed = repository_db_record.dist_to_shed can_update_db_record = True - elif repository_db_record.status in [ trans.install_model.ToolShedRepository.installation_status.DEACTIVATED ]: + elif repository_db_record.status in [ install_model.ToolShedRepository.installation_status.DEACTIVATED ]: # The current tool shed repository is deactivated, so updating its database record is not necessary - just activate it. log.debug( "Reactivating deactivated tool_shed_repository '%s'." % str( repository_db_record.name ) ) - common_install_util.activate_repository( trans, repository_db_record ) + common_install_util.activate_repository( app, repository_db_record ) # No additional updates to the database record are necessary. can_update_db_record = False - elif repository_db_record.status not in [ trans.install_model.ToolShedRepository.installation_status.NEW ]: + elif repository_db_record.status not in [ install_model.ToolShedRepository.installation_status.NEW ]: # Set changeset_revision here so suc.create_or_update_tool_shed_repository will find the previously installed # and uninstalled repository instead of creating a new record. changeset_revision = repository_db_record.installed_changeset_revision - suc.reset_previously_installed_repository( trans, repository_db_record ) + suc.reset_previously_installed_repository( install_model, repository_db_record ) can_update_db_record = True else: # No record exists in the database for the repository currently being processed. @@ -189,7 +191,7 @@ # to see where it was previously located in the tool panel. if repository_db_record and repository_db_record.metadata: tool_section, tool_panel_section_key = \ - tool_util.handle_tool_panel_selection( trans=trans, + tool_util.handle_tool_panel_selection( toolbox=app.toolbox, metadata=repository_db_record.metadata, no_changes_checked=no_changes_checked, tool_panel_section_id=tool_panel_section_id, @@ -197,18 +199,18 @@ else: # We're installing a new tool shed repository that does not yet have a database record. tool_panel_section_key, tool_section = \ - tool_util.handle_tool_panel_section( trans, + tool_util.handle_tool_panel_section( app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) tool_shed_repository = \ - suc.create_or_update_tool_shed_repository( app=trans.app, + suc.create_or_update_tool_shed_repository( app=app, name=name, description=description, installed_changeset_revision=installed_changeset_revision, ctx_rev=ctx_rev, repository_clone_url=repository_clone_url, metadata_dict={}, - status=trans.install_model.ToolShedRepository.installation_status.NEW, + status=install_model.ToolShedRepository.installation_status.NEW, current_changeset_revision=changeset_revision, owner=repository_owner, dist_to_shed=False ) @@ -222,7 +224,7 @@ tool_panel_section_keys.append( tool_panel_section_key ) filtered_repo_info_dicts.append( repo_info_dict ) # Build repository dependency relationships even if the user chose to not install repository dependencies. - build_repository_dependency_relationships( trans, all_repo_info_dicts, all_created_or_updated_tool_shed_repositories ) + build_repository_dependency_relationships( app, all_repo_info_dicts, all_created_or_updated_tool_shed_repositories ) return created_or_updated_tool_shed_repositories, tool_panel_section_keys, all_repo_info_dicts, filtered_repo_info_dicts def generate_message_for_invalid_repository_dependencies( metadata_dict, error_from_tuple=False ): @@ -344,9 +346,9 @@ prior_installation_required, only_if_compiling_contained_td ) -def get_repository_dependency_by_repository_id( trans, decoded_repository_id ): - return trans.install_model.context.query( trans.install_model.RepositoryDependency ) \ - .filter( trans.install_model.RepositoryDependency.table.c.tool_shed_repository_id == decoded_repository_id ) \ +def get_repository_dependency_by_repository_id( install_model, decoded_repository_id ): + return install_model.context.query( install_model.RepositoryDependency ) \ + .filter( install_model.RepositoryDependency.table.c.tool_shed_repository_id == decoded_repository_id ) \ .first() def get_repository_dependencies_for_installed_tool_shed_repository( trans, repository ): diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/tool_shed/util/shed_util_common.py --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -571,27 +571,28 @@ continue return key -def get_or_create_tool_shed_repository( trans, tool_shed, name, owner, changeset_revision ): +def get_or_create_tool_shed_repository( app, tool_shed, name, owner, changeset_revision ): """ Return a tool shed repository database record defined by the combination of tool shed, repository name, repository owner and changeset_revision or installed_changeset_revision. A new tool shed repository record will be created if one is not located. """ + install_model = app.install_model # We store the port in the database. tool_shed = common_util.remove_protocol_from_tool_shed_url( tool_shed ) # This method is used only in Galaxy, not the tool shed. - repository = get_repository_for_dependency_relationship( trans.app, tool_shed, name, owner, changeset_revision ) + repository = get_repository_for_dependency_relationship( app, tool_shed, name, owner, changeset_revision ) if not repository: - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed ) repository_clone_url = os.path.join( tool_shed_url, 'repos', owner, name ) - ctx_rev = get_ctx_rev( trans.app, tool_shed_url, name, owner, changeset_revision ) - repository = create_or_update_tool_shed_repository( app=trans.app, + ctx_rev = get_ctx_rev( app, tool_shed_url, name, owner, changeset_revision ) + repository = create_or_update_tool_shed_repository( app=app, name=name, description=None, installed_changeset_revision=changeset_revision, ctx_rev=ctx_rev, repository_clone_url=repository_clone_url, metadata_dict={}, - status=trans.install_model.ToolShedRepository.installation_status.NEW, + status=install_model.ToolShedRepository.installation_status.NEW, current_changeset_revision=None, owner=owner, dist_to_shed=False ) @@ -616,7 +617,7 @@ sorted_changeset_revisions = [ str( changeset_tup[ 1 ] ) for changeset_tup in sorted_changeset_tups ] return sorted_changeset_revisions -def get_prior_import_or_install_required_dict( trans, tsr_ids, repo_info_dicts ): +def get_prior_import_or_install_required_dict( app, tsr_ids, repo_info_dicts ): """ This method is used in the Tool Shed when exporting a repository and its dependencies, and in Galaxy when a repository and its dependencies are being installed. Return a dictionary whose keys are the received tsr_ids and whose values are a list of tsr_ids, each of which is contained @@ -628,13 +629,13 @@ prior_import_or_install_required_dict[ tsr_id ] = [] # Inspect the repository dependencies for each repository about to be installed and populate the dictionary. for repo_info_dict in repo_info_dicts: - repository, repository_dependencies = get_repository_and_repository_dependencies_from_repo_info_dict( trans, repo_info_dict ) + repository, repository_dependencies = get_repository_and_repository_dependencies_from_repo_info_dict( app, repo_info_dict ) if repository: - encoded_repository_id = trans.security.encode_id( repository.id ) + encoded_repository_id = app.security.encode_id( repository.id ) if encoded_repository_id in tsr_ids: # We've located the database table record for one of the repositories we're about to install, so find out if it has any repository # dependencies that require prior installation. - prior_import_or_install_ids = get_repository_ids_requiring_prior_import_or_install( trans, tsr_ids, repository_dependencies ) + prior_import_or_install_ids = get_repository_ids_requiring_prior_import_or_install( app, tsr_ids, repository_dependencies ) prior_import_or_install_required_dict[ encoded_repository_id ] = prior_import_or_install_ids return prior_import_or_install_required_dict @@ -707,23 +708,24 @@ description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = repo_info_tuple return description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies -def get_repository_and_repository_dependencies_from_repo_info_dict( trans, repo_info_dict ): +def get_repository_and_repository_dependencies_from_repo_info_dict( app, repo_info_dict ): """Return a tool_shed_repository or repository record defined by the information in the received repo_info_dict.""" repository_name = repo_info_dict.keys()[ 0 ] repo_info_tuple = repo_info_dict[ repository_name ] description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = \ get_repo_info_tuple_contents( repo_info_tuple ) - if trans.webapp.name == 'galaxy': + if hasattr( app, "install_model" ): + # In a tool shed client (Galaxy, or something install repositories like Galaxy) tool_shed = get_tool_shed_from_clone_url( repository_clone_url ) - repository = get_repository_for_dependency_relationship( trans.app, tool_shed, repository_name, repository_owner, changeset_revision ) + repository = get_repository_for_dependency_relationship( app, tool_shed, repository_name, repository_owner, changeset_revision ) else: # We're in the tool shed. - repository = get_repository_by_name_and_owner( trans.app, repository_name, repository_owner ) + repository = get_repository_by_name_and_owner( app, repository_name, repository_owner ) return repository, repository_dependencies def get_repository_by_id( trans, id ): """Get a repository from the database via id.""" - if trans.webapp.name == 'galaxy': + if is_tool_shed_client( trans.app ): return trans.install_model.context.query( trans.install_model.ToolShedRepository ).get( trans.security.decode_id( id ) ) else: return trans.sa_session.query( trans.model.Repository ).get( trans.security.decode_id( id ) ) @@ -731,15 +733,12 @@ def get_repository_by_name( app, name ): """Get a repository from the database via name.""" repository_query = get_repository_query( app ) - if app.name == 'galaxy': - return repository_query.filter_by( name=name ).first() - else: - return repository_query.filter_by( name=name ).first() + return repository_query.filter_by( name=name ).first() def get_repository_by_name_and_owner( app, name, owner ): """Get a repository from the database via name and owner""" repository_query = get_repository_query( app ) - if app.name == 'galaxy': + if is_tool_shed_client( app ): return repository_query \ .filter( and_( app.install_model.ToolShedRepository.table.c.name == name, app.install_model.ToolShedRepository.table.c.owner == owner ) ) \ @@ -884,7 +883,7 @@ # This should never be reached - raise an exception? return v, None -def get_repository_ids_requiring_prior_import_or_install( trans, tsr_ids, repository_dependencies ): +def get_repository_ids_requiring_prior_import_or_install( app, tsr_ids, repository_dependencies ): """ This method is used in the Tool Shed when exporting a repository and its dependencies, and in Galaxy when a repository and its dependencies are being installed. Inspect the received repository_dependencies and determine if the encoded id of each required repository is in the received @@ -908,14 +907,14 @@ # dependency. if not asbool( only_if_compiling_contained_td ): if asbool( prior_installation_required ): - if trans.webapp.name == 'galaxy': + if is_tool_shed_client( app ): # We store the port, if one exists, in the database. tool_shed = common_util.remove_protocol_from_tool_shed_url( tool_shed ) - repository = get_repository_for_dependency_relationship( trans.app, tool_shed, name, owner, changeset_revision ) + repository = get_repository_for_dependency_relationship( app, tool_shed, name, owner, changeset_revision ) else: - repository = get_repository_by_name_and_owner( trans.app, name, owner ) + repository = get_repository_by_name_and_owner( app, name, owner ) if repository: - encoded_repository_id = trans.security.encode_id( repository.id ) + encoded_repository_id = app.security.encode_id( repository.id ) if encoded_repository_id in tsr_ids: prior_tsr_ids.append( encoded_repository_id ) return prior_tsr_ids @@ -963,7 +962,7 @@ return get_repository_owner( tmp_url ) def get_repository_query( app ): - if app.name == "galaxy": + if is_tool_shed_client( app ): query = app.install_model.context.query( app.install_model.ToolShedRepository ) else: query = app.model.context.query( app.model.Repository ) @@ -1326,6 +1325,16 @@ return True return False + +def is_tool_shed_client( app ): + """ The tool shed and clients to the tool (i.e. Galaxy) require a lot + of similar functionality in this file but with small differences. This + method should determine if the app performing the action is the tool shed + or a client of the tool shed. + """ + return hasattr( app, "install_model" ) + + def open_repository_files_folder( trans, folder_path ): """ Return a list of dictionaries, each of which contains information for a file or directory contained @@ -1352,7 +1361,7 @@ folder_contents.append( node ) return folder_contents -def repository_was_previously_installed( trans, tool_shed_url, repository_name, repo_info_tuple, from_tip=False ): +def repository_was_previously_installed( app, tool_shed_url, repository_name, repo_info_tuple, from_tip=False ): """ Find out if a repository is already installed into Galaxy - there are several scenarios where this is necessary. For example, this method will handle the case where the repository was previously @@ -1361,12 +1370,12 @@ updating the one that was previously installed. We'll look in the database instead of on disk since the repository may be currently uninstalled. """ - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed_url ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed_url ) description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = \ get_repo_info_tuple_contents( repo_info_tuple ) tool_shed = get_tool_shed_from_clone_url( repository_clone_url ) # See if we can locate the repository using the value of changeset_revision. - tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( trans.app, + tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( app, tool_shed, repository_name, repository_owner, @@ -1382,11 +1391,11 @@ str( from_tip ) ) url = common_util.url_join( tool_shed_url, 'repository/previous_changeset_revisions%s' % params ) - text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + text = common_util.tool_shed_get( app, tool_shed_url, url ) if text: changeset_revisions = util.listify( text ) for previous_changeset_revision in changeset_revisions: - tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( trans.app, + tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( app, tool_shed, repository_name, repository_owner, @@ -1395,7 +1404,7 @@ return tool_shed_repository, previous_changeset_revision return None, None -def reset_previously_installed_repository( trans, repository ): +def reset_previously_installed_repository( install_model, repository ): """ Reset the atrributes of a tool_shed_repository that was previsouly installed. The repository will be in some state other than INSTALLED, so all atributes will be set to the default NEW state. This will enable the repository to be freshly installed. @@ -1411,10 +1420,10 @@ repository.deleted = False repository.tool_shed_status = None repository.uninstalled = False - repository.status = trans.install_model.ToolShedRepository.installation_status.NEW + repository.status = install_model.ToolShedRepository.installation_status.NEW repository.error_message = None - trans.install_model.context.add( repository ) - trans.install_model.context.flush() + install_model.context.add( repository ) + install_model.context.flush() def set_image_paths( app, encoded_repository_id, text ): """ @@ -1423,7 +1432,7 @@ the caller to open the file. """ if text: - if app.name == 'galaxy': + if is_tool_shed_client( app ): route_to_images = 'admin_toolshed/static/images/%s' % encoded_repository_id else: # We're in the tool shed. diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/tool_shed/util/tool_dependency_util.py --- a/lib/tool_shed/util/tool_dependency_util.py +++ b/lib/tool_shed/util/tool_dependency_util.py @@ -617,7 +617,7 @@ tool_dependencies=tool_dependencies ) # The required_repository may have been installed with a different changeset revision. required_repository, installed_changeset_revision = \ - suc.repository_was_previously_installed( trans, tool_shed_url, name, repo_info_tuple, from_tip=False ) + suc.repository_was_previously_installed( trans.app, tool_shed_url, name, repo_info_tuple, from_tip=False ) if required_repository: required_repository_installed_tool_dependencies, required_repository_missing_tool_dependencies = \ get_installed_and_missing_tool_dependencies_for_installed_repository( trans, required_repository, tool_dependencies ) diff -r df20b99bc7db3d3daab5b843b73b6890c85fd390 -r d10fc2e9a14df16b47fa3df013971920399a55bd lib/tool_shed/util/tool_util.py --- a/lib/tool_shed/util/tool_util.py +++ b/lib/tool_shed/util/tool_util.py @@ -467,14 +467,14 @@ fh.close() return sample_files, deleted_sample_files -def get_or_create_tool_section( trans, tool_panel_section_id, new_tool_panel_section_label=None ): +def get_or_create_tool_section( toolbox, tool_panel_section_id, new_tool_panel_section_label=None ): tool_panel_section_key = str( tool_panel_section_id ) - if tool_panel_section_key in trans.app.toolbox.tool_panel: - # Appending a tool to an existing section in trans.app.toolbox.tool_panel - tool_section = trans.app.toolbox.tool_panel[ tool_panel_section_key ] + if tool_panel_section_key in toolbox.tool_panel: + # Appending a tool to an existing section in toolbox.tool_panel + tool_section = toolbox.tool_panel[ tool_panel_section_key ] log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) ) else: - # Appending a new section to trans.app.toolbox.tool_panel + # Appending a new section to toolbox.tool_panel if new_tool_panel_section_label is None: # This might add an ugly section label to the tool panel, but, oh well... new_tool_panel_section_label = tool_panel_section_id @@ -483,7 +483,7 @@ elem.attrib[ 'id' ] = tool_panel_section_id elem.attrib[ 'version' ] = '' tool_section = galaxy.tools.ToolSection( elem ) - trans.app.toolbox.tool_panel[ tool_panel_section_key ] = tool_section + toolbox.tool_panel[ tool_panel_section_key ] = tool_section log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) ) return tool_panel_section_key, tool_section @@ -669,7 +669,7 @@ error = True return error, message -def handle_tool_panel_selection( trans, metadata, no_changes_checked, tool_panel_section_id, new_tool_panel_section_label ): +def handle_tool_panel_selection( toolbox, metadata, no_changes_checked, tool_panel_section_id, new_tool_panel_section_label ): """ Handle the selected tool panel location for loading tools included in tool shed repositories when installing or reinstalling them. @@ -697,17 +697,17 @@ original_section_name = tool_section_dict[ 'name' ] if original_section_id: tool_panel_section_key, tool_section = \ - get_or_create_tool_section( trans, + get_or_create_tool_section( toolbox, tool_panel_section_id=original_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) else: # The user elected to change the tool panel section to contain the tools. - tool_panel_section_key, tool_section = handle_tool_panel_section( trans, + tool_panel_section_key, tool_section = handle_tool_panel_section( toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) return tool_section, tool_panel_section_key -def handle_tool_panel_section( trans, tool_panel_section_id=None, new_tool_panel_section_label=None ): +def handle_tool_panel_section( toolbox, tool_panel_section_id=None, new_tool_panel_section_label=None ): """Return a ToolSection object retrieved from the current in-memory tool_panel.""" # If tool_panel_section_id is received, the section exists in the tool panel. In this case, the value of the # received tool_panel_section_id must be the id retrieved from a tool panel config (e.g., tool_conf.xml, which @@ -715,12 +715,12 @@ if new_tool_panel_section_label: section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) ) tool_panel_section_key, tool_section = \ - get_or_create_tool_section( trans, + get_or_create_tool_section( toolbox, tool_panel_section_id=section_id, new_tool_panel_section_label=new_tool_panel_section_label ) elif tool_panel_section_id: tool_panel_section_key = str( tool_panel_section_id ) - tool_section = trans.app.toolbox.tool_panel[ tool_panel_section_key ] + tool_section = toolbox.tool_panel[ tool_panel_section_key ] else: return None, None return tool_panel_section_key, tool_section https://bitbucket.org/galaxy/galaxy-central/commits/910fb573480d/ Changeset: 910fb573480d User: jmchilton Date: 2014-06-09 16:13:39 Summary: Rework ToolShedRepositoriesController API controller to use newer API decorator. Affected #: 1 file diff -r d10fc2e9a14df16b47fa3df013971920399a55bd -r 910fb573480d3d07bc627554fb3dcbeb4d51dc98 lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -5,6 +5,7 @@ from galaxy import util from galaxy import web +from galaxy.web import _future_expose_api as expose_api from galaxy.util import json from galaxy.web.base.controller import BaseAPIController @@ -34,7 +35,7 @@ class ToolShedRepositoriesController( BaseAPIController ): """RESTful controller for interactions with tool shed repositories.""" - @web.expose_api + @expose_api def exported_workflows( self, trans, id, **kwd ): """ GET /api/tool_shed_repositories/{encoded_tool_shed_repository_id}/exported_workflows @@ -67,7 +68,7 @@ exported_workflows.append( display_dict ) return exported_workflows - @web.expose_api + @expose_api def get_latest_installable_revision( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/get_latest_installable_revision @@ -116,7 +117,7 @@ 'error_message' : tool_shed_repository.error_message or '' } return value_mapper - @web.expose_api + @expose_api def import_workflow( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/import_workflow @@ -149,7 +150,7 @@ return {} return workflow.to_dict( view='element' ) - @web.expose_api + @expose_api def import_workflows( self, trans, **kwd ): """ POST /api/tool_shed_repositories/import_workflows @@ -177,7 +178,7 @@ imported_workflow_dicts.append( workflow.to_dict( view='element' ) ) return imported_workflow_dicts - @web.expose_api + @expose_api def index( self, trans, **kwd ): """ GET /api/tool_shed_repositories @@ -195,7 +196,7 @@ tool_shed_repository_dicts.append( tool_shed_repository_dict ) return tool_shed_repository_dicts - @web.expose_api + @expose_api def install_repository_revision( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/install_repository_revision @@ -403,7 +404,7 @@ # Display the list of installed repositories. return installed_tool_shed_repositories - @web.expose_api + @expose_api def install_repository_revisions( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/install_repository_revisions @@ -487,7 +488,7 @@ all_installed_tool_shed_repositories.extend( installed_tool_shed_repositories ) return all_installed_tool_shed_repositories - @web.expose_api + @expose_api def repair_repository_revision( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/repair_repository_revision @@ -538,7 +539,7 @@ # Display the list of repaired repositories. return tool_shed_repositories - @web.expose_api + @expose_api def reset_metadata_on_installed_repositories( self, trans, payload, **kwd ): """ PUT /api/tool_shed_repositories/reset_metadata_on_installed_repositories @@ -581,7 +582,7 @@ results[ 'stop_time' ] = stop_time return json.to_json_string( results, sort_keys=True, indent=4 ) - @web.expose_api + @expose_api def show( self, trans, id, **kwd ): """ GET /api/tool_shed_repositories/{encoded_tool_shed_repsository_id} https://bitbucket.org/galaxy/galaxy-central/commits/3e230c53b46a/ Changeset: 3e230c53b46a User: jmchilton Date: 2014-06-09 16:13:40 Summary: Refactor common code out of tool shed repositories API... ... and rework suc.have_shed_tool_conf_for_install to not require trans. Affected #: 3 files diff -r 910fb573480d3d07bc627554fb3dcbeb4d51dc98 -r 3e230c53b46ae3efaa96bd0b20c88e5d81c0b139 lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -35,6 +35,16 @@ class ToolShedRepositoriesController( BaseAPIController ): """RESTful controller for interactions with tool shed repositories.""" + def __ensure_can_install_repos( self, trans ): + # Make sure this Galaxy instance is configured with a shed-related tool panel configuration file. + if not suc.have_shed_tool_conf_for_install( trans.app ): + message = get_message_for_no_shed_tool_config() + log.debug( message ) + return dict( status='error', error=message ) + # Make sure the current user's API key proves he is an admin user in this Galaxy instance. + if not trans.user_is_admin(): + raise HTTPForbidden( detail='You are not authorized to install a tool shed repository into this Galaxy instance.' ) + @expose_api def exported_workflows( self, trans, id, **kwd ): """ @@ -242,14 +252,7 @@ changeset_revision = payload.get( 'changeset_revision', '' ) if not changeset_revision: raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." ) - # Make sure this Galaxy instance is configured with a shed-related tool panel configuration file. - if not suc.have_shed_tool_conf_for_install( trans ): - message = get_message_for_no_shed_tool_config() - log.debug( message ) - return dict( status='error', error=message ) - # Make sure the current user's API key proves he is an admin user in this Galaxy instance. - if not trans.user_is_admin(): - raise HTTPForbidden( detail='You are not authorized to install a tool shed repository into this Galaxy instance.' ) + self.__ensure_can_install_repos( trans ) # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed. installed_tool_shed_repositories = [] # Get all of the information necessary for installing the repository from the specified tool shed. @@ -439,13 +442,7 @@ (e.g., <toolbox tool_path="../shed_tools">). If this parameter is not set, a shed-related tool panel configuration file will be selected automatically. """ - if not suc.have_shed_tool_conf_for_install( trans ): - # This Galaxy instance is not configured with a shed-related tool panel configuration file. - message = get_message_for_no_shed_tool_config() - log.debug( message ) - return dict( status='error', error=message ) - if not trans.user_is_admin(): - raise HTTPForbidden( detail='You are not authorized to install a tool shed repository into this Galaxy instance.' ) + self.__ensure_can_install_repos( trans ) # Get the information about all of the repositories to be installed. tool_shed_urls = util.listify( payload.get( 'tool_shed_urls', '' ) ) names = util.listify( payload.get( 'names', '' ) ) diff -r 910fb573480d3d07bc627554fb3dcbeb4d51dc98 -r 3e230c53b46ae3efaa96bd0b20c88e5d81c0b139 lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -948,7 +948,7 @@ @web.expose @web.require_admin def prepare_for_install( self, trans, **kwd ): - if not suc.have_shed_tool_conf_for_install( trans ): + if not suc.have_shed_tool_conf_for_install( trans.app ): message = 'The <b>tool_config_file</b> setting in <b>universe_wsgi.ini</b> must include at least one ' message += 'shed tool configuration file name with a <b><toolbox></b> tag that includes a <b>tool_path</b> ' message += 'attribute value which is a directory relative to the Galaxy installation directory in order ' diff -r 910fb573480d3d07bc627554fb3dcbeb4d51dc98 -r 3e230c53b46ae3efaa96bd0b20c88e5d81c0b139 lib/tool_shed/util/shed_util_common.py --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -1314,11 +1314,11 @@ except Exception, e: log.exception( "An error occurred sending a tool shed repository update alert by email." ) -def have_shed_tool_conf_for_install( trans ): - if not trans.app.toolbox.shed_tool_confs: +def have_shed_tool_conf_for_install( app ): + if not app.toolbox.shed_tool_confs: return False - migrated_tools_conf_path, migrated_tools_conf_name = os.path.split( trans.app.config.migrated_tools_config ) - for shed_tool_conf_dict in trans.app.toolbox.shed_tool_confs: + migrated_tools_conf_path, migrated_tools_conf_name = os.path.split( app.config.migrated_tools_config ) + for shed_tool_conf_dict in app.toolbox.shed_tool_confs: shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ] shed_tool_conf_path, shed_tool_conf_name = os.path.split( shed_tool_conf ) if shed_tool_conf_name != migrated_tools_conf_name: https://bitbucket.org/galaxy/galaxy-central/commits/98744666b64d/ Changeset: 98744666b64d User: jmchilton Date: 2014-06-09 16:13:40 Summary: Add AdminRequiredException to galaxy.exceptions. There was a INSUFFICIENT_PERMISSIONS error code - but that seems more for user-land sharable objects. Affected #: 3 files diff -r 3e230c53b46ae3efaa96bd0b20c88e5d81c0b139 -r 98744666b64d3f1a7eb698065c138302ec07c5fa lib/galaxy/exceptions/__init__.py --- a/lib/galaxy/exceptions/__init__.py +++ b/lib/galaxy/exceptions/__init__.py @@ -112,6 +112,11 @@ err_code = error_codes.INSUFFICIENT_PERMISSIONS +class AdminRequiredException( MessageException ): + status_code = 403 + err_code = error_codes.ADMIN_REQUIRED + + class ObjectNotFound( MessageException ): """ Accessed object was not found """ status_code = 404 diff -r 3e230c53b46ae3efaa96bd0b20c88e5d81c0b139 -r 98744666b64d3f1a7eb698065c138302ec07c5fa lib/galaxy/exceptions/error_codes.json --- a/lib/galaxy/exceptions/error_codes.json +++ b/lib/galaxy/exceptions/error_codes.json @@ -85,6 +85,11 @@ "message": "You don't have proper permissions to perform the requested operation" }, { + "name": "ADMIN_REQUIRED", + "code": 403006, + "message": "Action requires admin account." + }, + { "name": "USER_OBJECT_NOT_FOUND", "code": 404001, "message": "No such object found." diff -r 3e230c53b46ae3efaa96bd0b20c88e5d81c0b139 -r 98744666b64d3f1a7eb698065c138302ec07c5fa lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -5,6 +5,7 @@ from galaxy import util from galaxy import web +from galaxy import exceptions from galaxy.web import _future_expose_api as expose_api from galaxy.util import json from galaxy.web.base.controller import BaseAPIController @@ -43,7 +44,7 @@ return dict( status='error', error=message ) # Make sure the current user's API key proves he is an admin user in this Galaxy instance. if not trans.user_is_admin(): - raise HTTPForbidden( detail='You are not authorized to install a tool shed repository into this Galaxy instance.' ) + raise exceptions.AdminRequiredException( 'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) @expose_api def exported_workflows( self, trans, id, **kwd ): @@ -103,7 +104,7 @@ raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) # Make sure the current user's API key proves he is an admin user in this Galaxy instance. if not trans.user_is_admin(): - raise HTTPForbidden( detail='You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) + raise exceptions.AdminRequiredException( 'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) params = '?name=%s&owner=%s' % ( name, owner ) url = common_util.url_join( tool_shed_url, 'api/repositories/get_ordered_installable_revisions%s' % params ) https://bitbucket.org/galaxy/galaxy-central/commits/942c1e22e281/ Changeset: 942c1e22e281 User: jmchilton Date: 2014-06-09 16:13:40 Summary: Make helper function for some duplicated code in tool shed repositories API. Affected #: 1 file diff -r 98744666b64d3f1a7eb698065c138302ec07c5fa -r 942c1e22e281192bbacff3d7645cac34afae1acb lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -93,15 +93,7 @@ :param owner (required): the owner of the Repository """ # Get the information about the repository to be installed from the payload. - tool_shed_url = payload.get( 'tool_shed_url', '' ) - if not tool_shed_url: - raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." ) - name = payload.get( 'name', '' ) - if not name: - raise HTTPBadRequest( detail="Missing required parameter 'name'." ) - owner = payload.get( 'owner', '' ) - if not owner: - raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) + tool_shed_url, name, owner = self.__parse_repository_from_payload( payload ) # Make sure the current user's API key proves he is an admin user in this Galaxy instance. if not trans.user_is_admin(): raise exceptions.AdminRequiredException( 'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) @@ -241,18 +233,7 @@ file will be selected automatically. """ # Get the information about the repository to be installed from the payload. - tool_shed_url = payload.get( 'tool_shed_url', '' ) - if not tool_shed_url: - raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." ) - name = payload.get( 'name', '' ) - if not name: - raise HTTPBadRequest( detail="Missing required parameter 'name'." ) - owner = payload.get( 'owner', '' ) - if not owner: - raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) - changeset_revision = payload.get( 'changeset_revision', '' ) - if not changeset_revision: - raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." ) + tool_shed_url, name, owner, changeset_revision = self.__parse_repository_from_payload( payload, include_changeset=True ) self.__ensure_can_install_repos( trans ) # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed. installed_tool_shed_repositories = [] @@ -501,18 +482,7 @@ :param changeset_revision (required): the changeset_revision of the RepositoryMetadata object associated with the Repository """ # Get the information about the repository to be installed from the payload. - tool_shed_url = payload.get( 'tool_shed_url', '' ) - if not tool_shed_url: - raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." ) - name = payload.get( 'name', '' ) - if not name: - raise HTTPBadRequest( detail="Missing required parameter 'name'." ) - owner = payload.get( 'owner', '' ) - if not owner: - raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) - changeset_revision = payload.get( 'changeset_revision', '' ) - if not changeset_revision: - raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." ) + tool_shed_url, name, owner, changeset_revision = self.__parse_repository_from_payload( payload, include_changeset=True ) tool_shed_repositories = [] tool_shed_repository = suc.get_tool_shed_repository_by_shed_name_owner_changeset_revision( trans.app, tool_shed_url, name, owner, changeset_revision ) repair_dict = repository_util.get_repair_dict( trans, tool_shed_repository ) @@ -537,6 +507,26 @@ # Display the list of repaired repositories. return tool_shed_repositories + def __parse_repository_from_payload( self, payload, include_changeset=False ): + # Get the information about the repository to be installed from the payload. + tool_shed_url = payload.get( 'tool_shed_url', '' ) + if not tool_shed_url: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'tool_shed_url'." ) + name = payload.get( 'name', '' ) + if not name: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'name'." ) + owner = payload.get( 'owner', '' ) + if not owner: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'owner'." ) + if not include_changeset: + return tool_shed_url, name, owner + + changeset_revision = payload.get( 'changeset_revision', '' ) + if not changeset_revision: + raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." ) + + return tool_shed_url, name, owner, changeset_revision + @expose_api def reset_metadata_on_installed_repositories( self, trans, payload, **kwd ): """ https://bitbucket.org/galaxy/galaxy-central/commits/cb788366ddb1/ Changeset: cb788366ddb1 User: jmchilton Date: 2014-06-09 16:13:40 Summary: Improved exception handling when installing repositories on tool shed comm errors. Now 5XX status will be set. More specific errors else where as well. Affected #: 1 file diff -r 942c1e22e281192bbacff3d7645cac34afae1acb -r cb788366ddb10b3cf537653af6fb86effad811fd lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -246,8 +246,8 @@ except Exception, e: message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.debug( message ) - return dict( status='error', error=message ) + log.warn( message ) + raise exceptions.InternalServerError( message ) if raw_text: # If successful, the response from get_repository_revision_install_info will be 3 # dictionaries, a dictionary defining the Repository, a dictionary defining the @@ -259,8 +259,8 @@ else: message = "Unable to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.debug( message ) - return dict( status='error', error=message ) + log.warn( message ) + raise exceptions.InternalServerError( message ) # Make sure the tool shed returned everything we need for installing the repository. if not repository_revision_dict or not repo_info_dict: key = kwd.get( 'key', None ) @@ -271,24 +271,24 @@ invalid_parameter_message += "name: %s\n" % str( name ) invalid_parameter_message += "owner: %s\n" % str( owner ) invalid_parameter_message += "changeset_revision: %s\n" % str( changeset_revision ) - raise HTTPBadRequest( detail=invalid_parameter_message ) + raise exceptions.RequestParameterInvalidException( invalid_parameter_message ) repo_info_dicts = [ repo_info_dict ] try: has_repository_dependencies = repository_revision_dict[ 'has_repository_dependencies' ] except: - raise HTTPBadRequest( detail="Missing required parameter 'has_repository_dependencies'." ) + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'has_repository_dependencies'." ) try: includes_tools = repository_revision_dict[ 'includes_tools' ] except: - raise HTTPBadRequest( detail="Missing required parameter 'includes_tools'." ) + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools'." ) try: includes_tool_dependencies = repository_revision_dict[ 'includes_tool_dependencies' ] except: - raise HTTPBadRequest( detail="Missing required parameter 'includes_tool_dependencies'." ) + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tool_dependencies'." ) try: includes_tools_for_display_in_tool_panel = repository_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] except: - raise HTTPBadRequest( detail="Missing required parameter 'includes_tools_for_display_in_tool_panel'." ) + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools_for_display_in_tool_panel'." ) # Get the information about the Galaxy components (e.g., tool pane section, tool config file, etc) that will contain the repository information. install_repository_dependencies = payload.get( 'install_repository_dependencies', False ) install_tool_dependencies = payload.get( 'install_tool_dependencies', False ) @@ -296,7 +296,7 @@ if trans.app.config.tool_dependency_dir is None: no_tool_dependency_dir_message = "Tool dependencies can be automatically installed only if you set the value of your 'tool_dependency_dir' " no_tool_dependency_dir_message += "setting in your Galaxy configuration file (universe_wsgi.ini) and restart your Galaxy server." - raise HTTPBadRequest( detail=no_tool_dependency_dir_message ) + raise exceptions.ConfigDoesNotAllowException( no_tool_dependency_dir_message ) new_tool_panel_section_label = payload.get( 'new_tool_panel_section_label', '' ) shed_tool_conf = payload.get( 'shed_tool_conf', None ) if shed_tool_conf: @@ -385,7 +385,7 @@ installed_tool_shed_repositories.append( tool_shed_repository_dict ) else: # We're attempting to install more than 1 repository, and all of them have already been installed. - return dict( status='error', error='All repositories that you are attempting to install have been previously installed.' ) + raise exceptions.RequestParameterInvalidException( 'All repositories that you are attempting to install have been previously installed.' ) # Display the list of installed repositories. return installed_tool_shed_repositories https://bitbucket.org/galaxy/galaxy-central/commits/3d70026148d7/ Changeset: 3d70026148d7 User: jmchilton Date: 2014-06-09 16:13:40 Summary: Break-up big function install_repository_revision in tool_shed_repositories API. Affected #: 1 file diff -r cb788366ddb10b3cf537653af6fb86effad811fd -r 3d70026148d7e5c60eb02e5556f45f138ee3893f lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -238,41 +238,7 @@ # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed. installed_tool_shed_repositories = [] # Get all of the information necessary for installing the repository from the specified tool shed. - params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) - url = common_util.url_join( tool_shed_url, - 'api/repositories/get_repository_revision_install_info%s' % params ) - try: - raw_text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) - except Exception, e: - message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ - ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.warn( message ) - raise exceptions.InternalServerError( message ) - if raw_text: - # If successful, the response from get_repository_revision_install_info will be 3 - # dictionaries, a dictionary defining the Repository, a dictionary defining the - # Repository revision (RepositoryMetadata), and a dictionary including the additional - # information required to install the repository. - items = json.from_json_string( raw_text ) - repository_revision_dict = items[ 1 ] - repo_info_dict = items[ 2 ] - else: - message = "Unable to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ - ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.warn( message ) - raise exceptions.InternalServerError( message ) - # Make sure the tool shed returned everything we need for installing the repository. - if not repository_revision_dict or not repo_info_dict: - key = kwd.get( 'key', None ) - invalid_parameter_message = "No information is available for the requested repository revision.\n" - invalid_parameter_message += "One or more of the following parameter values is likely invalid:\n" - invalid_parameter_message += "key: %s\n" % str( key ) - invalid_parameter_message += "tool_shed_url: %s\n" % str( tool_shed_url ) - invalid_parameter_message += "name: %s\n" % str( name ) - invalid_parameter_message += "owner: %s\n" % str( owner ) - invalid_parameter_message += "changeset_revision: %s\n" % str( changeset_revision ) - raise exceptions.RequestParameterInvalidException( invalid_parameter_message ) - repo_info_dicts = [ repo_info_dict ] + repository_revision_dict, repo_info_dicts = self.__get_install_info_from_tool_shed( trans.app, tool_shed_url, name, owner, changeset_revision ) try: has_repository_dependencies = repository_revision_dict[ 'has_repository_dependencies' ] except: @@ -389,6 +355,42 @@ # Display the list of installed repositories. return installed_tool_shed_repositories + def __get_install_info_from_tool_shed( self, app, tool_shed_url, name, owner, changeset_revision ): + params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) + url = common_util.url_join( tool_shed_url, + 'api/repositories/get_repository_revision_install_info%s' % params ) + try: + raw_text = common_util.tool_shed_get( app, tool_shed_url, url ) + except Exception, e: + message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ + ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) + log.warn( message ) + raise exceptions.InternalServerError( message ) + if raw_text: + # If successful, the response from get_repository_revision_install_info will be 3 + # dictionaries, a dictionary defining the Repository, a dictionary defining the + # Repository revision (RepositoryMetadata), and a dictionary including the additional + # information required to install the repository. + items = json.from_json_string( raw_text ) + repository_revision_dict = items[ 1 ] + repo_info_dict = items[ 2 ] + else: + message = "Unable to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ + ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) + log.warn( message ) + raise exceptions.InternalServerError( message ) + # Make sure the tool shed returned everything we need for installing the repository. + if not repository_revision_dict or not repo_info_dict: + invalid_parameter_message = "No information is available for the requested repository revision.\n" + invalid_parameter_message += "One or more of the following parameter values is likely invalid:\n" + invalid_parameter_message += "tool_shed_url: %s\n" % str( tool_shed_url ) + invalid_parameter_message += "name: %s\n" % str( name ) + invalid_parameter_message += "owner: %s\n" % str( owner ) + invalid_parameter_message += "changeset_revision: %s\n" % str( changeset_revision ) + raise exceptions.RequestParameterInvalidException( invalid_parameter_message ) + repo_info_dicts = [ repo_info_dict ] + return repository_revision_dict, repo_info_dicts + @expose_api def install_repository_revisions( self, trans, payload, **kwd ): """ https://bitbucket.org/galaxy/galaxy-central/commits/e28e0157c6e6/ Changeset: e28e0157c6e6 User: jmchilton Date: 2014-06-09 16:13:40 Summary: Refactor install_repository_revision - move all API formatting logic to end of function. Affected #: 1 file diff -r 3d70026148d7e5c60eb02e5556f45f138ee3893f -r e28e0157c6e6337def3abb268622cfea8438a59d lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -344,16 +344,19 @@ tool_path, install_tool_dependencies, reinstalling=False ) - 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 ) ) - installed_tool_shed_repositories.append( tool_shed_repository_dict ) + installed_tool_shed_repositories.append( tool_shed_repository ) else: # We're attempting to install more than 1 repository, and all of them have already been installed. raise exceptions.RequestParameterInvalidException( 'All repositories that you are attempting to install have been previously installed.' ) # Display the list of installed repositories. - return installed_tool_shed_repositories + + 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 + return map( to_dict, installed_tool_shed_repositories ) def __get_install_info_from_tool_shed( self, app, tool_shed_url, name, owner, changeset_revision ): params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) https://bitbucket.org/galaxy/galaxy-central/commits/e734520631f2/ Changeset: e734520631f2 User: jmchilton Date: 2014-06-09 16:13:40 Summary: Refactor code actually orchistrating installs out of high-level API action. Affected #: 2 files diff -r e28e0157c6e6337def3abb268622cfea8438a59d -r e734520631f2553c211ae7c9a12df7ac3b0adf42 lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -235,120 +235,7 @@ # 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 ) - # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed. - installed_tool_shed_repositories = [] - # Get all of the information necessary for installing the repository from the specified tool shed. - repository_revision_dict, repo_info_dicts = self.__get_install_info_from_tool_shed( trans.app, tool_shed_url, name, owner, changeset_revision ) - try: - has_repository_dependencies = repository_revision_dict[ 'has_repository_dependencies' ] - except: - raise exceptions.InternalServerError( "Tool shed response missing required parameter 'has_repository_dependencies'." ) - try: - includes_tools = repository_revision_dict[ 'includes_tools' ] - except: - raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools'." ) - try: - includes_tool_dependencies = repository_revision_dict[ 'includes_tool_dependencies' ] - except: - raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tool_dependencies'." ) - try: - includes_tools_for_display_in_tool_panel = repository_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] - except: - raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools_for_display_in_tool_panel'." ) - # Get the information about the Galaxy components (e.g., tool pane section, tool config file, etc) that will contain the repository information. - install_repository_dependencies = payload.get( 'install_repository_dependencies', False ) - install_tool_dependencies = payload.get( 'install_tool_dependencies', False ) - if install_tool_dependencies: - if trans.app.config.tool_dependency_dir is None: - no_tool_dependency_dir_message = "Tool dependencies can be automatically installed only if you set the value of your 'tool_dependency_dir' " - no_tool_dependency_dir_message += "setting in your Galaxy configuration file (universe_wsgi.ini) and restart your Galaxy server." - raise exceptions.ConfigDoesNotAllowException( no_tool_dependency_dir_message ) - new_tool_panel_section_label = payload.get( 'new_tool_panel_section_label', '' ) - shed_tool_conf = payload.get( 'shed_tool_conf', None ) - if shed_tool_conf: - # Get the tool_path setting. - index, shed_conf_dict = suc.get_shed_tool_conf_dict( trans.app, shed_tool_conf ) - tool_path = shed_conf_dict[ 'tool_path' ] - else: - # Pick a semi-random shed-related tool panel configuration file and get the tool_path setting. - for shed_config_dict in trans.app.toolbox.shed_tool_confs: - # Don't use migrated_tools_conf.xml. - if shed_config_dict[ 'config_filename' ] != trans.app.config.migrated_tools_config: - break - shed_tool_conf = shed_config_dict[ 'config_filename' ] - tool_path = shed_config_dict[ 'tool_path' ] - if not shed_tool_conf: - raise HTTPBadRequest( detail="Missing required parameter 'shed_tool_conf'." ) - tool_panel_section_id = payload.get( 'tool_panel_section_id', '' ) - if tool_panel_section_id not in [ None, '' ]: - if tool_panel_section_id not in trans.app.toolbox.tool_panel: - fixed_tool_panel_section_id = 'section_%s' % tool_panel_section_id - if fixed_tool_panel_section_id in trans.app.toolbox.tool_panel: - tool_panel_section_id = fixed_tool_panel_section_id - else: - tool_panel_section_id = '' - else: - tool_panel_section_id = '' - # Build the dictionary of information necessary for creating tool_shed_repository database records for each repository being installed. - 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 ) - # Create the tool_shed_repository database records and gather additional information for repository installation. - created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_util.handle_tool_shed_repositories( trans.app, installation_dict, using_api=True ) - if created_or_updated_tool_shed_repositories: - # Build the dictionary of information necessary for installing the repositories. - installation_dict = dict( created_or_updated_tool_shed_repositories=created_or_updated_tool_shed_repositories, - filtered_repo_info_dicts=filtered_repo_info_dicts, - 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, - shed_tool_conf=shed_tool_conf, - status='done', - tool_panel_section_id=tool_panel_section_id, - tool_panel_section_keys=tool_panel_section_keys, - tool_path=tool_path, - tool_shed_url=tool_shed_url ) - # Prepare the repositories for installation. Even though this method receives a single combination of tool_shed_url, name, owner and - # changeset_revision, there may be multiple repositories for installation at this point because repository dependencies may have added - # additional repositories for installation along with the single specified repository. - encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ - repository_util.initiate_repository_installation( trans.app, installation_dict ) - # Some repositories may have repository dependencies that are required to be installed before the dependent repository, so we'll - # order the list of tsr_ids to ensure all repositories install in the required order. - tsr_ids = [ trans.security.encode_id( tool_shed_repository.id ) for tool_shed_repository in tool_shed_repositories ] - ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ - repository_util.order_components_for_installation( trans.app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) - # Install the repositories, keeping track of each one for later display. - for index, tsr_id in enumerate( ordered_tsr_ids ): - tool_shed_repository = trans.install_model.context.query( trans.install_model.ToolShedRepository ).get( trans.security.decode_id( tsr_id ) ) - if tool_shed_repository.status in [ trans.install_model.ToolShedRepository.installation_status.NEW, - trans.install_model.ToolShedRepository.installation_status.UNINSTALLED ]: - - repo_info_dict = ordered_repo_info_dicts[ index ] - tool_panel_section_key = ordered_tool_panel_section_keys[ index ] - repository_util.install_tool_shed_repository( trans.app, - tool_shed_repository, - repo_info_dict, - tool_panel_section_key, - shed_tool_conf, - tool_path, - install_tool_dependencies, - reinstalling=False ) - installed_tool_shed_repositories.append( tool_shed_repository ) - else: - # We're attempting to install more than 1 repository, and all of them have already been installed. - raise exceptions.RequestParameterInvalidException( 'All repositories that you are attempting to install have been previously installed.' ) - # Display the list of installed repositories. + installed_tool_shed_repositories = repository_util.install( trans.app, 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 ) ) @@ -356,44 +243,9 @@ action='show', id=trans.security.encode_id( tool_shed_repository.id ) ) return tool_shed_repository_dict + return map( to_dict, installed_tool_shed_repositories ) - def __get_install_info_from_tool_shed( self, app, tool_shed_url, name, owner, changeset_revision ): - params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) - url = common_util.url_join( tool_shed_url, - 'api/repositories/get_repository_revision_install_info%s' % params ) - try: - raw_text = common_util.tool_shed_get( app, tool_shed_url, url ) - except Exception, e: - message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ - ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.warn( message ) - raise exceptions.InternalServerError( message ) - if raw_text: - # If successful, the response from get_repository_revision_install_info will be 3 - # dictionaries, a dictionary defining the Repository, a dictionary defining the - # Repository revision (RepositoryMetadata), and a dictionary including the additional - # information required to install the repository. - items = json.from_json_string( raw_text ) - repository_revision_dict = items[ 1 ] - repo_info_dict = items[ 2 ] - else: - message = "Unable to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ - ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.warn( message ) - raise exceptions.InternalServerError( message ) - # Make sure the tool shed returned everything we need for installing the repository. - if not repository_revision_dict or not repo_info_dict: - invalid_parameter_message = "No information is available for the requested repository revision.\n" - invalid_parameter_message += "One or more of the following parameter values is likely invalid:\n" - invalid_parameter_message += "tool_shed_url: %s\n" % str( tool_shed_url ) - invalid_parameter_message += "name: %s\n" % str( name ) - invalid_parameter_message += "owner: %s\n" % str( owner ) - invalid_parameter_message += "changeset_revision: %s\n" % str( changeset_revision ) - raise exceptions.RequestParameterInvalidException( invalid_parameter_message ) - repo_info_dicts = [ repo_info_dict ] - return repository_revision_dict, repo_info_dicts - @expose_api def install_repository_revisions( self, trans, payload, **kwd ): """ diff -r e28e0157c6e6337def3abb268622cfea8438a59d -r e734520631f2553c211ae7c9a12df7ac3b0adf42 lib/tool_shed/galaxy_install/repository_util.py --- a/lib/tool_shed/galaxy_install/repository_util.py +++ b/lib/tool_shed/galaxy_install/repository_util.py @@ -3,6 +3,7 @@ import shutil import tempfile import threading +from galaxy import exceptions from galaxy import tools from galaxy.util import json from galaxy import util @@ -546,6 +547,167 @@ query = install_model.context.query( install_model.ToolShedRepository ).filter( or_( *clause_list ) ) return encoded_kwd, query, tool_shed_repositories, encoded_repository_ids + +def install( app, tool_shed_url, name, owner, changeset_revision, install_options ): + # Get all of the information necessary for installing the repository from the specified tool shed. + repository_revision_dict, repo_info_dicts = __get_install_info_from_tool_shed( app, tool_shed_url, name, owner, changeset_revision ) + installed_tool_shed_repositories = __install_repositories( app, repository_revision_dict, repo_info_dicts, install_options ) + return installed_tool_shed_repositories + + +def __install_repositories( self, app, tool_shed_url, repository_revision_dict, repo_info_dicts, install_options ): + # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed. + installed_tool_shed_repositories = [] + try: + has_repository_dependencies = repository_revision_dict[ 'has_repository_dependencies' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'has_repository_dependencies'." ) + try: + includes_tools = repository_revision_dict[ 'includes_tools' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools'." ) + try: + includes_tool_dependencies = repository_revision_dict[ 'includes_tool_dependencies' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tool_dependencies'." ) + try: + includes_tools_for_display_in_tool_panel = repository_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools_for_display_in_tool_panel'." ) + # Get the information about the Galaxy components (e.g., tool pane section, tool config file, etc) that will contain the repository information. + install_repository_dependencies = install_options.get( 'install_repository_dependencies', False ) + install_tool_dependencies = install_options.get( 'install_tool_dependencies', False ) + if install_tool_dependencies: + if app.config.tool_dependency_dir is None: + no_tool_dependency_dir_message = "Tool dependencies can be automatically installed only if you set the value of your 'tool_dependency_dir' " + no_tool_dependency_dir_message += "setting in your Galaxy configuration file (universe_wsgi.ini) and restart your Galaxy server." + raise exceptions.ConfigDoesNotAllowException( no_tool_dependency_dir_message ) + new_tool_panel_section_label = install_options.get( 'new_tool_panel_section_label', '' ) + shed_tool_conf = install_options.get( 'shed_tool_conf', None ) + if shed_tool_conf: + # Get the tool_path setting. + index, shed_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf ) + tool_path = shed_conf_dict[ 'tool_path' ] + else: + # Pick a semi-random shed-related tool panel configuration file and get the tool_path setting. + for shed_config_dict in app.toolbox.shed_tool_confs: + # Don't use migrated_tools_conf.xml. + if shed_config_dict[ 'config_filename' ] != app.config.migrated_tools_config: + break + shed_tool_conf = shed_config_dict[ 'config_filename' ] + tool_path = shed_config_dict[ 'tool_path' ] + if not shed_tool_conf: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'shed_tool_conf'." ) + tool_panel_section_id = install_options.get( 'tool_panel_section_id', '' ) + if tool_panel_section_id not in [ None, '' ]: + if tool_panel_section_id not in app.toolbox.tool_panel: + fixed_tool_panel_section_id = 'section_%s' % tool_panel_section_id + if fixed_tool_panel_section_id in app.toolbox.tool_panel: + tool_panel_section_id = fixed_tool_panel_section_id + else: + tool_panel_section_id = '' + else: + tool_panel_section_id = '' + # Build the dictionary of information necessary for creating tool_shed_repository database records for each repository being installed. + 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 ) + # Create the tool_shed_repository database records and gather additional information for repository installation. + created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ + handle_tool_shed_repositories( app, installation_dict, using_api=True ) + if created_or_updated_tool_shed_repositories: + # Build the dictionary of information necessary for installing the repositories. + installation_dict = dict( created_or_updated_tool_shed_repositories=created_or_updated_tool_shed_repositories, + filtered_repo_info_dicts=filtered_repo_info_dicts, + 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, + shed_tool_conf=shed_tool_conf, + status='done', + tool_panel_section_id=tool_panel_section_id, + tool_panel_section_keys=tool_panel_section_keys, + tool_path=tool_path, + tool_shed_url=tool_shed_url ) + # Prepare the repositories for installation. Even though this method receives a single combination of tool_shed_url, name, owner and + # changeset_revision, there may be multiple repositories for installation at this point because repository dependencies may have added + # additional repositories for installation along with the single specified repository. + encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ + initiate_repository_installation( app, installation_dict ) + # Some repositories may have repository dependencies that are required to be installed before the dependent repository, so we'll + # order the list of tsr_ids to ensure all repositories install in the required order. + tsr_ids = [ app.security.encode_id( tool_shed_repository.id ) for tool_shed_repository in tool_shed_repositories ] + ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ + order_components_for_installation( app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) + # Install the repositories, keeping track of each one for later display. + for index, tsr_id in enumerate( ordered_tsr_ids ): + install_model = app.install_model + tool_shed_repository = install_model.context.query( install_model.ToolShedRepository ).get( app.security.decode_id( tsr_id ) ) + if tool_shed_repository.status in [ install_model.ToolShedRepository.installation_status.NEW, + install_model.ToolShedRepository.installation_status.UNINSTALLED ]: + + repo_info_dict = ordered_repo_info_dicts[ index ] + tool_panel_section_key = ordered_tool_panel_section_keys[ index ] + install_tool_shed_repository( app, + tool_shed_repository, + repo_info_dict, + tool_panel_section_key, + shed_tool_conf, + tool_path, + install_tool_dependencies, + reinstalling=False ) + installed_tool_shed_repositories.append( tool_shed_repository ) + else: + # We're attempting to install more than 1 repository, and all of them have already been installed. + raise exceptions.RequestParameterInvalidException( 'All repositories that you are attempting to install have been previously installed.' ) + return installed_tool_shed_repositories + + +def __get_install_info_from_tool_shed( self, app, tool_shed_url, name, owner, changeset_revision ): + params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) + url = common_util.url_join( tool_shed_url, + 'api/repositories/get_repository_revision_install_info%s' % params ) + try: + raw_text = common_util.tool_shed_get( app, tool_shed_url, url ) + except Exception, e: + message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ + ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) + log.warn( message ) + raise exceptions.InternalServerError( message ) + if raw_text: + # If successful, the response from get_repository_revision_install_info will be 3 + # dictionaries, a dictionary defining the Repository, a dictionary defining the + # Repository revision (RepositoryMetadata), and a dictionary including the additional + # information required to install the repository. + items = json.from_json_string( raw_text ) + repository_revision_dict = items[ 1 ] + repo_info_dict = items[ 2 ] + else: + message = "Unable to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ + ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) + log.warn( message ) + raise exceptions.InternalServerError( message ) + # Make sure the tool shed returned everything we need for installing the repository. + if not repository_revision_dict or not repo_info_dict: + invalid_parameter_message = "No information is available for the requested repository revision.\n" + invalid_parameter_message += "One or more of the following parameter values is likely invalid:\n" + invalid_parameter_message += "tool_shed_url: %s\n" % str( tool_shed_url ) + invalid_parameter_message += "name: %s\n" % str( name ) + invalid_parameter_message += "owner: %s\n" % str( owner ) + invalid_parameter_message += "changeset_revision: %s\n" % str( changeset_revision ) + raise exceptions.RequestParameterInvalidException( invalid_parameter_message ) + repo_info_dicts = [ repo_info_dict ] + return repository_revision_dict, repo_info_dicts + + def install_tool_shed_repository( app, tool_shed_repository, repo_info_dict, tool_panel_section_key, shed_tool_conf, tool_path, install_tool_dependencies, reinstalling=False ): install_model = app.install_model https://bitbucket.org/galaxy/galaxy-central/commits/5884328e9172/ Changeset: 5884328e9172 User: jmchilton Date: 2014-06-09 18:01:47 Summary: Merged in jmchilton/galaxy-central-fork-1 (pull request #405) Tool shed refactoring toward use outside Galaxy app. Affected #: 11 files diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/galaxy/exceptions/__init__.py --- a/lib/galaxy/exceptions/__init__.py +++ b/lib/galaxy/exceptions/__init__.py @@ -112,6 +112,11 @@ err_code = error_codes.INSUFFICIENT_PERMISSIONS +class AdminRequiredException( MessageException ): + status_code = 403 + err_code = error_codes.ADMIN_REQUIRED + + class ObjectNotFound( MessageException ): """ Accessed object was not found """ status_code = 404 diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/galaxy/exceptions/error_codes.json --- a/lib/galaxy/exceptions/error_codes.json +++ b/lib/galaxy/exceptions/error_codes.json @@ -85,6 +85,11 @@ "message": "You don't have proper permissions to perform the requested operation" }, { + "name": "ADMIN_REQUIRED", + "code": 403006, + "message": "Action requires admin account." + }, + { "name": "USER_OBJECT_NOT_FOUND", "code": 404001, "message": "No such object found." diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -5,6 +5,8 @@ from galaxy import util from galaxy import web +from galaxy import exceptions +from galaxy.web import _future_expose_api as expose_api from galaxy.util import json from galaxy.web.base.controller import BaseAPIController @@ -34,7 +36,17 @@ class ToolShedRepositoriesController( BaseAPIController ): """RESTful controller for interactions with tool shed repositories.""" - @web.expose_api + def __ensure_can_install_repos( self, trans ): + # Make sure this Galaxy instance is configured with a shed-related tool panel configuration file. + if not suc.have_shed_tool_conf_for_install( trans.app ): + message = get_message_for_no_shed_tool_config() + log.debug( message ) + return dict( status='error', error=message ) + # Make sure the current user's API key proves he is an admin user in this Galaxy instance. + if not trans.user_is_admin(): + raise exceptions.AdminRequiredException( 'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) + + @expose_api def exported_workflows( self, trans, id, **kwd ): """ GET /api/tool_shed_repositories/{encoded_tool_shed_repository_id}/exported_workflows @@ -67,7 +79,7 @@ exported_workflows.append( display_dict ) return exported_workflows - @web.expose_api + @expose_api def get_latest_installable_revision( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/get_latest_installable_revision @@ -81,18 +93,10 @@ :param owner (required): the owner of the Repository """ # Get the information about the repository to be installed from the payload. - tool_shed_url = payload.get( 'tool_shed_url', '' ) - if not tool_shed_url: - raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." ) - name = payload.get( 'name', '' ) - if not name: - raise HTTPBadRequest( detail="Missing required parameter 'name'." ) - owner = payload.get( 'owner', '' ) - if not owner: - raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) + tool_shed_url, name, owner = self.__parse_repository_from_payload( payload ) # Make sure the current user's API key proves he is an admin user in this Galaxy instance. if not trans.user_is_admin(): - raise HTTPForbidden( detail='You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) + raise exceptions.AdminRequiredException( 'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) params = '?name=%s&owner=%s' % ( name, owner ) url = common_util.url_join( tool_shed_url, 'api/repositories/get_ordered_installable_revisions%s' % params ) @@ -116,7 +120,7 @@ 'error_message' : tool_shed_repository.error_message or '' } return value_mapper - @web.expose_api + @expose_api def import_workflow( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/import_workflow @@ -149,7 +153,7 @@ return {} return workflow.to_dict( view='element' ) - @web.expose_api + @expose_api def import_workflows( self, trans, **kwd ): """ POST /api/tool_shed_repositories/import_workflows @@ -177,7 +181,7 @@ imported_workflow_dicts.append( workflow.to_dict( view='element' ) ) return imported_workflow_dicts - @web.expose_api + @expose_api def index( self, trans, **kwd ): """ GET /api/tool_shed_repositories @@ -195,7 +199,7 @@ tool_shed_repository_dicts.append( tool_shed_repository_dict ) return tool_shed_repository_dicts - @web.expose_api + @expose_api def install_repository_revision( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/install_repository_revision @@ -229,181 +233,20 @@ file will be selected automatically. """ # Get the information about the repository to be installed from the payload. - tool_shed_url = payload.get( 'tool_shed_url', '' ) - if not tool_shed_url: - raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." ) - name = payload.get( 'name', '' ) - if not name: - raise HTTPBadRequest( detail="Missing required parameter 'name'." ) - owner = payload.get( 'owner', '' ) - if not owner: - raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) - changeset_revision = payload.get( 'changeset_revision', '' ) - if not changeset_revision: - raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." ) - # Make sure this Galaxy instance is configured with a shed-related tool panel configuration file. - if not suc.have_shed_tool_conf_for_install( trans ): - message = get_message_for_no_shed_tool_config() - log.debug( message ) - return dict( status='error', error=message ) - # Make sure the current user's API key proves he is an admin user in this Galaxy instance. - if not trans.user_is_admin(): - raise HTTPForbidden( detail='You are not authorized to install a tool shed repository into this Galaxy instance.' ) - # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed. - installed_tool_shed_repositories = [] - # Get all of the information necessary for installing the repository from the specified tool shed. - params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) - url = common_util.url_join( tool_shed_url, - 'api/repositories/get_repository_revision_install_info%s' % params ) - try: - raw_text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) - except Exception, e: - message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ - ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.debug( message ) - return dict( status='error', error=message ) - if raw_text: - # If successful, the response from get_repository_revision_install_info will be 3 - # dictionaries, a dictionary defining the Repository, a dictionary defining the - # Repository revision (RepositoryMetadata), and a dictionary including the additional - # information required to install the repository. - items = json.from_json_string( raw_text ) - repository_revision_dict = items[ 1 ] - repo_info_dict = items[ 2 ] - else: - message = "Unable to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ - ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) - log.debug( message ) - return dict( status='error', error=message ) - # Make sure the tool shed returned everything we need for installing the repository. - if not repository_revision_dict or not repo_info_dict: - key = kwd.get( 'key', None ) - invalid_parameter_message = "No information is available for the requested repository revision.\n" - invalid_parameter_message += "One or more of the following parameter values is likely invalid:\n" - invalid_parameter_message += "key: %s\n" % str( key ) - invalid_parameter_message += "tool_shed_url: %s\n" % str( tool_shed_url ) - invalid_parameter_message += "name: %s\n" % str( name ) - invalid_parameter_message += "owner: %s\n" % str( owner ) - invalid_parameter_message += "changeset_revision: %s\n" % str( changeset_revision ) - raise HTTPBadRequest( detail=invalid_parameter_message ) - repo_info_dicts = [ repo_info_dict ] - try: - has_repository_dependencies = repository_revision_dict[ 'has_repository_dependencies' ] - except: - raise HTTPBadRequest( detail="Missing required parameter 'has_repository_dependencies'." ) - try: - includes_tools = repository_revision_dict[ 'includes_tools' ] - except: - raise HTTPBadRequest( detail="Missing required parameter 'includes_tools'." ) - try: - includes_tool_dependencies = repository_revision_dict[ 'includes_tool_dependencies' ] - except: - raise HTTPBadRequest( detail="Missing required parameter 'includes_tool_dependencies'." ) - try: - includes_tools_for_display_in_tool_panel = repository_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] - except: - raise HTTPBadRequest( detail="Missing required parameter 'includes_tools_for_display_in_tool_panel'." ) - # Get the information about the Galaxy components (e.g., tool pane section, tool config file, etc) that will contain the repository information. - install_repository_dependencies = payload.get( 'install_repository_dependencies', False ) - install_tool_dependencies = payload.get( 'install_tool_dependencies', False ) - if install_tool_dependencies: - if trans.app.config.tool_dependency_dir is None: - no_tool_dependency_dir_message = "Tool dependencies can be automatically installed only if you set the value of your 'tool_dependency_dir' " - no_tool_dependency_dir_message += "setting in your Galaxy configuration file (universe_wsgi.ini) and restart your Galaxy server." - raise HTTPBadRequest( detail=no_tool_dependency_dir_message ) - new_tool_panel_section_label = payload.get( 'new_tool_panel_section_label', '' ) - shed_tool_conf = payload.get( 'shed_tool_conf', None ) - if shed_tool_conf: - # Get the tool_path setting. - index, shed_conf_dict = suc.get_shed_tool_conf_dict( trans.app, shed_tool_conf ) - tool_path = shed_conf_dict[ 'tool_path' ] - else: - # Pick a semi-random shed-related tool panel configuration file and get the tool_path setting. - for shed_config_dict in trans.app.toolbox.shed_tool_confs: - # Don't use migrated_tools_conf.xml. - if shed_config_dict[ 'config_filename' ] != trans.app.config.migrated_tools_config: - break - shed_tool_conf = shed_config_dict[ 'config_filename' ] - tool_path = shed_config_dict[ 'tool_path' ] - if not shed_tool_conf: - raise HTTPBadRequest( detail="Missing required parameter 'shed_tool_conf'." ) - tool_panel_section_id = payload.get( 'tool_panel_section_id', '' ) - if tool_panel_section_id not in [ None, '' ]: - if tool_panel_section_id not in trans.app.toolbox.tool_panel: - fixed_tool_panel_section_id = 'section_%s' % tool_panel_section_id - if fixed_tool_panel_section_id in trans.app.toolbox.tool_panel: - tool_panel_section_id = fixed_tool_panel_section_id - else: - tool_panel_section_id = '' - else: - tool_panel_section_id = '' - # Build the dictionary of information necessary for creating tool_shed_repository database records for each repository being installed. - 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 ) - # Create the tool_shed_repository database records and gather additional information for repository installation. - created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_util.handle_tool_shed_repositories( trans, installation_dict, using_api=True ) - if created_or_updated_tool_shed_repositories: - # Build the dictionary of information necessary for installing the repositories. - installation_dict = dict( created_or_updated_tool_shed_repositories=created_or_updated_tool_shed_repositories, - filtered_repo_info_dicts=filtered_repo_info_dicts, - 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, - shed_tool_conf=shed_tool_conf, - status='done', - tool_panel_section_id=tool_panel_section_id, - tool_panel_section_keys=tool_panel_section_keys, - tool_path=tool_path, - tool_shed_url=tool_shed_url ) - # Prepare the repositories for installation. Even though this method receives a single combination of tool_shed_url, name, owner and - # changeset_revision, there may be multiple repositories for installation at this point because repository dependencies may have added - # additional repositories for installation along with the single specified repository. - encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ - repository_util.initiate_repository_installation( trans, installation_dict ) - # Some repositories may have repository dependencies that are required to be installed before the dependent repository, so we'll - # order the list of tsr_ids to ensure all repositories install in the required order. - tsr_ids = [ trans.security.encode_id( tool_shed_repository.id ) for tool_shed_repository in tool_shed_repositories ] - ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ - repository_util.order_components_for_installation( trans, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) - # Install the repositories, keeping track of each one for later display. - for index, tsr_id in enumerate( ordered_tsr_ids ): - tool_shed_repository = trans.install_model.context.query( trans.install_model.ToolShedRepository ).get( trans.security.decode_id( tsr_id ) ) - if tool_shed_repository.status in [ trans.install_model.ToolShedRepository.installation_status.NEW, - trans.install_model.ToolShedRepository.installation_status.UNINSTALLED ]: + tool_shed_url, name, owner, changeset_revision = self.__parse_repository_from_payload( payload, include_changeset=True ) + self.__ensure_can_install_repos( trans ) + installed_tool_shed_repositories = repository_util.install( trans.app, tool_shed_url, name, owner, changeset_revision, payload ) - repo_info_dict = ordered_repo_info_dicts[ index ] - tool_panel_section_key = ordered_tool_panel_section_keys[ index ] - repository_util.install_tool_shed_repository( trans, - tool_shed_repository, - repo_info_dict, - tool_panel_section_key, - shed_tool_conf, - tool_path, - install_tool_dependencies, - reinstalling=False ) - 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 ) ) - installed_tool_shed_repositories.append( tool_shed_repository_dict ) - else: - # We're attempting to install more than 1 repository, and all of them have already been installed. - return dict( status='error', error='All repositories that you are attempting to install have been previously installed.' ) - # Display the list of installed repositories. - return installed_tool_shed_repositories + 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 - @web.expose_api + return map( to_dict, installed_tool_shed_repositories ) + + @expose_api def install_repository_revisions( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/install_repository_revisions @@ -438,13 +281,7 @@ (e.g., <toolbox tool_path="../shed_tools">). If this parameter is not set, a shed-related tool panel configuration file will be selected automatically. """ - if not suc.have_shed_tool_conf_for_install( trans ): - # This Galaxy instance is not configured with a shed-related tool panel configuration file. - message = get_message_for_no_shed_tool_config() - log.debug( message ) - return dict( status='error', error=message ) - if not trans.user_is_admin(): - raise HTTPForbidden( detail='You are not authorized to install a tool shed repository into this Galaxy instance.' ) + self.__ensure_can_install_repos( trans ) # Get the information about all of the repositories to be installed. tool_shed_urls = util.listify( payload.get( 'tool_shed_urls', '' ) ) names = util.listify( payload.get( 'names', '' ) ) @@ -487,7 +324,7 @@ all_installed_tool_shed_repositories.extend( installed_tool_shed_repositories ) return all_installed_tool_shed_repositories - @web.expose_api + @expose_api def repair_repository_revision( self, trans, payload, **kwd ): """ POST /api/tool_shed_repositories/repair_repository_revision @@ -502,18 +339,7 @@ :param changeset_revision (required): the changeset_revision of the RepositoryMetadata object associated with the Repository """ # Get the information about the repository to be installed from the payload. - tool_shed_url = payload.get( 'tool_shed_url', '' ) - if not tool_shed_url: - raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." ) - name = payload.get( 'name', '' ) - if not name: - raise HTTPBadRequest( detail="Missing required parameter 'name'." ) - owner = payload.get( 'owner', '' ) - if not owner: - raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) - changeset_revision = payload.get( 'changeset_revision', '' ) - if not changeset_revision: - raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." ) + tool_shed_url, name, owner, changeset_revision = self.__parse_repository_from_payload( payload, include_changeset=True ) tool_shed_repositories = [] tool_shed_repository = suc.get_tool_shed_repository_by_shed_name_owner_changeset_revision( trans.app, tool_shed_url, name, owner, changeset_revision ) repair_dict = repository_util.get_repair_dict( trans, tool_shed_repository ) @@ -538,7 +364,27 @@ # Display the list of repaired repositories. return tool_shed_repositories - @web.expose_api + def __parse_repository_from_payload( self, payload, include_changeset=False ): + # Get the information about the repository to be installed from the payload. + tool_shed_url = payload.get( 'tool_shed_url', '' ) + if not tool_shed_url: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'tool_shed_url'." ) + name = payload.get( 'name', '' ) + if not name: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'name'." ) + owner = payload.get( 'owner', '' ) + if not owner: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'owner'." ) + if not include_changeset: + return tool_shed_url, name, owner + + changeset_revision = payload.get( 'changeset_revision', '' ) + if not changeset_revision: + raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." ) + + return tool_shed_url, name, owner, changeset_revision + + @expose_api def reset_metadata_on_installed_repositories( self, trans, payload, **kwd ): """ PUT /api/tool_shed_repositories/reset_metadata_on_installed_repositories @@ -581,7 +427,7 @@ results[ 'stop_time' ] = stop_time return json.to_json_string( results, sort_keys=True, indent=4 ) - @web.expose_api + @expose_api def show( self, trans, id, **kwd ): """ GET /api/tool_shed_repositories/{encoded_tool_shed_repsository_id} diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -47,7 +47,7 @@ repository_id = kwd[ 'id' ] repository = suc.get_installed_tool_shed_repository( trans, repository_id ) try: - common_install_util.activate_repository( trans, repository ) + common_install_util.activate_repository( trans.app, repository ) except Exception, e: error_message = "Error activating repository %s: %s" % ( repository.name, str( e ) ) log.exception( error_message ) @@ -107,7 +107,7 @@ # repository dependencies and tool dependencies will be current. Only allow selecting a different section # in the tool panel if the repository was uninstalled and it contained tools that should be displayed in # the tool panel. - changeset_revision_dict = repository_util.get_update_to_changeset_revision_and_ctx_rev( trans, repository ) + changeset_revision_dict = repository_util.get_update_to_changeset_revision_and_ctx_rev( trans.app, repository ) current_changeset_revision = changeset_revision_dict.get( 'changeset_revision', None ) current_ctx_rev = changeset_revision_dict.get( 'ctx_rev', None ) if current_changeset_revision and current_ctx_rev: @@ -517,7 +517,7 @@ tmp_clone_url = common_util.url_join( tool_shed_url, 'repos', owner, name ) tmp_repo_info_tuple = ( None, tmp_clone_url, latest_downloadable_revision, None, owner, None, None ) installed_repository, installed_changeset_revision = \ - suc.repository_was_previously_installed( trans, tool_shed_url, name, tmp_repo_info_tuple, from_tip=False ) + suc.repository_was_previously_installed( trans.app, tool_shed_url, name, tmp_repo_info_tuple, from_tip=False ) if installed_repository: current_changeset_revision = str( installed_repository.changeset_revision ) message = 'Revision <b>%s</b> of repository <b>%s</b> owned by <b>%s</b> has already been installed.' % \ @@ -629,7 +629,7 @@ for index, tool_shed_repository in enumerate( tool_shed_repositories ): repo_info_dict = repo_info_dicts[ index ] tool_panel_section_key = tool_panel_section_keys[ index ] - repository_util.install_tool_shed_repository( trans, + repository_util.install_tool_shed_repository( trans.app, tool_shed_repository, repo_info_dict, tool_panel_section_key, @@ -692,7 +692,7 @@ # dependent repository, so we'll order the list of tsr_ids to ensure all repositories install in the # required order. ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ - repository_util.order_components_for_installation( trans, + repository_util.order_components_for_installation( trans.app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) @@ -948,7 +948,7 @@ @web.expose @web.require_admin def prepare_for_install( self, trans, **kwd ): - if not suc.have_shed_tool_conf_for_install( trans ): + if not suc.have_shed_tool_conf_for_install( trans.app ): message = 'The <b>tool_config_file</b> setting in <b>universe_wsgi.ini</b> must include at least one ' message += 'shed tool configuration file name with a <b><toolbox></b> tag that includes a <b>tool_path</b> ' message += 'attribute value which is a directory relative to the Galaxy installation directory in order ' @@ -1070,7 +1070,7 @@ tool_path=tool_path, tool_shed_url=tool_shed_url ) created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_util.handle_tool_shed_repositories( trans, installation_dict, using_api=False ) + repository_util.handle_tool_shed_repositories( trans.app, installation_dict, using_api=False ) if created_or_updated_tool_shed_repositories: installation_dict = dict( created_or_updated_tool_shed_repositories=created_or_updated_tool_shed_repositories, filtered_repo_info_dicts=filtered_repo_info_dicts, @@ -1089,7 +1089,7 @@ tool_path=tool_path, tool_shed_url=tool_shed_url ) encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ - repository_util.initiate_repository_installation( trans, installation_dict ) + repository_util.initiate_repository_installation( trans.app, installation_dict ) return trans.fill_template( 'admin/tool_shed_repository/initiate_repository_installation.mako', encoded_kwd=encoded_kwd, query=query, @@ -1287,7 +1287,7 @@ if tool_shed_repository.includes_tools_for_display_in_tool_panel: # Handle the selected tool panel location for loading tools included in the tool shed repository. tool_section, tool_panel_section_key = \ - tool_util.handle_tool_panel_selection( trans=trans, + tool_util.handle_tool_panel_selection( toolbox=trans.app.toolbox, metadata=metadata, no_changes_checked=no_changes_checked, tool_panel_section_id=tool_panel_section_id, @@ -1345,7 +1345,7 @@ repo_info_dicts.append( repo_info_dict ) # Make sure all tool_shed_repository records exist. created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_dependency_util.create_repository_dependency_objects( trans=trans, + repository_dependency_util.create_repository_dependency_objects( app=trans.app, tool_path=tool_path, tool_shed_url=tool_shed_url, repo_info_dicts=repo_info_dicts, @@ -1713,7 +1713,7 @@ """An error occurred while cloning the repository, so reset everything necessary to enable another attempt.""" repository = suc.get_installed_tool_shed_repository( trans, kwd[ 'id' ] ) if kwd.get( 'reset_repository', False ): - repository_util.set_repository_attributes( trans, + repository_util.set_repository_attributes( trans.app, repository, status=trans.install_model.ToolShedRepository.installation_status.NEW, error_message=None, diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/tool_shed/galaxy_install/repository_util.py --- a/lib/tool_shed/galaxy_install/repository_util.py +++ b/lib/tool_shed/galaxy_install/repository_util.py @@ -3,6 +3,7 @@ import shutil import tempfile import threading +from galaxy import exceptions from galaxy import tools from galaxy.util import json from galaxy import util @@ -135,13 +136,13 @@ prior_install_required_dict[ tsr_id ] = [] # Inspect the repository dependencies for each repository about to be installed and populate the dictionary. for repo_info_dict in repo_info_dicts: - repository, repository_dependencies = suc.get_repository_and_repository_dependencies_from_repo_info_dict( trans, repo_info_dict ) + repository, repository_dependencies = suc.get_repository_and_repository_dependencies_from_repo_info_dict( trans.app, repo_info_dict ) if repository: encoded_repository_id = trans.security.encode_id( repository.id ) if encoded_repository_id in tsr_ids: # We've located the database table record for one of the repositories we're about to install, so find out if it has any repository # dependencies that require prior installation. - prior_install_ids = suc.get_repository_ids_requiring_prior_import_or_install( trans, tsr_ids, repository_dependencies ) + prior_install_ids = suc.get_repository_ids_requiring_prior_import_or_install( trans.app, tsr_ids, repository_dependencies ) prior_install_required_dict[ encoded_repository_id ] = prior_install_ids return prior_install_required_dict @@ -174,7 +175,7 @@ tool_panel_section_keys.append( tool_panel_section_key ) repo_info_dicts.append( repo_info_dict ) ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ - order_components_for_installation( trans, + order_components_for_installation( trans.app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) @@ -264,7 +265,7 @@ tool_panel_section_name = section_dict[ 'name' ] if tool_panel_section_id: tool_panel_section_key, tool_panel_section = \ - tool_util.get_or_create_tool_section( trans, + tool_util.get_or_create_tool_section( trans.app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=tool_panel_section_name ) else: @@ -314,16 +315,16 @@ '' return [] -def get_update_to_changeset_revision_and_ctx_rev( trans, repository ): +def get_update_to_changeset_revision_and_ctx_rev( app, repository ): """Return the changeset revision hash to which the repository can be updated.""" changeset_revision_dict = {} - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, str( repository.tool_shed ) ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( repository.tool_shed ) ) params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( repository.name ), str( repository.owner ), str( repository.installed_changeset_revision ) ) url = common_util.url_join( tool_shed_url, 'repository/get_changeset_revision_and_ctx_rev%s' % params ) try: - encoded_update_dict = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + encoded_update_dict = common_util.tool_shed_get( app, tool_shed_url, url ) if encoded_update_dict: update_dict = encoding_util.tool_shed_decode( encoded_update_dict ) includes_data_managers = update_dict.get( 'includes_data_managers', False ) @@ -360,15 +361,16 @@ changeset_revision_dict[ 'ctx_rev' ] = None return changeset_revision_dict -def handle_repository_contents( trans, tool_shed_repository, tool_path, repository_clone_url, relative_install_dir, +def handle_repository_contents( app, tool_shed_repository, tool_path, repository_clone_url, relative_install_dir, tool_shed=None, tool_section=None, shed_tool_conf=None, reinstalling=False ): """ Generate the metadata for the installed tool shed repository, among other things. This method is called from Galaxy (never the tool shed) when an administrator is installing a new repository or reinstalling an uninstalled repository. """ - shed_config_dict = trans.app.toolbox.get_shed_config_dict_by_filename( shed_tool_conf ) + install_model = app.install_model + shed_config_dict = app.toolbox.get_shed_config_dict_by_filename( shed_tool_conf ) metadata_dict, invalid_file_tups = \ - metadata_util.generate_metadata_for_changeset_revision( app=trans.app, + metadata_util.generate_metadata_for_changeset_revision( app=app, repository=tool_shed_repository, changeset_revision=tool_shed_repository.changeset_revision, repository_clone_url=repository_clone_url, @@ -380,13 +382,13 @@ persist=True ) tool_shed_repository.metadata = metadata_dict # Update the tool_shed_repository.tool_shed_status column in the database. - tool_shed_status_dict = suc.get_tool_shed_status_for_installed_repository( trans.app, tool_shed_repository ) + tool_shed_status_dict = suc.get_tool_shed_status_for_installed_repository( app, tool_shed_repository ) if tool_shed_status_dict: tool_shed_repository.tool_shed_status = tool_shed_status_dict - trans.install_model.context.add( tool_shed_repository ) - trans.install_model.context.flush() + install_model.context.add( tool_shed_repository ) + install_model.context.flush() if 'tool_dependencies' in metadata_dict and not reinstalling: - tool_dependencies = tool_dependency_util.create_tool_dependency_objects( trans.app, + tool_dependencies = tool_dependency_util.create_tool_dependency_objects( app, tool_shed_repository, relative_install_dir, set_status=True ) @@ -394,36 +396,36 @@ sample_files = metadata_dict.get( 'sample_files', [] ) tool_index_sample_files = tool_util.get_tool_index_sample_files( sample_files ) tool_data_table_conf_filename, tool_data_table_elems = \ - tool_util.install_tool_data_tables( trans.app, tool_shed_repository, tool_index_sample_files ) + tool_util.install_tool_data_tables( app, tool_shed_repository, tool_index_sample_files ) if tool_data_table_elems: - trans.app.tool_data_tables.add_new_entries_from_config_file( tool_data_table_conf_filename, + app.tool_data_tables.add_new_entries_from_config_file( tool_data_table_conf_filename, None, - trans.app.config.shed_tool_data_table_config, + app.config.shed_tool_data_table_config, persist=True ) if 'tools' in metadata_dict: tool_panel_dict = tool_util.generate_tool_panel_dict_for_new_install( metadata_dict[ 'tools' ], tool_section ) sample_files = metadata_dict.get( 'sample_files', [] ) tool_index_sample_files = tool_util.get_tool_index_sample_files( sample_files ) - tool_util.copy_sample_files( trans.app, tool_index_sample_files, tool_path=tool_path ) + tool_util.copy_sample_files( app, tool_index_sample_files, tool_path=tool_path ) sample_files_copied = [ str( s ) for s in tool_index_sample_files ] - repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata_dict ) + repository_tools_tups = suc.get_repository_tools_tups( app, metadata_dict ) if repository_tools_tups: # Handle missing data table entries for tool parameters that are dynamically generated select lists. - repository_tools_tups = tool_util.handle_missing_data_table_entry( trans.app, + repository_tools_tups = tool_util.handle_missing_data_table_entry( app, relative_install_dir, tool_path, repository_tools_tups ) # Handle missing index files for tool parameters that are dynamically generated select lists. repository_tools_tups, sample_files_copied = \ - tool_util.handle_missing_index_file( trans.app, + tool_util.handle_missing_index_file( app, tool_path, sample_files, repository_tools_tups, sample_files_copied ) # Copy remaining sample files included in the repository to the ~/tool-data directory of the # local Galaxy instance. - tool_util.copy_sample_files( trans.app, sample_files, tool_path=tool_path, sample_files_copied=sample_files_copied ) - tool_util.add_to_tool_panel( app=trans.app, + tool_util.copy_sample_files( app, sample_files, tool_path=tool_path, sample_files_copied=sample_files_copied ) + tool_util.add_to_tool_panel( app=app, repository_name=tool_shed_repository.name, repository_clone_url=repository_clone_url, changeset_revision=tool_shed_repository.installed_changeset_revision, @@ -433,26 +435,26 @@ tool_panel_dict=tool_panel_dict, new_install=True ) if 'data_manager' in metadata_dict: - new_data_managers = data_manager_util.install_data_managers( trans.app, - trans.app.config.shed_data_manager_config_file, + new_data_managers = data_manager_util.install_data_managers( app, + app.config.shed_data_manager_config_file, metadata_dict, shed_config_dict, relative_install_dir, tool_shed_repository, repository_tools_tups ) if 'datatypes' in metadata_dict: - tool_shed_repository.status = trans.install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES + tool_shed_repository.status = install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES if not tool_shed_repository.includes_datatypes: tool_shed_repository.includes_datatypes = True - trans.install_model.context.add( tool_shed_repository ) - trans.install_model.context.flush() + install_model.context.add( tool_shed_repository ) + 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 ) # Load data types required by tools. converter_path, display_path = \ - datatype_util.alter_config_and_load_prorietary_datatypes( trans.app, datatypes_config, files_dir, override=False ) + datatype_util.alter_config_and_load_prorietary_datatypes( app, datatypes_config, files_dir, override=False ) if converter_path or display_path: # Create a dictionary of tool shed repository related information. repository_dict = \ @@ -465,12 +467,12 @@ display_path=display_path ) if converter_path: # Load proprietary datatype converters - trans.app.datatypes_registry.load_datatype_converters( trans.app.toolbox, installed_repository_dict=repository_dict ) + app.datatypes_registry.load_datatype_converters( app.toolbox, installed_repository_dict=repository_dict ) if display_path: # Load proprietary datatype display applications - trans.app.datatypes_registry.load_display_applications( installed_repository_dict=repository_dict ) + app.datatypes_registry.load_display_applications( installed_repository_dict=repository_dict ) -def handle_tool_shed_repositories( trans, installation_dict, using_api=False ): +def handle_tool_shed_repositories( app, installation_dict, using_api=False ): # The following installation_dict entries are all required. install_repository_dependencies = installation_dict[ 'install_repository_dependencies' ] new_tool_panel_section_label = installation_dict[ 'new_tool_panel_section_label' ] @@ -480,7 +482,7 @@ tool_path = installation_dict[ 'tool_path' ] tool_shed_url = installation_dict[ 'tool_shed_url' ] created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ - repository_dependency_util.create_repository_dependency_objects( trans=trans, + repository_dependency_util.create_repository_dependency_objects( app=app, tool_path=tool_path, tool_shed_url=tool_shed_url, repo_info_dicts=repo_info_dicts, @@ -490,7 +492,8 @@ new_tool_panel_section_label=new_tool_panel_section_label ) return created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts -def initiate_repository_installation( trans, installation_dict ): +def initiate_repository_installation( app, installation_dict ): + install_model = app.install_model # The following installation_dict entries are all required. created_or_updated_tool_shed_repositories = installation_dict[ 'created_or_updated_tool_shed_repositories' ] filtered_repo_info_dicts = installation_dict[ 'filtered_repo_info_dicts' ] @@ -511,13 +514,13 @@ # Handle contained tools. if includes_tools_for_display_in_tool_panel and ( new_tool_panel_section_label or tool_panel_section_id ): tool_panel_section_key, tool_section = \ - tool_util.handle_tool_panel_section( trans, + tool_util.handle_tool_panel_section( app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) else: tool_panel_section_key = None tool_section = None - encoded_repository_ids = [ trans.security.encode_id( tsr.id ) for tsr in created_or_updated_tool_shed_repositories ] + encoded_repository_ids = [ app.security.encode_id( tsr.id ) for tsr in created_or_updated_tool_shed_repositories ] new_kwd = dict( includes_tools=includes_tools, includes_tools_for_display_in_tool_panel=includes_tools_for_display_in_tool_panel, has_repository_dependencies=has_repository_dependencies, @@ -536,19 +539,181 @@ tsr_ids = [ r.id for r in created_or_updated_tool_shed_repositories ] tool_shed_repositories = [] for tsr_id in tsr_ids: - tsr = trans.install_model.context.query( trans.install_model.ToolShedRepository ).get( tsr_id ) + tsr = install_model.context.query( install_model.ToolShedRepository ).get( tsr_id ) tool_shed_repositories.append( tsr ) clause_list = [] for tsr_id in tsr_ids: - clause_list.append( trans.install_model.ToolShedRepository.table.c.id == tsr_id ) - query = trans.install_model.context.query( trans.install_model.ToolShedRepository ).filter( or_( *clause_list ) ) + clause_list.append( install_model.ToolShedRepository.table.c.id == tsr_id ) + query = install_model.context.query( install_model.ToolShedRepository ).filter( or_( *clause_list ) ) return encoded_kwd, query, tool_shed_repositories, encoded_repository_ids -def install_tool_shed_repository( trans, tool_shed_repository, repo_info_dict, tool_panel_section_key, shed_tool_conf, tool_path, + +def install( app, tool_shed_url, name, owner, changeset_revision, install_options ): + # Get all of the information necessary for installing the repository from the specified tool shed. + repository_revision_dict, repo_info_dicts = __get_install_info_from_tool_shed( app, tool_shed_url, name, owner, changeset_revision ) + installed_tool_shed_repositories = __install_repositories( app, repository_revision_dict, repo_info_dicts, install_options ) + return installed_tool_shed_repositories + + +def __install_repositories( self, app, tool_shed_url, repository_revision_dict, repo_info_dicts, install_options ): + # Keep track of all repositories that are installed - there may be more than one if repository dependencies are installed. + installed_tool_shed_repositories = [] + try: + has_repository_dependencies = repository_revision_dict[ 'has_repository_dependencies' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'has_repository_dependencies'." ) + try: + includes_tools = repository_revision_dict[ 'includes_tools' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools'." ) + try: + includes_tool_dependencies = repository_revision_dict[ 'includes_tool_dependencies' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tool_dependencies'." ) + try: + includes_tools_for_display_in_tool_panel = repository_revision_dict[ 'includes_tools_for_display_in_tool_panel' ] + except: + raise exceptions.InternalServerError( "Tool shed response missing required parameter 'includes_tools_for_display_in_tool_panel'." ) + # Get the information about the Galaxy components (e.g., tool pane section, tool config file, etc) that will contain the repository information. + install_repository_dependencies = install_options.get( 'install_repository_dependencies', False ) + install_tool_dependencies = install_options.get( 'install_tool_dependencies', False ) + if install_tool_dependencies: + if app.config.tool_dependency_dir is None: + no_tool_dependency_dir_message = "Tool dependencies can be automatically installed only if you set the value of your 'tool_dependency_dir' " + no_tool_dependency_dir_message += "setting in your Galaxy configuration file (universe_wsgi.ini) and restart your Galaxy server." + raise exceptions.ConfigDoesNotAllowException( no_tool_dependency_dir_message ) + new_tool_panel_section_label = install_options.get( 'new_tool_panel_section_label', '' ) + shed_tool_conf = install_options.get( 'shed_tool_conf', None ) + if shed_tool_conf: + # Get the tool_path setting. + index, shed_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf ) + tool_path = shed_conf_dict[ 'tool_path' ] + else: + # Pick a semi-random shed-related tool panel configuration file and get the tool_path setting. + for shed_config_dict in app.toolbox.shed_tool_confs: + # Don't use migrated_tools_conf.xml. + if shed_config_dict[ 'config_filename' ] != app.config.migrated_tools_config: + break + shed_tool_conf = shed_config_dict[ 'config_filename' ] + tool_path = shed_config_dict[ 'tool_path' ] + if not shed_tool_conf: + raise exceptions.RequestParameterMissingException( "Missing required parameter 'shed_tool_conf'." ) + tool_panel_section_id = install_options.get( 'tool_panel_section_id', '' ) + if tool_panel_section_id not in [ None, '' ]: + if tool_panel_section_id not in app.toolbox.tool_panel: + fixed_tool_panel_section_id = 'section_%s' % tool_panel_section_id + if fixed_tool_panel_section_id in app.toolbox.tool_panel: + tool_panel_section_id = fixed_tool_panel_section_id + else: + tool_panel_section_id = '' + else: + tool_panel_section_id = '' + # Build the dictionary of information necessary for creating tool_shed_repository database records for each repository being installed. + 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 ) + # Create the tool_shed_repository database records and gather additional information for repository installation. + created_or_updated_tool_shed_repositories, tool_panel_section_keys, repo_info_dicts, filtered_repo_info_dicts = \ + handle_tool_shed_repositories( app, installation_dict, using_api=True ) + if created_or_updated_tool_shed_repositories: + # Build the dictionary of information necessary for installing the repositories. + installation_dict = dict( created_or_updated_tool_shed_repositories=created_or_updated_tool_shed_repositories, + filtered_repo_info_dicts=filtered_repo_info_dicts, + 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, + shed_tool_conf=shed_tool_conf, + status='done', + tool_panel_section_id=tool_panel_section_id, + tool_panel_section_keys=tool_panel_section_keys, + tool_path=tool_path, + tool_shed_url=tool_shed_url ) + # Prepare the repositories for installation. Even though this method receives a single combination of tool_shed_url, name, owner and + # changeset_revision, there may be multiple repositories for installation at this point because repository dependencies may have added + # additional repositories for installation along with the single specified repository. + encoded_kwd, query, tool_shed_repositories, encoded_repository_ids = \ + initiate_repository_installation( app, installation_dict ) + # Some repositories may have repository dependencies that are required to be installed before the dependent repository, so we'll + # order the list of tsr_ids to ensure all repositories install in the required order. + tsr_ids = [ app.security.encode_id( tool_shed_repository.id ) for tool_shed_repository in tool_shed_repositories ] + ordered_tsr_ids, ordered_repo_info_dicts, ordered_tool_panel_section_keys = \ + order_components_for_installation( app, tsr_ids, repo_info_dicts, tool_panel_section_keys=tool_panel_section_keys ) + # Install the repositories, keeping track of each one for later display. + for index, tsr_id in enumerate( ordered_tsr_ids ): + install_model = app.install_model + tool_shed_repository = install_model.context.query( install_model.ToolShedRepository ).get( app.security.decode_id( tsr_id ) ) + if tool_shed_repository.status in [ install_model.ToolShedRepository.installation_status.NEW, + install_model.ToolShedRepository.installation_status.UNINSTALLED ]: + + repo_info_dict = ordered_repo_info_dicts[ index ] + tool_panel_section_key = ordered_tool_panel_section_keys[ index ] + install_tool_shed_repository( app, + tool_shed_repository, + repo_info_dict, + tool_panel_section_key, + shed_tool_conf, + tool_path, + install_tool_dependencies, + reinstalling=False ) + installed_tool_shed_repositories.append( tool_shed_repository ) + else: + # We're attempting to install more than 1 repository, and all of them have already been installed. + raise exceptions.RequestParameterInvalidException( 'All repositories that you are attempting to install have been previously installed.' ) + return installed_tool_shed_repositories + + +def __get_install_info_from_tool_shed( self, app, tool_shed_url, name, owner, changeset_revision ): + params = '?name=%s&owner=%s&changeset_revision=%s' % ( name, owner, changeset_revision ) + url = common_util.url_join( tool_shed_url, + 'api/repositories/get_repository_revision_install_info%s' % params ) + try: + raw_text = common_util.tool_shed_get( app, tool_shed_url, url ) + except Exception, e: + message = "Error attempting to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ + ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) + log.warn( message ) + raise exceptions.InternalServerError( message ) + if raw_text: + # If successful, the response from get_repository_revision_install_info will be 3 + # dictionaries, a dictionary defining the Repository, a dictionary defining the + # Repository revision (RepositoryMetadata), and a dictionary including the additional + # information required to install the repository. + items = json.from_json_string( raw_text ) + repository_revision_dict = items[ 1 ] + repo_info_dict = items[ 2 ] + else: + message = "Unable to retrieve installation information from tool shed %s for revision %s of repository %s owned by %s: %s" % \ + ( str( tool_shed_url ), str( changeset_revision ), str( name ), str( owner ), str( e ) ) + log.warn( message ) + raise exceptions.InternalServerError( message ) + # Make sure the tool shed returned everything we need for installing the repository. + if not repository_revision_dict or not repo_info_dict: + invalid_parameter_message = "No information is available for the requested repository revision.\n" + invalid_parameter_message += "One or more of the following parameter values is likely invalid:\n" + invalid_parameter_message += "tool_shed_url: %s\n" % str( tool_shed_url ) + invalid_parameter_message += "name: %s\n" % str( name ) + invalid_parameter_message += "owner: %s\n" % str( owner ) + invalid_parameter_message += "changeset_revision: %s\n" % str( changeset_revision ) + raise exceptions.RequestParameterInvalidException( invalid_parameter_message ) + repo_info_dicts = [ repo_info_dict ] + return repository_revision_dict, repo_info_dicts + + +def install_tool_shed_repository( app, tool_shed_repository, repo_info_dict, tool_panel_section_key, shed_tool_conf, tool_path, install_tool_dependencies, reinstalling=False ): + install_model = app.install_model if tool_panel_section_key: try: - tool_section = trans.app.toolbox.tool_panel[ tool_panel_section_key ] + tool_section = app.toolbox.tool_panel[ tool_panel_section_key ] except KeyError: log.debug( 'Invalid tool_panel_section_key "%s" specified. Tools will be loaded outside of sections in the tool panel.', str( tool_panel_section_key ) ) @@ -558,31 +723,30 @@ if isinstance( repo_info_dict, basestring ): repo_info_dict = encoding_util.tool_shed_decode( repo_info_dict ) # Clone each repository to the configured location. - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.CLONING ) + install_model.ToolShedRepository.installation_status.CLONING ) repo_info_tuple = repo_info_dict[ tool_shed_repository.name ] description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = repo_info_tuple relative_clone_dir = suc.generate_tool_shed_repository_install_dir( repository_clone_url, tool_shed_repository.installed_changeset_revision ) - clone_dir = os.path.join( tool_path, relative_clone_dir ) relative_install_dir = os.path.join( relative_clone_dir, tool_shed_repository.name ) install_dir = os.path.join( tool_path, relative_install_dir ) cloned_ok, error_message = hg_util.clone_repository( repository_clone_url, os.path.abspath( install_dir ), ctx_rev ) if cloned_ok: if reinstalling: # Since we're reinstalling the repository we need to find the latest changeset revision to which it can be updated. - changeset_revision_dict = get_update_to_changeset_revision_and_ctx_rev( trans, tool_shed_repository ) + changeset_revision_dict = get_update_to_changeset_revision_and_ctx_rev( app, tool_shed_repository ) current_changeset_revision = changeset_revision_dict.get( 'changeset_revision', None ) current_ctx_rev = changeset_revision_dict.get( 'ctx_rev', None ) if current_ctx_rev != ctx_rev: - repo = hg_util.get_repo_for_repository( trans.app, + repo = hg_util.get_repo_for_repository( app, repository=None, repo_path=os.path.abspath( install_dir ), create=False ) pull_repository( repo, repository_clone_url, current_changeset_revision ) hg_util.update_repository( repo, ctx_rev=current_ctx_rev ) - handle_repository_contents( trans, + handle_repository_contents( app, tool_shed_repository=tool_shed_repository, tool_path=tool_path, repository_clone_url=repository_clone_url, @@ -591,23 +755,23 @@ tool_section=tool_section, shed_tool_conf=shed_tool_conf, reinstalling=reinstalling ) - trans.install_model.context.refresh( tool_shed_repository ) + install_model.context.refresh( tool_shed_repository ) metadata = tool_shed_repository.metadata if 'tools' in metadata: # Get the tool_versions from the tool shed for each tool in the installed change set. - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS ) - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, str( tool_shed_repository.tool_shed ) ) + install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, str( tool_shed_repository.tool_shed ) ) params = '?name=%s&owner=%s&changeset_revision=%s' % ( str( tool_shed_repository.name ), str( tool_shed_repository.owner ), str( tool_shed_repository.changeset_revision ) ) url = common_util.url_join( tool_shed_url, '/repository/get_tool_versions%s' % params ) - text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + text = common_util.tool_shed_get( app, tool_shed_url, url ) if text: tool_version_dicts = json.from_json_string( text ) - tool_util.handle_tool_versions( trans.app, tool_version_dicts, tool_shed_repository ) + tool_util.handle_tool_versions( app, tool_version_dicts, tool_shed_repository ) else: if not error_message: error_message = "" @@ -617,29 +781,29 @@ if install_tool_dependencies and tool_shed_repository.tool_dependencies and 'tool_dependencies' in metadata: work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-itsr" ) # Install tool dependencies. - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES ) + install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES ) # Get the tool_dependencies.xml file from the repository. tool_dependencies_config = hg_util.get_config_from_disk( 'tool_dependencies.xml', install_dir ) installed_tool_dependencies = \ - common_install_util.install_specified_tool_dependencies( app=trans.app, + common_install_util.install_specified_tool_dependencies( app=app, tool_shed_repository=tool_shed_repository, tool_dependencies_config=tool_dependencies_config, tool_dependencies=tool_shed_repository.tool_dependencies, from_tool_migration_manager=False ) basic_util.remove_dir( work_dir ) - suc.update_tool_shed_repository_status( trans.app, + suc.update_tool_shed_repository_status( app, tool_shed_repository, - trans.install_model.ToolShedRepository.installation_status.INSTALLED ) - if trans.app.config.manage_dependency_relationships: + install_model.ToolShedRepository.installation_status.INSTALLED ) + if app.config.manage_dependency_relationships: # Add the installed repository and any tool dependencies to the in-memory dictionaries in the installed_repository_manager. - trans.app.installed_repository_manager.handle_repository_install( tool_shed_repository ) + app.installed_repository_manager.handle_repository_install( tool_shed_repository ) else: # An error occurred while cloning the repository, so reset everything necessary to enable another attempt. - set_repository_attributes( trans, + set_repository_attributes( app, tool_shed_repository, - status=trans.install_model.ToolShedRepository.installation_status.ERROR, + status=install_model.ToolShedRepository.installation_status.ERROR, error_message=error_message, deleted=False, uninstalled=False, @@ -722,7 +886,7 @@ lock.release() return new_containers_dict -def order_components_for_installation( trans, tsr_ids, repo_info_dicts, tool_panel_section_keys ): +def order_components_for_installation( app, tsr_ids, repo_info_dicts, tool_panel_section_keys ): """ Some repositories may have repository dependencies that are required to be installed before the dependent repository. This method will inspect the list of repositories about to be installed and make sure to order them appropriately. @@ -737,7 +901,7 @@ # Create a dictionary whose keys are the received tsr_ids and whose values are a list of tsr_ids, each of which is # contained in the received list of tsr_ids and whose associated repository must be installed prior to the repository # associated with the tsr_id key. - prior_install_required_dict = suc.get_prior_import_or_install_required_dict( trans, tsr_ids, repo_info_dicts ) + prior_install_required_dict = suc.get_prior_import_or_install_required_dict( app, tsr_ids, repo_info_dicts ) processed_tsr_ids = [] while len( processed_tsr_ids ) != len( prior_install_required_dict.keys() ): tsr_id = suc.get_next_prior_import_or_install_required_dict_entry( prior_install_required_dict, processed_tsr_ids ) @@ -825,7 +989,7 @@ repair_dict = {} if repository.status in [ trans.install_model.ToolShedRepository.installation_status.DEACTIVATED ]: try: - common_install_util.activate_repository( trans, repository ) + common_install_util.activate_repository( trans.app, repository ) except Exception, e: error_message = "Error activating repository %s: %s" % ( repository.name, str( e ) ) log.debug( error_message ) @@ -835,7 +999,7 @@ # Reset the repository attributes to the New state for installation. if metadata: tool_section, tool_panel_section_key = \ - tool_util.handle_tool_panel_selection( trans, + tool_util.handle_tool_panel_selection( trans.app.toolbox, metadata, no_changes_checked=True, tool_panel_section_id=None, @@ -843,14 +1007,14 @@ else: # The tools will be loaded outside of any sections in the tool panel. tool_panel_section_key = None - set_repository_attributes( trans, + set_repository_attributes( trans.app, repository, status=trans.install_model.ToolShedRepository.installation_status.NEW, error_message=None, deleted=False, uninstalled=False, remove_from_disk=True ) - install_tool_shed_repository( trans, + install_tool_shed_repository( trans.app, repository, repo_info_dict, tool_panel_section_key, @@ -893,9 +1057,9 @@ suc.update_tool_shed_repository_status( trans.app, repository, trans.install_model.ToolShedRepository.installation_status.INSTALLED ) return repair_dict -def set_repository_attributes( trans, repository, status, error_message, deleted, uninstalled, remove_from_disk=False ): +def set_repository_attributes( app, repository, status, error_message, deleted, uninstalled, remove_from_disk=False ): if remove_from_disk: - relative_install_dir = repository.repo_path( trans.app ) + relative_install_dir = repository.repo_path( app ) if relative_install_dir: clone_dir = os.path.abspath( relative_install_dir ) try: @@ -907,8 +1071,8 @@ repository.status = status repository.deleted = deleted repository.uninstalled = uninstalled - trans.install_model.context.add( repository ) - trans.install_model.context.flush() + app.install_model.context.add( repository ) + app.install_model.context.flush() def update_repository_record( trans, repository, updated_metadata_dict, updated_changeset_revision, updated_ctx_rev ): """ diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/tool_shed/util/common_install_util.py --- a/lib/tool_shed/util/common_install_util.py +++ b/lib/tool_shed/util/common_install_util.py @@ -22,18 +22,19 @@ log = logging.getLogger( __name__ ) -def activate_repository( trans, repository ): +def activate_repository( app, repository ): """Activate an installed tool shed repository that has been marked as deactivated.""" - repository_clone_url = common_util.generate_clone_url_for_installed_repository( trans.app, repository ) - shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( trans.app, repository ) + install_model = app.install_model + repository_clone_url = common_util.generate_clone_url_for_installed_repository( app, repository ) + shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( app, repository ) repository.deleted = False - repository.status = trans.install_model.ToolShedRepository.installation_status.INSTALLED + repository.status = install_model.ToolShedRepository.installation_status.INSTALLED if repository.includes_tools_for_display_in_tool_panel: metadata = repository.metadata - repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata ) + repository_tools_tups = suc.get_repository_tools_tups( app, metadata ) # Reload tools into the appropriate tool panel section. tool_panel_dict = repository.metadata[ 'tool_panel_section' ] - tool_util.add_to_tool_panel( trans.app, + tool_util.add_to_tool_panel( app, repository.name, repository_clone_url, repository.installed_changeset_revision, @@ -43,32 +44,32 @@ tool_panel_dict, new_install=False ) if repository.includes_data_managers: - tp, data_manager_relative_install_dir = repository.get_tool_relative_path( trans.app ) + tp, data_manager_relative_install_dir = repository.get_tool_relative_path( app ) # Hack to add repository.name here, which is actually the root of the installed repository data_manager_relative_install_dir = os.path.join( data_manager_relative_install_dir, repository.name ) - new_data_managers = data_manager_util.install_data_managers( trans.app, - trans.app.config.shed_data_manager_config_file, + new_data_managers = data_manager_util.install_data_managers( app, + app.config.shed_data_manager_config_file, metadata, - repository.get_shed_config_dict( trans.app ), + repository.get_shed_config_dict( app ), data_manager_relative_install_dir, repository, repository_tools_tups ) - trans.install_model.context.add( repository ) - trans.install_model.context.flush() + install_model.context.add( repository ) + install_model.context.flush() if repository.includes_datatypes: if tool_path: repository_install_dir = os.path.abspath( os.path.join( tool_path, relative_install_dir ) ) else: repository_install_dir = os.path.abspath( relative_install_dir ) # Activate proprietary datatypes. - installed_repository_dict = datatype_util.load_installed_datatypes( trans.app, repository, repository_install_dir, deactivate=False ) + installed_repository_dict = datatype_util.load_installed_datatypes( app, repository, repository_install_dir, deactivate=False ) if installed_repository_dict: converter_path = installed_repository_dict.get( 'converter_path' ) if converter_path is not None: - datatype_util.load_installed_datatype_converters( trans.app, installed_repository_dict, deactivate=False ) + datatype_util.load_installed_datatype_converters( app, installed_repository_dict, deactivate=False ) display_path = installed_repository_dict.get( 'display_path' ) if display_path is not None: - datatype_util.load_installed_display_applications( trans.app, installed_repository_dict, deactivate=False ) + datatype_util.load_installed_display_applications( app, installed_repository_dict, deactivate=False ) def get_dependencies_for_repository( trans, tool_shed_url, repo_info_dict, includes_tool_dependencies, updating=False ): """ @@ -107,7 +108,7 @@ installed_rd, missing_rd = \ get_installed_and_missing_repository_dependencies_for_new_or_updated_install( trans, repo_info_tuple ) # Discover all repository dependencies and retrieve information for installing them. - all_repo_info_dict = get_required_repo_info_dicts( trans, tool_shed_url, util.listify( repo_info_dict ) ) + all_repo_info_dict = get_required_repo_info_dicts( trans.app, tool_shed_url, util.listify( repo_info_dict ) ) has_repository_dependencies = all_repo_info_dict.get( 'has_repository_dependencies', False ) has_repository_dependencies_only_if_compiling_contained_td = \ all_repo_info_dict.get( 'has_repository_dependencies_only_if_compiling_contained_td', False ) @@ -145,7 +146,7 @@ missing_td[ td_key ] = td_dict else: # We have a single repository with (possibly) no defined repository dependencies. - all_repo_info_dict = get_required_repo_info_dicts( trans, tool_shed_url, util.listify( repo_info_dict ) ) + all_repo_info_dict = get_required_repo_info_dicts( trans.app, tool_shed_url, util.listify( repo_info_dict ) ) has_repository_dependencies = all_repo_info_dict.get( 'has_repository_dependencies', False ) has_repository_dependencies_only_if_compiling_contained_td = \ all_repo_info_dict.get( 'has_repository_dependencies_only_if_compiling_contained_td', False ) @@ -261,7 +262,7 @@ # repository_dependencies, installed_td ) tmp_clone_url = common_util.generate_clone_url_from_repo_info_tup( trans, rd_tup ) tmp_repo_info_tuple = ( None, tmp_clone_url, changeset_revision, None, owner, None, None ) - repository, installed_changeset_revision = suc.repository_was_previously_installed( trans, + repository, installed_changeset_revision = suc.repository_was_previously_installed( trans.app, tool_shed, name, tmp_repo_info_tuple, @@ -380,7 +381,7 @@ missing_tool_dependencies[ td_key ] = val return installed_tool_dependencies, missing_tool_dependencies -def get_required_repo_info_dicts( trans, tool_shed_url, repo_info_dicts ): +def get_required_repo_info_dicts( app, tool_shed_url, repo_info_dicts ): """ Inspect the list of repo_info_dicts for repository dependencies and append a repo_info_dict for each of them to the list. All repository_dependencies entries in each of the received repo_info_dicts includes @@ -444,9 +445,9 @@ encoded_required_repository_tups.append( encoding_util.encoding_sep.join( required_repository_tup ) ) encoded_required_repository_str = encoding_util.encoding_sep2.join( encoded_required_repository_tups ) encoded_required_repository_str = encoding_util.tool_shed_encode( encoded_required_repository_str ) - if trans.webapp.name == 'galaxy': + if suc.is_tool_shed_client( app ): # Handle secure / insecure Tool Shed URL protocol changes and port changes. - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed_url ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed_url ) url = common_util.url_join( tool_shed_url, '/repository/get_required_repo_info_dict' ) # Fix for handling 307 redirect not being handled nicely by urllib2.urlopen when the urllib2.Request has data provided url = urllib2.urlopen( urllib2.Request( url ) ).geturl() diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/tool_shed/util/export_util.py --- a/lib/tool_shed/util/export_util.py +++ b/lib/tool_shed/util/export_util.py @@ -262,7 +262,7 @@ str( repository.user.username ), repository_dependencies, None ) - all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( trans, tool_shed_url, [ repo_info_dict ] ) + all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( trans.app, tool_shed_url, [ repo_info_dict ] ) all_repo_info_dicts = all_required_repo_info_dict.get( 'all_repo_info_dicts', [] ) return all_repo_info_dicts @@ -320,7 +320,7 @@ # Create a dictionary whose keys are the received repository_ids and whose values are a list of # repository_ids, each of which is contained in the received list of repository_ids and whose associated # repository must be imported prior to the repository associated with the repository_id key. - prior_import_required_dict = suc.get_prior_import_or_install_required_dict( trans, repository_ids, repo_info_dicts ) + prior_import_required_dict = suc.get_prior_import_or_install_required_dict( trans.app, repository_ids, repo_info_dicts ) processed_repository_ids = [] # Process the list of repository dependencies defined for the repository associated with the received # primary_repository_id. diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/tool_shed/util/repository_dependency_util.py --- a/lib/tool_shed/util/repository_dependency_util.py +++ b/lib/tool_shed/util/repository_dependency_util.py @@ -16,12 +16,13 @@ log = logging.getLogger( __name__ ) -def build_repository_dependency_relationships( trans, repo_info_dicts, tool_shed_repositories ): +def build_repository_dependency_relationships( app, repo_info_dicts, tool_shed_repositories ): """ Build relationships between installed tool shed repositories and other installed tool shed repositories upon which they depend. These relationships are defined in the repository_dependencies entry for each dictionary in the received list of repo_info_dicts. Each of these dictionaries is associated with a repository in the received tool_shed_repositories list. """ + install_model = app.install_model log.debug( "Building repository dependency relationships..." ) for repo_info_dict in repo_info_dicts: for name, repo_info_tuple in repo_info_dict.items(): @@ -45,7 +46,7 @@ break if d_repository is None: # The dependent repository is not in the received list so look in the database. - d_repository = suc.get_or_create_tool_shed_repository( trans, d_toolshed, d_name, d_owner, d_changeset_revision ) + d_repository = suc.get_or_create_tool_shed_repository( app, d_toolshed, d_name, d_owner, d_changeset_revision ) # Process each repository_dependency defined for the current dependent repository. for repository_dependency_components_list in val: required_repository = None @@ -60,7 +61,7 @@ break if required_repository is None: # The required repository is not in the received list so look in the database. - required_repository = suc.get_or_create_tool_shed_repository( trans, + required_repository = suc.get_or_create_tool_shed_repository( app, rd_toolshed, rd_name, rd_owner, @@ -73,20 +74,20 @@ break if not rrda: # Make sure required_repository is in the repository_dependency table. - repository_dependency = get_repository_dependency_by_repository_id( trans, required_repository.id ) + repository_dependency = get_repository_dependency_by_repository_id( install_model, required_repository.id ) if not repository_dependency: log.debug( 'Creating new repository_dependency record for installed revision %s of repository: %s owned by %s.' % \ ( str( required_repository.installed_changeset_revision ), str( required_repository.name ), str( required_repository.owner ) ) ) - repository_dependency = trans.install_model.RepositoryDependency( tool_shed_repository_id=required_repository.id ) - trans.install_model.context.add( repository_dependency ) - trans.install_model.context.flush() + repository_dependency = install_model.RepositoryDependency( tool_shed_repository_id=required_repository.id ) + install_model.context.add( repository_dependency ) + install_model.context.flush() # Build the relationship between the d_repository and the required_repository. - rrda = trans.install_model.RepositoryRepositoryDependencyAssociation( tool_shed_repository_id=d_repository.id, - repository_dependency_id=repository_dependency.id ) - trans.install_model.context.add( rrda ) - trans.install_model.context.flush() + rrda = install_model.RepositoryRepositoryDependencyAssociation( tool_shed_repository_id=d_repository.id, + repository_dependency_id=repository_dependency.id ) + install_model.context.add( rrda ) + install_model.context.flush() def can_add_to_key_rd_dicts( key_rd_dict, key_rd_dicts ): """Handle the case where an update to the changeset revision was done.""" @@ -101,7 +102,7 @@ return False return True -def create_repository_dependency_objects( trans, tool_path, tool_shed_url, repo_info_dicts, install_repository_dependencies=False, +def create_repository_dependency_objects( app, tool_path, tool_shed_url, repo_info_dicts, install_repository_dependencies=False, no_changes_checked=False, tool_panel_section_id=None, new_tool_panel_section_label=None ): """ Discover all repository dependencies and make sure all tool_shed_repository and associated repository_dependency @@ -110,6 +111,7 @@ in the all_repo_info_dicts list will be processed. However, if repository dependencies are not to be installed, only those items contained in the received repo_info_dicts list will be processed. """ + install_model = app.install_model log.debug( "Creating repository dependency objects..." ) # The following list will be maintained within this method to contain all created or updated tool shed repositories, # including repository dependencies that may not be installed. @@ -125,7 +127,7 @@ # Discover all repository dependencies and retrieve information for installing them. Even if the user elected # to not install repository dependencies we have to make sure all repository dependency objects exist so that # the appropriate repository dependency relationships can be built. - all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( trans, tool_shed_url, repo_info_dicts ) + all_required_repo_info_dict = common_install_util.get_required_repo_info_dicts( app, tool_shed_url, repo_info_dicts ) all_repo_info_dicts = all_required_repo_info_dict.get( 'all_repo_info_dicts', [] ) if not all_repo_info_dicts: # No repository dependencies were discovered so process the received repositories. @@ -142,14 +144,14 @@ suc.get_repo_info_tuple_contents( repo_info_tuple ) # See if the repository has an existing record in the database. repository_db_record, installed_changeset_revision = \ - suc.repository_was_previously_installed( trans, tool_shed_url, name, repo_info_tuple, from_tip=False ) + suc.repository_was_previously_installed( app, tool_shed_url, name, repo_info_tuple, from_tip=False ) if repository_db_record: - if repository_db_record.status in [ trans.install_model.ToolShedRepository.installation_status.INSTALLED, - trans.install_model.ToolShedRepository.installation_status.CLONING, - trans.install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS, - trans.install_model.ToolShedRepository.installation_status.INSTALLING_REPOSITORY_DEPENDENCIES, - trans.install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES, - trans.install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES ]: + if repository_db_record.status in [ install_model.ToolShedRepository.installation_status.INSTALLED, + install_model.ToolShedRepository.installation_status.CLONING, + install_model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS, + install_model.ToolShedRepository.installation_status.INSTALLING_REPOSITORY_DEPENDENCIES, + install_model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES, + install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES ]: debug_msg = "Skipping installation of revision %s of repository '%s' because it was installed " % \ ( str( changeset_revision ), str( repository_db_record.name ) ) debug_msg += "with the (possibly updated) revision %s and its current installation status is '%s'." % \ @@ -157,26 +159,26 @@ log.debug( debug_msg ) can_update_db_record = False else: - if repository_db_record.status in [ trans.install_model.ToolShedRepository.installation_status.ERROR, - trans.install_model.ToolShedRepository.installation_status.NEW, - trans.install_model.ToolShedRepository.installation_status.UNINSTALLED ]: + if repository_db_record.status in [ install_model.ToolShedRepository.installation_status.ERROR, + install_model.ToolShedRepository.installation_status.NEW, + install_model.ToolShedRepository.installation_status.UNINSTALLED ]: # The current tool shed repository is not currently installed, so we can update its record in the database. name = repository_db_record.name installed_changeset_revision = repository_db_record.installed_changeset_revision metadata_dict = repository_db_record.metadata dist_to_shed = repository_db_record.dist_to_shed can_update_db_record = True - elif repository_db_record.status in [ trans.install_model.ToolShedRepository.installation_status.DEACTIVATED ]: + elif repository_db_record.status in [ install_model.ToolShedRepository.installation_status.DEACTIVATED ]: # The current tool shed repository is deactivated, so updating its database record is not necessary - just activate it. log.debug( "Reactivating deactivated tool_shed_repository '%s'." % str( repository_db_record.name ) ) - common_install_util.activate_repository( trans, repository_db_record ) + common_install_util.activate_repository( app, repository_db_record ) # No additional updates to the database record are necessary. can_update_db_record = False - elif repository_db_record.status not in [ trans.install_model.ToolShedRepository.installation_status.NEW ]: + elif repository_db_record.status not in [ install_model.ToolShedRepository.installation_status.NEW ]: # Set changeset_revision here so suc.create_or_update_tool_shed_repository will find the previously installed # and uninstalled repository instead of creating a new record. changeset_revision = repository_db_record.installed_changeset_revision - suc.reset_previously_installed_repository( trans, repository_db_record ) + suc.reset_previously_installed_repository( install_model, repository_db_record ) can_update_db_record = True else: # No record exists in the database for the repository currently being processed. @@ -189,7 +191,7 @@ # to see where it was previously located in the tool panel. if repository_db_record and repository_db_record.metadata: tool_section, tool_panel_section_key = \ - tool_util.handle_tool_panel_selection( trans=trans, + tool_util.handle_tool_panel_selection( toolbox=app.toolbox, metadata=repository_db_record.metadata, no_changes_checked=no_changes_checked, tool_panel_section_id=tool_panel_section_id, @@ -197,18 +199,18 @@ else: # We're installing a new tool shed repository that does not yet have a database record. tool_panel_section_key, tool_section = \ - tool_util.handle_tool_panel_section( trans, + tool_util.handle_tool_panel_section( app.toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) tool_shed_repository = \ - suc.create_or_update_tool_shed_repository( app=trans.app, + suc.create_or_update_tool_shed_repository( app=app, name=name, description=description, installed_changeset_revision=installed_changeset_revision, ctx_rev=ctx_rev, repository_clone_url=repository_clone_url, metadata_dict={}, - status=trans.install_model.ToolShedRepository.installation_status.NEW, + status=install_model.ToolShedRepository.installation_status.NEW, current_changeset_revision=changeset_revision, owner=repository_owner, dist_to_shed=False ) @@ -222,7 +224,7 @@ tool_panel_section_keys.append( tool_panel_section_key ) filtered_repo_info_dicts.append( repo_info_dict ) # Build repository dependency relationships even if the user chose to not install repository dependencies. - build_repository_dependency_relationships( trans, all_repo_info_dicts, all_created_or_updated_tool_shed_repositories ) + build_repository_dependency_relationships( app, all_repo_info_dicts, all_created_or_updated_tool_shed_repositories ) return created_or_updated_tool_shed_repositories, tool_panel_section_keys, all_repo_info_dicts, filtered_repo_info_dicts def generate_message_for_invalid_repository_dependencies( metadata_dict, error_from_tuple=False ): @@ -344,9 +346,9 @@ prior_installation_required, only_if_compiling_contained_td ) -def get_repository_dependency_by_repository_id( trans, decoded_repository_id ): - return trans.install_model.context.query( trans.install_model.RepositoryDependency ) \ - .filter( trans.install_model.RepositoryDependency.table.c.tool_shed_repository_id == decoded_repository_id ) \ +def get_repository_dependency_by_repository_id( install_model, decoded_repository_id ): + return install_model.context.query( install_model.RepositoryDependency ) \ + .filter( install_model.RepositoryDependency.table.c.tool_shed_repository_id == decoded_repository_id ) \ .first() def get_repository_dependencies_for_installed_tool_shed_repository( trans, repository ): diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/tool_shed/util/shed_util_common.py --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -571,27 +571,28 @@ continue return key -def get_or_create_tool_shed_repository( trans, tool_shed, name, owner, changeset_revision ): +def get_or_create_tool_shed_repository( app, tool_shed, name, owner, changeset_revision ): """ Return a tool shed repository database record defined by the combination of tool shed, repository name, repository owner and changeset_revision or installed_changeset_revision. A new tool shed repository record will be created if one is not located. """ + install_model = app.install_model # We store the port in the database. tool_shed = common_util.remove_protocol_from_tool_shed_url( tool_shed ) # This method is used only in Galaxy, not the tool shed. - repository = get_repository_for_dependency_relationship( trans.app, tool_shed, name, owner, changeset_revision ) + repository = get_repository_for_dependency_relationship( app, tool_shed, name, owner, changeset_revision ) if not repository: - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed ) repository_clone_url = os.path.join( tool_shed_url, 'repos', owner, name ) - ctx_rev = get_ctx_rev( trans.app, tool_shed_url, name, owner, changeset_revision ) - repository = create_or_update_tool_shed_repository( app=trans.app, + ctx_rev = get_ctx_rev( app, tool_shed_url, name, owner, changeset_revision ) + repository = create_or_update_tool_shed_repository( app=app, name=name, description=None, installed_changeset_revision=changeset_revision, ctx_rev=ctx_rev, repository_clone_url=repository_clone_url, metadata_dict={}, - status=trans.install_model.ToolShedRepository.installation_status.NEW, + status=install_model.ToolShedRepository.installation_status.NEW, current_changeset_revision=None, owner=owner, dist_to_shed=False ) @@ -616,7 +617,7 @@ sorted_changeset_revisions = [ str( changeset_tup[ 1 ] ) for changeset_tup in sorted_changeset_tups ] return sorted_changeset_revisions -def get_prior_import_or_install_required_dict( trans, tsr_ids, repo_info_dicts ): +def get_prior_import_or_install_required_dict( app, tsr_ids, repo_info_dicts ): """ This method is used in the Tool Shed when exporting a repository and its dependencies, and in Galaxy when a repository and its dependencies are being installed. Return a dictionary whose keys are the received tsr_ids and whose values are a list of tsr_ids, each of which is contained @@ -628,13 +629,13 @@ prior_import_or_install_required_dict[ tsr_id ] = [] # Inspect the repository dependencies for each repository about to be installed and populate the dictionary. for repo_info_dict in repo_info_dicts: - repository, repository_dependencies = get_repository_and_repository_dependencies_from_repo_info_dict( trans, repo_info_dict ) + repository, repository_dependencies = get_repository_and_repository_dependencies_from_repo_info_dict( app, repo_info_dict ) if repository: - encoded_repository_id = trans.security.encode_id( repository.id ) + encoded_repository_id = app.security.encode_id( repository.id ) if encoded_repository_id in tsr_ids: # We've located the database table record for one of the repositories we're about to install, so find out if it has any repository # dependencies that require prior installation. - prior_import_or_install_ids = get_repository_ids_requiring_prior_import_or_install( trans, tsr_ids, repository_dependencies ) + prior_import_or_install_ids = get_repository_ids_requiring_prior_import_or_install( app, tsr_ids, repository_dependencies ) prior_import_or_install_required_dict[ encoded_repository_id ] = prior_import_or_install_ids return prior_import_or_install_required_dict @@ -707,23 +708,24 @@ description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = repo_info_tuple return description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies -def get_repository_and_repository_dependencies_from_repo_info_dict( trans, repo_info_dict ): +def get_repository_and_repository_dependencies_from_repo_info_dict( app, repo_info_dict ): """Return a tool_shed_repository or repository record defined by the information in the received repo_info_dict.""" repository_name = repo_info_dict.keys()[ 0 ] repo_info_tuple = repo_info_dict[ repository_name ] description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = \ get_repo_info_tuple_contents( repo_info_tuple ) - if trans.webapp.name == 'galaxy': + if hasattr( app, "install_model" ): + # In a tool shed client (Galaxy, or something install repositories like Galaxy) tool_shed = get_tool_shed_from_clone_url( repository_clone_url ) - repository = get_repository_for_dependency_relationship( trans.app, tool_shed, repository_name, repository_owner, changeset_revision ) + repository = get_repository_for_dependency_relationship( app, tool_shed, repository_name, repository_owner, changeset_revision ) else: # We're in the tool shed. - repository = get_repository_by_name_and_owner( trans.app, repository_name, repository_owner ) + repository = get_repository_by_name_and_owner( app, repository_name, repository_owner ) return repository, repository_dependencies def get_repository_by_id( trans, id ): """Get a repository from the database via id.""" - if trans.webapp.name == 'galaxy': + if is_tool_shed_client( trans.app ): return trans.install_model.context.query( trans.install_model.ToolShedRepository ).get( trans.security.decode_id( id ) ) else: return trans.sa_session.query( trans.model.Repository ).get( trans.security.decode_id( id ) ) @@ -731,15 +733,12 @@ def get_repository_by_name( app, name ): """Get a repository from the database via name.""" repository_query = get_repository_query( app ) - if app.name == 'galaxy': - return repository_query.filter_by( name=name ).first() - else: - return repository_query.filter_by( name=name ).first() + return repository_query.filter_by( name=name ).first() def get_repository_by_name_and_owner( app, name, owner ): """Get a repository from the database via name and owner""" repository_query = get_repository_query( app ) - if app.name == 'galaxy': + if is_tool_shed_client( app ): return repository_query \ .filter( and_( app.install_model.ToolShedRepository.table.c.name == name, app.install_model.ToolShedRepository.table.c.owner == owner ) ) \ @@ -884,7 +883,7 @@ # This should never be reached - raise an exception? return v, None -def get_repository_ids_requiring_prior_import_or_install( trans, tsr_ids, repository_dependencies ): +def get_repository_ids_requiring_prior_import_or_install( app, tsr_ids, repository_dependencies ): """ This method is used in the Tool Shed when exporting a repository and its dependencies, and in Galaxy when a repository and its dependencies are being installed. Inspect the received repository_dependencies and determine if the encoded id of each required repository is in the received @@ -908,14 +907,14 @@ # dependency. if not asbool( only_if_compiling_contained_td ): if asbool( prior_installation_required ): - if trans.webapp.name == 'galaxy': + if is_tool_shed_client( app ): # We store the port, if one exists, in the database. tool_shed = common_util.remove_protocol_from_tool_shed_url( tool_shed ) - repository = get_repository_for_dependency_relationship( trans.app, tool_shed, name, owner, changeset_revision ) + repository = get_repository_for_dependency_relationship( app, tool_shed, name, owner, changeset_revision ) else: - repository = get_repository_by_name_and_owner( trans.app, name, owner ) + repository = get_repository_by_name_and_owner( app, name, owner ) if repository: - encoded_repository_id = trans.security.encode_id( repository.id ) + encoded_repository_id = app.security.encode_id( repository.id ) if encoded_repository_id in tsr_ids: prior_tsr_ids.append( encoded_repository_id ) return prior_tsr_ids @@ -963,7 +962,7 @@ return get_repository_owner( tmp_url ) def get_repository_query( app ): - if app.name == "galaxy": + if is_tool_shed_client( app ): query = app.install_model.context.query( app.install_model.ToolShedRepository ) else: query = app.model.context.query( app.model.Repository ) @@ -1315,17 +1314,27 @@ except Exception, e: log.exception( "An error occurred sending a tool shed repository update alert by email." ) -def have_shed_tool_conf_for_install( trans ): - if not trans.app.toolbox.shed_tool_confs: +def have_shed_tool_conf_for_install( app ): + if not app.toolbox.shed_tool_confs: return False - migrated_tools_conf_path, migrated_tools_conf_name = os.path.split( trans.app.config.migrated_tools_config ) - for shed_tool_conf_dict in trans.app.toolbox.shed_tool_confs: + migrated_tools_conf_path, migrated_tools_conf_name = os.path.split( app.config.migrated_tools_config ) + for shed_tool_conf_dict in app.toolbox.shed_tool_confs: shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ] shed_tool_conf_path, shed_tool_conf_name = os.path.split( shed_tool_conf ) if shed_tool_conf_name != migrated_tools_conf_name: return True return False + +def is_tool_shed_client( app ): + """ The tool shed and clients to the tool (i.e. Galaxy) require a lot + of similar functionality in this file but with small differences. This + method should determine if the app performing the action is the tool shed + or a client of the tool shed. + """ + return hasattr( app, "install_model" ) + + def open_repository_files_folder( trans, folder_path ): """ Return a list of dictionaries, each of which contains information for a file or directory contained @@ -1352,7 +1361,7 @@ folder_contents.append( node ) return folder_contents -def repository_was_previously_installed( trans, tool_shed_url, repository_name, repo_info_tuple, from_tip=False ): +def repository_was_previously_installed( app, tool_shed_url, repository_name, repo_info_tuple, from_tip=False ): """ Find out if a repository is already installed into Galaxy - there are several scenarios where this is necessary. For example, this method will handle the case where the repository was previously @@ -1361,12 +1370,12 @@ updating the one that was previously installed. We'll look in the database instead of on disk since the repository may be currently uninstalled. """ - tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( trans.app, tool_shed_url ) + tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry( app, tool_shed_url ) description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies = \ get_repo_info_tuple_contents( repo_info_tuple ) tool_shed = get_tool_shed_from_clone_url( repository_clone_url ) # See if we can locate the repository using the value of changeset_revision. - tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( trans.app, + tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( app, tool_shed, repository_name, repository_owner, @@ -1382,11 +1391,11 @@ str( from_tip ) ) url = common_util.url_join( tool_shed_url, 'repository/previous_changeset_revisions%s' % params ) - text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + text = common_util.tool_shed_get( app, tool_shed_url, url ) if text: changeset_revisions = util.listify( text ) for previous_changeset_revision in changeset_revisions: - tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( trans.app, + tool_shed_repository = get_tool_shed_repository_by_shed_name_owner_installed_changeset_revision( app, tool_shed, repository_name, repository_owner, @@ -1395,7 +1404,7 @@ return tool_shed_repository, previous_changeset_revision return None, None -def reset_previously_installed_repository( trans, repository ): +def reset_previously_installed_repository( install_model, repository ): """ Reset the atrributes of a tool_shed_repository that was previsouly installed. The repository will be in some state other than INSTALLED, so all atributes will be set to the default NEW state. This will enable the repository to be freshly installed. @@ -1411,10 +1420,10 @@ repository.deleted = False repository.tool_shed_status = None repository.uninstalled = False - repository.status = trans.install_model.ToolShedRepository.installation_status.NEW + repository.status = install_model.ToolShedRepository.installation_status.NEW repository.error_message = None - trans.install_model.context.add( repository ) - trans.install_model.context.flush() + install_model.context.add( repository ) + install_model.context.flush() def set_image_paths( app, encoded_repository_id, text ): """ @@ -1423,7 +1432,7 @@ the caller to open the file. """ if text: - if app.name == 'galaxy': + if is_tool_shed_client( app ): route_to_images = 'admin_toolshed/static/images/%s' % encoded_repository_id else: # We're in the tool shed. diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/tool_shed/util/tool_dependency_util.py --- a/lib/tool_shed/util/tool_dependency_util.py +++ b/lib/tool_shed/util/tool_dependency_util.py @@ -617,7 +617,7 @@ tool_dependencies=tool_dependencies ) # The required_repository may have been installed with a different changeset revision. required_repository, installed_changeset_revision = \ - suc.repository_was_previously_installed( trans, tool_shed_url, name, repo_info_tuple, from_tip=False ) + suc.repository_was_previously_installed( trans.app, tool_shed_url, name, repo_info_tuple, from_tip=False ) if required_repository: required_repository_installed_tool_dependencies, required_repository_missing_tool_dependencies = \ get_installed_and_missing_tool_dependencies_for_installed_repository( trans, required_repository, tool_dependencies ) diff -r 411d8fb07181e3599ddb54d4924876fa846979c1 -r 5884328e91724e9bdf4b43f012eb63fa0c803ef6 lib/tool_shed/util/tool_util.py --- a/lib/tool_shed/util/tool_util.py +++ b/lib/tool_shed/util/tool_util.py @@ -467,14 +467,14 @@ fh.close() return sample_files, deleted_sample_files -def get_or_create_tool_section( trans, tool_panel_section_id, new_tool_panel_section_label=None ): +def get_or_create_tool_section( toolbox, tool_panel_section_id, new_tool_panel_section_label=None ): tool_panel_section_key = str( tool_panel_section_id ) - if tool_panel_section_key in trans.app.toolbox.tool_panel: - # Appending a tool to an existing section in trans.app.toolbox.tool_panel - tool_section = trans.app.toolbox.tool_panel[ tool_panel_section_key ] + if tool_panel_section_key in toolbox.tool_panel: + # Appending a tool to an existing section in toolbox.tool_panel + tool_section = toolbox.tool_panel[ tool_panel_section_key ] log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) ) else: - # Appending a new section to trans.app.toolbox.tool_panel + # Appending a new section to toolbox.tool_panel if new_tool_panel_section_label is None: # This might add an ugly section label to the tool panel, but, oh well... new_tool_panel_section_label = tool_panel_section_id @@ -483,7 +483,7 @@ elem.attrib[ 'id' ] = tool_panel_section_id elem.attrib[ 'version' ] = '' tool_section = galaxy.tools.ToolSection( elem ) - trans.app.toolbox.tool_panel[ tool_panel_section_key ] = tool_section + toolbox.tool_panel[ tool_panel_section_key ] = tool_section log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) ) return tool_panel_section_key, tool_section @@ -669,7 +669,7 @@ error = True return error, message -def handle_tool_panel_selection( trans, metadata, no_changes_checked, tool_panel_section_id, new_tool_panel_section_label ): +def handle_tool_panel_selection( toolbox, metadata, no_changes_checked, tool_panel_section_id, new_tool_panel_section_label ): """ Handle the selected tool panel location for loading tools included in tool shed repositories when installing or reinstalling them. @@ -697,17 +697,17 @@ original_section_name = tool_section_dict[ 'name' ] if original_section_id: tool_panel_section_key, tool_section = \ - get_or_create_tool_section( trans, + get_or_create_tool_section( toolbox, tool_panel_section_id=original_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) else: # The user elected to change the tool panel section to contain the tools. - tool_panel_section_key, tool_section = handle_tool_panel_section( trans, + tool_panel_section_key, tool_section = handle_tool_panel_section( toolbox, tool_panel_section_id=tool_panel_section_id, new_tool_panel_section_label=new_tool_panel_section_label ) return tool_section, tool_panel_section_key -def handle_tool_panel_section( trans, tool_panel_section_id=None, new_tool_panel_section_label=None ): +def handle_tool_panel_section( toolbox, tool_panel_section_id=None, new_tool_panel_section_label=None ): """Return a ToolSection object retrieved from the current in-memory tool_panel.""" # If tool_panel_section_id is received, the section exists in the tool panel. In this case, the value of the # received tool_panel_section_id must be the id retrieved from a tool panel config (e.g., tool_conf.xml, which @@ -715,12 +715,12 @@ if new_tool_panel_section_label: section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) ) tool_panel_section_key, tool_section = \ - get_or_create_tool_section( trans, + get_or_create_tool_section( toolbox, tool_panel_section_id=section_id, new_tool_panel_section_label=new_tool_panel_section_label ) elif tool_panel_section_id: tool_panel_section_key = str( tool_panel_section_id ) - tool_section = trans.app.toolbox.tool_panel[ tool_panel_section_key ] + tool_section = toolbox.tool_panel[ tool_panel_section_key ] else: return None, None return tool_panel_section_key, tool_section Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.