1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/cd5d9bf32d86/ Changeset: cd5d9bf32d86 User: greg Date: 2014-07-18 20:41:44 Summary: As much as possible, eliminate the use of trans in the tool shed's tool_util.py module. Affected #: 4 files diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 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 @@ -244,7 +244,10 @@ if kwd.get( 'deactivate_or_uninstall_repository_button', False ): if tool_shed_repository.includes_tools_for_display_in_tool_panel: # Handle tool panel alterations. - tool_util.remove_from_tool_panel( trans, tool_shed_repository, shed_tool_conf, uninstall=remove_from_disk_checked ) + tool_util.remove_from_tool_panel( trans.app, + tool_shed_repository, + shed_tool_conf, + uninstall=remove_from_disk_checked ) if tool_shed_repository.includes_data_managers: data_manager_util.remove_from_data_manager( trans.app, tool_shed_repository ) if tool_shed_repository.includes_datatypes: @@ -1116,9 +1119,9 @@ return trans.response.send_redirect( web.url_for( controller='admin_toolshed', action='manage_repositories', **kwd ) ) - shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans ) + shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans.app ) tool_path = suc.get_tool_path_by_shed_tool_conf_filename( trans.app, shed_tool_conf ) - tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans ) + tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans.app ) if len( repo_info_dicts ) == 1: # If we're installing or updating a single repository, see if it contains a readme or # dependencies that we can display. @@ -1636,7 +1639,7 @@ original_section_name = '' else: original_section_name = '' - tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans ) + tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans.app ) no_changes_check_box = CheckboxField( 'no_changes', checked=True ) if original_section_name: message += "The tools contained in your <b>%s</b> repository were last loaded into the tool panel section <b>%s</b>. " \ @@ -1652,7 +1655,7 @@ no_changes_check_box = None original_section_name = '' tool_panel_section_select_field = None - shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans ) + shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans.app ) dd = dependency_display.DependencyDisplayer( trans.app ) containers_dict = \ dd.populate_containers_dict_for_new_install( tool_shed_url=tool_shed_url, diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 lib/galaxy/webapps/tool_shed/controllers/repository.py --- a/lib/galaxy/webapps/tool_shed/controllers/repository.py +++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py @@ -1164,7 +1164,10 @@ message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'done' ) render_repository_actions_for = kwd.get( 'render_repository_actions_for', 'tool_shed' ) - repository, tool, message = tool_util.load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config ) + repository, tool, message = tool_util.load_tool_from_changeset_revision( trans.app, + repository_id, + changeset_revision, + tool_config ) if message: status = 'error' tool_state = tool_util.new_state( trans, tool, invalid=False ) @@ -2144,7 +2147,10 @@ message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'error' ) render_repository_actions_for = kwd.get( 'render_repository_actions_for', 'tool_shed' ) - repository, tool, error_message = tool_util.load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config ) + repository, tool, error_message = tool_util.load_tool_from_changeset_revision( trans.app, + repository_id, + changeset_revision, + tool_config ) tool_state = tool_util.new_state( trans, tool, invalid=True ) invalid_file_tups = [] if tool: @@ -3398,7 +3404,7 @@ guid = tool_metadata_dict[ 'guid' ] full_path_to_tool_config = os.path.abspath( relative_path_to_tool_config ) full_path_to_dir, tool_config_filename = os.path.split( full_path_to_tool_config ) - can_use_disk_file = tool_util.can_use_tool_config_disk_file( trans, + can_use_disk_file = tool_util.can_use_tool_config_disk_file( trans.app, repository, repo, full_path_to_tool_config, @@ -3406,7 +3412,7 @@ if can_use_disk_file: trans.app.config.tool_data_path = work_dir tool, valid, message, sample_files = \ - tool_util.handle_sample_files_and_load_tool_from_disk( trans, + tool_util.handle_sample_files_and_load_tool_from_disk( trans.app, repo_files_dir, repository_id, full_path_to_tool_config, @@ -3415,7 +3421,7 @@ status = 'error' else: tool, message, sample_files = \ - tool_util.handle_sample_files_and_load_tool_from_tmp_config( trans, + tool_util.handle_sample_files_and_load_tool_from_tmp_config( trans.app, repo, repository_id, changeset_revision, diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 lib/tool_shed/util/tool_util.py --- a/lib/tool_shed/util/tool_util.py +++ b/lib/tool_shed/util/tool_util.py @@ -65,7 +65,10 @@ if config_elem.tag == 'section': app.toolbox.load_section_tag_set( config_elem, tool_path, load_panel_dict=True ) elif config_elem.tag == 'workflow': - app.toolbox.load_workflow_tag_set( config_elem, app.toolbox.tool_panel, app.toolbox.integrated_tool_panel, load_panel_dict=True ) + app.toolbox.load_workflow_tag_set( config_elem, + app.toolbox.tool_panel, + app.toolbox.integrated_tool_panel, + load_panel_dict=True ) elif config_elem.tag == 'tool': guid = config_elem.get( 'guid' ) app.toolbox.load_tool_tag_set( config_elem, @@ -82,12 +85,12 @@ app.toolbox.write_integrated_tool_panel_config_file() app.toolbox_search = ToolBoxSearch( app.toolbox ) -def build_shed_tool_conf_select_field( trans ): - """Build a SelectField whose options are the keys in trans.app.toolbox.shed_tool_confs.""" +def build_shed_tool_conf_select_field( app ): + """Build a SelectField whose options are the keys in app.toolbox.shed_tool_confs.""" options = [] - for shed_tool_conf_dict in trans.app.toolbox.shed_tool_confs: + for shed_tool_conf_dict in app.toolbox.shed_tool_confs: shed_tool_conf_filename = shed_tool_conf_dict[ 'config_filename' ] - if shed_tool_conf_filename != trans.app.config.migrated_tools_config: + if shed_tool_conf_filename != app.config.migrated_tools_config: if shed_tool_conf_filename.startswith( './' ): option_label = shed_tool_conf_filename.replace( './', '', 1 ) else: @@ -98,10 +101,10 @@ select_field.add_option( option_tup[ 0 ], option_tup[ 1 ] ) return select_field -def build_tool_panel_section_select_field( trans ): +def build_tool_panel_section_select_field( app ): """Build a SelectField whose options are the sections of the current in-memory toolbox.""" options = [] - for k, v in trans.app.toolbox.tool_panel.items(): + for k, v in app.toolbox.tool_panel.items(): if isinstance( v, galaxy.tools.ToolSection ): options.append( ( v.name, v.id ) ) select_field = SelectField( name='tool_panel_section_id', display='radio' ) @@ -109,19 +112,23 @@ select_field.add_option( option_tup[ 0 ], option_tup[ 1 ] ) return select_field -def can_use_tool_config_disk_file( trans, repository, repo, file_path, changeset_revision ): +def can_use_tool_config_disk_file( app, repository, repo, file_path, changeset_revision ): """ - Determine if repository's tool config file on disk can be used. This method is restricted to tool config files since, with the - exception of tool config files, multiple files with the same name will likely be in various directories in the repository and we're - comparing file names only (not relative paths). + Determine if repository's tool config file on disk can be used. This method + is restricted to tool config files since, with the exception of tool config + files, multiple files with the same name will likely be in various directories + in the repository and we're comparing file names only (not relative paths). """ if not file_path or not os.path.exists( file_path ): - # The file no longer exists on disk, so it must have been deleted at some previous point in the change log. + # The file no longer exists on disk, so it must have been deleted at some previous + # point in the change log. return False - if changeset_revision == repository.tip( trans.app ): + if changeset_revision == repository.tip( app ): return True file_name = basic_util.strip_path( file_path ) - latest_version_of_file = get_latest_tool_config_revision_from_repository_manifest( repo, file_name, changeset_revision ) + latest_version_of_file = get_latest_tool_config_revision_from_repository_manifest( repo, + file_name, + changeset_revision ) can_use_disk_file = filecmp.cmp( file_path, latest_version_of_file ) try: os.unlink( latest_version_of_file ) @@ -131,14 +138,15 @@ def check_tool_input_params( app, repo_dir, tool_config_name, tool, sample_files ): """ - Check all of the tool's input parameters, looking for any that are dynamically generated using external data files to make - sure the files exist. + Check all of the tool's input parameters, looking for any that are dynamically + generated using external data files to make sure the files exist. """ invalid_files_and_errors_tups = [] correction_msg = '' for input_param in tool.input_params: if isinstance( input_param, parameters.basic.SelectToolParameter ) and input_param.is_dynamic: - # If the tool refers to .loc files or requires an entry in the tool_data_table_conf.xml, make sure all requirements exist. + # If the tool refers to .loc files or requires an entry in the tool_data_table_conf.xml, + # make sure all requirements exist. options = input_param.dynamic_options or input_param.options if options and isinstance( options, dynamic_options.DynamicOptions ): if options.tool_data_table or options.missing_tool_data_table_name: @@ -151,8 +159,9 @@ else: options.missing_tool_data_table_name = None else: - correction_msg = "This file requires an entry in the tool_data_table_conf.xml file. Upload a file named tool_data_table_conf.xml.sample " - correction_msg += "to the repository that includes the required entry to correct this error.<br/>" + correction_msg = "This file requires an entry in the tool_data_table_conf.xml file. " + correction_msg += "Upload a file named tool_data_table_conf.xml.sample to the repository " + correction_msg += "that includes the required entry to correct this error.<br/>" invalid_tup = ( tool_config_name, correction_msg ) if invalid_tup not in invalid_files_and_errors_tups: invalid_files_and_errors_tups.append( invalid_tup ) @@ -172,7 +181,8 @@ break if not sample_found: correction_msg = "This file refers to a file named <b>%s</b>. " % str( index_file_name ) - correction_msg += "Upload a file named <b>%s.sample</b> to the repository to correct this error." % str( index_file_name ) + correction_msg += "Upload a file named <b>%s.sample</b> to the repository to correct this error." % \ + str( index_file_name ) invalid_files_and_errors_tups.append( ( tool_config_name, correction_msg ) ) return invalid_files_and_errors_tups @@ -188,15 +198,18 @@ message = '' return message -def copy_disk_sample_files_to_dir( trans, repo_files_dir, dest_path ): - """Copy all files currently on disk that end with the .sample extension to the directory to which dest_path refers.""" +def copy_disk_sample_files_to_dir( app, repo_files_dir, dest_path ): + """ + Copy all files currently on disk that end with the .sample extension to the + directory to which dest_path refers. + """ sample_files = [] for root, dirs, files in os.walk( repo_files_dir ): if root.find( '.hg' ) < 0: for name in files: if name.endswith( '.sample' ): relative_path = os.path.join( root, name ) - copy_sample_file( trans.app, relative_path, dest_path=dest_path ) + copy_sample_file( app, relative_path, dest_path=dest_path ) sample_files.append( name ) return sample_files @@ -239,7 +252,8 @@ if is_data_index_sample_file( filename ): copy_sample_file( app, filename, dest_path=dest_path ) -def generate_message_for_invalid_tools( app, invalid_file_tups, repository, metadata_dict, as_html=True, displaying_invalid_tool=False ): +def generate_message_for_invalid_tools( app, invalid_file_tups, repository, metadata_dict, as_html=True, + displaying_invalid_tool=False ): if as_html: new_line = '<br/>' bold_start = '<b>' @@ -270,8 +284,10 @@ sample_ext = '%s.sample' % missing_file else: sample_ext = missing_file - correction_msg = "This file refers to a missing file %s%s%s. " % ( bold_start, str( missing_file ), bold_end ) - correction_msg += "Upload a file named %s%s%s to the repository to correct this error." % ( bold_start, sample_ext, bold_end ) + correction_msg = "This file refers to a missing file %s%s%s. " % \ + ( bold_start, str( missing_file ), bold_end ) + correction_msg += "Upload a file named %s%s%s to the repository to correct this error." % \ + ( bold_start, sample_ext, bold_end ) else: if as_html: correction_msg = exception_msg @@ -282,8 +298,8 @@ def generate_tool_panel_dict_for_new_install( tool_dicts, tool_section=None ): """ - When installing a repository that contains tools, all tools must currently be defined within the same tool section in the tool - panel or outside of any sections. + When installing a repository that contains tools, all tools must currently be defined + within the same tool section in the tool panel or outside of any sections. """ tool_panel_dict = {} if tool_section: @@ -307,10 +323,15 @@ def generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=None ): """ - Create a dictionary of the following type for a single tool config file name. The intent is to call this method for every tool config - in a repository and append each of these as entries to a tool panel dictionary for the repository. This allows for each tool to be - loaded into a different section in the tool panel. - {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} + Create a dictionary of the following type for a single tool config file name. + The intent is to call this method for every tool config in a repository and + append each of these as entries to a tool panel dictionary for the repository. + This allows for each tool to be loaded into a different section in the tool panel. + {<Tool guid> : + [{ tool_config : <tool_config_file>, + id: <ToolSection id>, + version : <ToolSection version>, + name : <TooSection name>}]} """ tool_panel_dict = {} file_name = basic_util.strip_path( tool_config ) @@ -318,7 +339,8 @@ tool_panel_dict[ guid ] = tool_section_dicts return tool_panel_dict -def generate_tool_panel_elem_list( repository_name, repository_clone_url, changeset_revision, tool_panel_dict, repository_tools_tups, owner='' ): +def generate_tool_panel_elem_list( repository_name, repository_clone_url, changeset_revision, tool_panel_dict, + repository_tools_tups, owner='' ): """Generate a list of ElementTree Element objects for each section or tool.""" elem_list = [] tool_elem = None @@ -349,9 +371,21 @@ if tup_guid == guid: break if inside_section: - tool_elem = suc.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, tool_section ) + tool_elem = suc.generate_tool_elem( tool_shed, + repository_name, + changeset_revision, + owner, + tool_file_path, + tool, + tool_section ) else: - tool_elem = suc.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, None ) + tool_elem = suc.generate_tool_elem( tool_shed, + repository_name, + changeset_revision, + owner, + tool_file_path, + tool, + None ) if inside_section: if section_in_elem_list: elem_list[ index ] = tool_section @@ -367,7 +401,8 @@ tool_config = '' if tool_sections: for tool_section in tool_sections: - # The value of tool_section will be None if the tool is displayed outside of any sections in the tool panel. + # The value of tool_section will be None if the tool is displayed outside + # of any sections in the tool panel. if tool_section: section_id = tool_section.id or '' section_version = tool_section.version or '' @@ -376,7 +411,10 @@ section_id = '' section_version = '' section_name = '' - tool_section_dicts.append( dict( tool_config=tool_config, id=section_id, version=section_version, name=section_name ) ) + tool_section_dicts.append( dict( tool_config=tool_config, + id=section_id, + version=section_version, + name=section_name ) ) else: tool_section_dicts.append( dict( tool_config=tool_config, id='', version='', name='' ) ) return tool_section_dicts @@ -409,9 +447,10 @@ def get_latest_tool_config_revision_from_repository_manifest( repo, filename, changeset_revision ): """ - Get the latest revision of a tool config file named filename from the repository manifest up to the value of changeset_revision. - This method is restricted to tool_config files rather than any file since it is likely that, with the exception of tool config files, - multiple files will have the same name in various directories within the repository. + Get the latest revision of a tool config file named filename from the repository + manifest up to the value of changeset_revision. This method is restricted to tool_config + files rather than any file since it is likely that, with the exception of tool config + files, multiple files will have the same name in various directories within the repository. """ stripped_filename = basic_util.strip_path( filename ) for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ): @@ -422,8 +461,9 @@ try: fctx = manifest_ctx[ ctx_file ] except LookupError: - # The ctx_file may have been moved in the change set. For example, 'ncbi_blastp_wrapper.xml' was moved to - # 'tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml', so keep looking for the file until we find the new location. + # The ctx_file may have been moved in the change set. For example, + # 'ncbi_blastp_wrapper.xml' was moved to 'tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml', + # so keep looking for the file until we find the new location. continue fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-gltcrfrm" ) tmp_filename = fh.name @@ -436,10 +476,12 @@ def get_list_of_copied_sample_files( repo, ctx, dir ): """ - Find all sample files (files in the repository with the special .sample extension) in the reversed repository manifest up to ctx. Copy - each discovered file to dir and return the list of filenames. If a .sample file was added in a changeset and then deleted in a later - changeset, it will be returned in the deleted_sample_files list. The caller will set the value of app.config.tool_data_path to dir in - order to load the tools and generate metadata for them. + Find all sample files (files in the repository with the special .sample extension) + in the reversed repository manifest up to ctx. Copy each discovered file to dir and + return the list of filenames. If a .sample file was added in a changeset and then + deleted in a later changeset, it will be returned in the deleted_sample_files list. + The caller will set the value of app.config.tool_data_path to dir in order to load + the tools and generate metadata for them. """ deleted_sample_files = [] sample_files = [] @@ -447,16 +489,20 @@ changeset_ctx = repo.changectx( changeset ) for ctx_file in changeset_ctx.files(): ctx_file_name = basic_util.strip_path( ctx_file ) - # If we decide in the future that files deleted later in the changelog should not be used, we can use the following if statement. - # if ctx_file_name.endswith( '.sample' ) and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files: + # If we decide in the future that files deleted later in the changelog should + # not be used, we can use the following if statement. if ctx_file_name.endswith( '.sample' ) + # and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files: if ctx_file_name.endswith( '.sample' ) and ctx_file_name not in sample_files: fctx = hg_util.get_file_context_from_ctx( changeset_ctx, ctx_file ) if fctx in [ 'DELETED' ]: - # Since the possibly future used if statement above is commented out, the same file that was initially added will be - # discovered in an earlier changeset in the change log and fall through to the else block below. In other words, if - # a file named blast2go.loc.sample was added in change set 0 and then deleted in changeset 3, the deleted file in changeset - # 3 will be handled here, but the later discovered file in changeset 0 will be handled in the else block below. In this - # way, the file contents will always be found for future tools even though the file was deleted. + # Since the possibly future used if statement above is commented out, the + # same file that was initially added will be discovered in an earlier changeset + # in the change log and fall through to the else block below. In other words, + # if a file named blast2go.loc.sample was added in change set 0 and then deleted + # in changeset 3, the deleted file in changeset 3 will be handled here, but the + # later discovered file in changeset 0 will be handled in the else block below. + # In this way, the file contents will always be found for future tools even though + # the file was deleted. if ctx_file_name not in deleted_sample_files: deleted_sample_files.append( ctx_file_name ) else: @@ -522,14 +568,14 @@ """Return a ToolVersionAssociation if one exists that associates the two received tool_versions""" context = app.install_model.context return context.query( app.install_model.ToolVersionAssociation ) \ - .filter( and_( app.install_model.ToolVersionAssociation.table.c.parent_id == parent_tool_version.id, - app.install_model.ToolVersionAssociation.table.c.tool_id == tool_version.id ) ) \ - .first() + .filter( and_( app.install_model.ToolVersionAssociation.table.c.parent_id == parent_tool_version.id, + app.install_model.ToolVersionAssociation.table.c.tool_id == tool_version.id ) ) \ + .first() def get_version_lineage_for_tool( app, repository_id, repository_metadata, guid ): """ - Return the tool version lineage chain in descendant order for the received guid contained in the received - repsitory_metadata.tool_versions. + Return the tool version lineage chain in descendant order for the received + guid contained in the received repsitory_metadata.tool_versions. """ repository = suc.get_repository_by_id( app, repository_id ) repo = hg_util.get_repo_for_repository( app, repository=repository, repo_path=None, create=False ) @@ -563,9 +609,10 @@ def handle_missing_data_table_entry( app, relative_install_dir, tool_path, repository_tools_tups ): """ - Inspect each tool to see if any have input parameters that are dynamically generated select lists that require entries in the - tool_data_table_conf.xml file. This method is called only from Galaxy (not the tool shed) when a repository is being installed - or reinstalled. + Inspect each tool to see if any have input parameters that are dynamically + generated select lists that require entries in the tool_data_table_conf.xml + file. This method is called only from Galaxy (not the tool shed) when a + repository is being installed or reinstalled. """ missing_data_table_entry = False for index, repository_tools_tup in enumerate( repository_tools_tups ): @@ -574,7 +621,8 @@ missing_data_table_entry = True break if missing_data_table_entry: - # The repository must contain a tool_data_table_conf.xml.sample file that includes all required entries for all tools in the repository. + # The repository must contain a tool_data_table_conf.xml.sample file that includes + # all required entries for all tools in the repository. sample_tool_data_table_conf = hg_util.get_config_from_disk( 'tool_data_table_conf.xml.sample', relative_install_dir ) if sample_tool_data_table_conf: # Add entries to the ToolDataTableManager's in-memory data_tables dictionary. @@ -591,8 +639,9 @@ def handle_missing_index_file( app, tool_path, sample_files, repository_tools_tups, sample_files_copied ): """ - Inspect each tool to see if it has any input parameters that are dynamically generated select lists that depend on a .loc file. - This method is not called from the tool shed, but from Galaxy when a repository is being installed. + Inspect each tool to see if it has any input parameters that are dynamically + generated select lists that depend on a .loc file. This method is not called + from the tool shed, but from Galaxy when a repository is being installed. """ for index, repository_tools_tup in enumerate( repository_tools_tups ): tup_path, guid, repository_tool = repository_tools_tup @@ -615,53 +664,60 @@ repository_tools_tups[ index ] = ( tup_path, guid, repository_tool ) return repository_tools_tups, sample_files_copied -def handle_sample_files_and_load_tool_from_disk( trans, repo_files_dir, repository_id, tool_config_filepath, work_dir ): - # Copy all sample files from disk to a temporary directory since the sample files may be in multiple directories. +def handle_sample_files_and_load_tool_from_disk( app, repo_files_dir, repository_id, tool_config_filepath, work_dir ): + """ + Copy all sample files from disk to a temporary directory since the sample files may + be in multiple directories. + """ message = '' - sample_files = copy_disk_sample_files_to_dir( trans, repo_files_dir, work_dir ) + sample_files = copy_disk_sample_files_to_dir( app, repo_files_dir, work_dir ) if sample_files: if 'tool_data_table_conf.xml.sample' in sample_files: # Load entries into the tool_data_tables if the tool requires them. tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' ) - error, message = handle_sample_tool_data_table_conf_file( trans.app, tool_data_table_config ) - tool, valid, message2 = load_tool_from_config( trans.app, repository_id, tool_config_filepath ) + error, message = handle_sample_tool_data_table_conf_file( app, tool_data_table_config ) + tool, valid, message2 = load_tool_from_config( app, repository_id, tool_config_filepath ) message = concat_messages( message, message2 ) return tool, valid, message, sample_files -def handle_sample_files_and_load_tool_from_tmp_config( trans, repo, repository_id, changeset_revision, tool_config_filename, work_dir ): +def handle_sample_files_and_load_tool_from_tmp_config( app, repo, repository_id, changeset_revision, + tool_config_filename, work_dir ): tool = None message = '' ctx = hg_util.get_changectx_for_changeset( repo, changeset_revision ) - # We're not currently doing anything with the returned list of deleted_sample_files here. It is intended to help handle sample files that are in - # the manifest, but have been deleted from disk. + # We're not currently doing anything with the returned list of deleted_sample_files here. It is + # intended to help handle sample files that are in the manifest, but have been deleted from disk. sample_files, deleted_sample_files = get_list_of_copied_sample_files( repo, ctx, dir=work_dir ) if sample_files: - trans.app.config.tool_data_path = work_dir + app.config.tool_data_path = work_dir if 'tool_data_table_conf.xml.sample' in sample_files: # Load entries into the tool_data_tables if the tool requires them. tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' ) if tool_data_table_config: - error, message = handle_sample_tool_data_table_conf_file( trans.app, tool_data_table_config ) + error, message = handle_sample_tool_data_table_conf_file( app, tool_data_table_config ) if error: log.debug( message ) manifest_ctx, ctx_file = hg_util.get_ctx_file_path_from_manifest( tool_config_filename, repo, changeset_revision ) if manifest_ctx and ctx_file: - tool, message2 = load_tool_from_tmp_config( trans, repo, repository_id, manifest_ctx, ctx_file, work_dir ) + tool, message2 = load_tool_from_tmp_config( app, repo, repository_id, manifest_ctx, ctx_file, work_dir ) message = concat_messages( message, message2 ) return tool, message, sample_files def handle_sample_tool_data_table_conf_file( app, filename, persist=False ): """ - Parse the incoming filename and add new entries to the in-memory app.tool_data_tables dictionary. If persist is True (should only occur - if call is from the Galaxy side, not the tool shed), the new entries will be appended to Galaxy's shed_tool_data_table_conf.xml file on disk. + Parse the incoming filename and add new entries to the in-memory + app.tool_data_tables dictionary. If persist is True (should only occur + if call is from the Galaxy side, not the tool shed), the new entries will + be appended to Galaxy's shed_tool_data_table_conf.xml file on disk. """ error = False message = '' try: - new_table_elems, message = app.tool_data_tables.add_new_entries_from_config_file( config_filename=filename, - tool_data_path=app.config.tool_data_path, - shed_tool_data_table_config=app.config.shed_tool_data_table_config, - persist=persist ) + new_table_elems, message = \ + app.tool_data_tables.add_new_entries_from_config_file( config_filename=filename, + tool_data_path=app.config.tool_data_path, + shed_tool_data_table_config=app.config.shed_tool_data_table_config, + persist=persist ) if message: error = True except Exception, e: @@ -709,9 +765,10 @@ 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 - # may have getext). If new_tool_panel_section_label is received, a new section will be added to the 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 may have getext). If new_tool_panel_section_label + # is received, a new section will be added to the tool panel. if new_tool_panel_section_label: section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) ) tool_panel_section_key, tool_section = \ @@ -727,8 +784,9 @@ def handle_tool_versions( app, tool_version_dicts, tool_shed_repository ): """ - Using the list of tool_version_dicts retrieved from the tool shed (one per changeset revison up to the currently installed changeset revision), - create the parent / child pairs of tool versions. Each dictionary contains { tool id : parent tool id } pairs. + Using the list of tool_version_dicts retrieved from the tool shed (one per changeset + revison up to the currently installed changeset revision), create the parent / child + pairs of tool versions. Each dictionary contains { tool id : parent tool id } pairs. """ context = app.install_model.context for tool_version_dict in tool_version_dicts: @@ -802,9 +860,10 @@ #store repository info in the table tagset for traceability repo_elem = suc.generate_repository_info_elem_from_repository( tool_shed_repository, parent_elem=elem ) if elems: - os.unlink( tool_data_table_conf_filename ) #remove old data_table - app.tool_data_tables.to_xml_file( tool_data_table_conf_filename, elems ) #persist new data_table content - + # Remove old data_table + os.unlink( tool_data_table_conf_filename ) + # Persist new data_table content. + app.tool_data_tables.to_xml_file( tool_data_table_conf_filename, elems ) return tool_data_table_conf_filename, elems @@ -829,10 +888,11 @@ def is_data_index_sample_file( file_path ): """ - Attempt to determine if a .sample file is appropriate for copying to ~/tool-data when a tool shed repository is being installed - into a Galaxy instance. + Attempt to determine if a .sample file is appropriate for copying to ~/tool-data when + a tool shed repository is being installed into a Galaxy instance. """ - # Currently most data index files are tabular, so check that first. We'll assume that if the file is tabular, it's ok to copy. + # Currently most data index files are tabular, so check that first. We'll assume that + # if the file is tabular, it's ok to copy. if is_column_based( file_path ): return True # If the file is any of the following, don't copy it. @@ -851,7 +911,7 @@ # Default to copying the file if none of the above are true. return True -def load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config_filename ): +def load_tool_from_changeset_revision( app, repository_id, changeset_revision, tool_config_filename ): """ Return a loaded tool whose tool config file name (e.g., filtering.xml) is the value of tool_config_filename. The value of changeset_revision is a valid (downloadable) @@ -859,31 +919,35 @@ the received valid changeset revision and the first changeset revision in the repository, searching backwards. """ - original_tool_data_path = trans.app.config.tool_data_path - repository = suc.get_repository_in_tool_shed( trans.app, repository_id ) - repo_files_dir = repository.repo_path( trans.app ) - repo = hg_util.get_repo_for_repository( trans.app, repository=None, repo_path=repo_files_dir, create=False ) + original_tool_data_path = app.config.tool_data_path + repository = suc.get_repository_in_tool_shed( app, repository_id ) + repo_files_dir = repository.repo_path( app ) + repo = hg_util.get_repo_for_repository( app, repository=None, repo_path=repo_files_dir, create=False ) message = '' tool = None can_use_disk_file = False tool_config_filepath = suc.get_absolute_path_to_file_in_repository( repo_files_dir, tool_config_filename ) work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-ltfcr" ) - can_use_disk_file = can_use_tool_config_disk_file( trans, repository, repo, tool_config_filepath, changeset_revision ) + can_use_disk_file = can_use_tool_config_disk_file( app, + repository, + repo, + tool_config_filepath, + changeset_revision ) if can_use_disk_file: - trans.app.config.tool_data_path = work_dir - tool, valid, message, sample_files = handle_sample_files_and_load_tool_from_disk( trans, + app.config.tool_data_path = work_dir + tool, valid, message, sample_files = handle_sample_files_and_load_tool_from_disk( app, repo_files_dir, repository_id, tool_config_filepath, work_dir ) if tool is not None: - invalid_files_and_errors_tups = check_tool_input_params( trans.app, + invalid_files_and_errors_tups = check_tool_input_params( app, repo_files_dir, tool_config_filename, tool, sample_files ) if invalid_files_and_errors_tups: - message2 = generate_message_for_invalid_tools( trans.app, + message2 = generate_message_for_invalid_tools( app, invalid_files_and_errors_tups, repository, metadata_dict=None, @@ -891,16 +955,16 @@ displaying_invalid_tool=True ) message = concat_messages( message, message2 ) else: - tool, message, sample_files = handle_sample_files_and_load_tool_from_tmp_config( trans, + tool, message, sample_files = handle_sample_files_and_load_tool_from_tmp_config( app, repo, repository_id, changeset_revision, tool_config_filename, work_dir ) basic_util.remove_dir( work_dir ) - trans.app.config.tool_data_path = original_tool_data_path + app.config.tool_data_path = original_tool_data_path # Reset the tool_data_tables by loading the empty tool_data_table_conf.xml file. - reset_tool_data_tables( trans.app ) + reset_tool_data_tables( app ) return repository, tool, message def load_tool_from_config( app, repository_id, full_path ): @@ -920,7 +984,7 @@ error_message = str( e ) return tool, valid, error_message -def load_tool_from_tmp_config( trans, repo, repository_id, ctx, ctx_file, work_dir ): +def load_tool_from_tmp_config( app, repo, repository_id, ctx, ctx_file, work_dir ): tool = None message = '' tmp_tool_config = hg_util.get_named_tmpfile_from_ctx( ctx, ctx_file, work_dir ) @@ -936,7 +1000,7 @@ tmp_code_file_name = hg_util.copy_file_from_manifest( repo, ctx, code_file_name, work_dir ) if tmp_code_file_name: tmp_code_files.append( tmp_code_file_name ) - tool, valid, message = load_tool_from_config( trans.app, repository_id, tmp_tool_config ) + tool, valid, message = load_tool_from_config( app, repository_id, tmp_tool_config ) for tmp_code_file in tmp_code_files: try: os.unlink( tmp_code_file ) @@ -966,7 +1030,11 @@ def panel_entry_per_tool( tool_section_dict ): # Return True if tool_section_dict looks like this. - # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} + # {<Tool guid> : + # [{ tool_config : <tool_config_file>, + # id: <ToolSection id>, + # version : <ToolSection version>, + # name : <TooSection name>}]} # But not like this. # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>} if not tool_section_dict: @@ -985,10 +1053,11 @@ if isinstance( tool.tool_action, UploadToolAction ): app.toolbox.reload_tool_by_id( tool_id ) -def remove_from_shed_tool_config( trans, shed_tool_conf_dict, guids_to_remove ): - # A tool shed repository is being uninstalled so change the shed_tool_conf file. Parse the config file to generate the entire list - # of config_elems instead of using the in-memory list since it will be a subset of the entire list if one or more repositories have - # been deactivated. +def remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove ): + # A tool shed repository is being uninstalled so change the shed_tool_conf file. + # Parse the config file to generate the entire list of config_elems instead of + # using the in-memory list since it will be a subset of the entire list if one + # or more repositories have been deactivated. shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ] tool_path = shed_tool_conf_dict[ 'tool_path' ] config_elems = [] @@ -1016,26 +1085,31 @@ for config_elem in config_elems_to_remove: config_elems.remove( config_elem ) # Persist the altered in-memory version of the tool config. - suc.config_elems_to_xml_file( trans.app, config_elems, shed_tool_conf, tool_path ) + suc.config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path ) -def remove_from_tool_panel( trans, repository, shed_tool_conf, uninstall ): - """A tool shed repository is being deactivated or uninstalled, so handle tool panel alterations accordingly.""" - # Determine where the tools are currently defined in the tool panel and store this information so the tools can be displayed - # in the same way when the repository is activated or reinstalled. - tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( trans.app, repository ) +def remove_from_tool_panel( app, repository, shed_tool_conf, uninstall ): + """ + A tool shed repository is being deactivated or uninstalled, so handle tool panel + alterations accordingly. + """ + # Determine where the tools are currently defined in the tool panel and store this + # information so the tools can be displayed in the same way when the repository is + # activated or reinstalled. + tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( app, repository ) repository.metadata[ 'tool_panel_section' ] = tool_panel_dict - trans.install_model.context.add( repository ) - trans.install_model.context.flush() - # Create a list of guids for all tools that will be removed from the in-memory tool panel and config file on disk. + app.install_model.context.add( repository ) + app.install_model.context.flush() + # Create a list of guids for all tools that will be removed from the in-memory tool panel + # and config file on disk. guids_to_remove = [ k for k in tool_panel_dict.keys() ] # Remove the tools from the toolbox's tools_by_id dictionary. for guid_to_remove in guids_to_remove: - if guid_to_remove in trans.app.toolbox.tools_by_id: - del trans.app.toolbox.tools_by_id[ guid_to_remove ] - index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( trans.app, shed_tool_conf ) + if guid_to_remove in app.toolbox.tools_by_id: + del app.toolbox.tools_by_id[ guid_to_remove ] + index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf ) if uninstall: # Remove from the shed_tool_conf file on disk. - remove_from_shed_tool_config( trans, shed_tool_conf_dict, guids_to_remove ) + remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove ) config_elems = shed_tool_conf_dict[ 'config_elems' ] config_elems_to_remove = [] for config_elem in config_elems: @@ -1052,18 +1126,19 @@ # Remove the tool sub-element from the section element. config_elem.remove( tool_elem ) # Remove the tool from the section in the in-memory tool panel. - if section_key in trans.app.toolbox.tool_panel: - tool_section = trans.app.toolbox.tool_panel[ section_key ] + if section_key in app.toolbox.tool_panel: + tool_section = app.toolbox.tool_panel[ section_key ] guid = tool_elem.get( 'guid' ) tool_key = 'tool_%s' % str( guid ) # Get the list of versions of this tool that are currently available in the toolbox. - available_tool_versions = trans.app.toolbox.get_loaded_tools_by_lineage( guid ) + available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid ) if tool_key in tool_section.elems: if available_tool_versions: available_tool_versions.reverse() replacement_tool_key = None replacement_tool_version = None - # Since we are going to remove the tool from the section, replace it with the newest loaded version of the tool. + # Since we are going to remove the tool from the section, replace it with the + # newest loaded version of the tool. for available_tool_version in available_tool_versions: available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section() if available_tool_version.id in tool_section.elems.keys() or section_key == available_tool_section_id: @@ -1078,15 +1153,17 @@ # Remove the tool from the tool section. del tool_section.elems[ tool_key ] # Add the replacement tool at the same location in the tool section. - tool_section.elems.insert( tool_section_elems_index, replacement_tool_key, replacement_tool_version ) + tool_section.elems.insert( tool_section_elems_index, + replacement_tool_key, + replacement_tool_version ) else: del tool_section.elems[ tool_key ] else: del tool_section.elems[ tool_key ] if uninstall: # Remove the tool from the section in the in-memory integrated tool panel. - if section_key in trans.app.toolbox.integrated_tool_panel: - tool_section = trans.app.toolbox.integrated_tool_panel[ section_key ] + if section_key in app.toolbox.integrated_tool_panel: + tool_section = app.toolbox.integrated_tool_panel[ section_key ] tool_key = 'tool_%s' % str( tool_elem.get( 'guid' ) ) if tool_key in tool_section.elems: del tool_section.elems[ tool_key ] @@ -1098,46 +1175,47 @@ if guid in guids_to_remove: tool_key = 'tool_%s' % str( config_elem.get( 'guid' ) ) # Get the list of versions of this tool that are currently available in the toolbox. - available_tool_versions = trans.app.toolbox.get_loaded_tools_by_lineage( guid ) - if tool_key in trans.app.toolbox.tool_panel: + available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid ) + if tool_key in app.toolbox.tool_panel: if available_tool_versions: available_tool_versions.reverse() replacement_tool_key = None replacement_tool_version = None - # Since we are going to remove the tool from the section, replace it with the newest loaded version of the tool. + # Since we are going to remove the tool from the section, replace it with + # the newest loaded version of the tool. for available_tool_version in available_tool_versions: available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section() - if available_tool_version.id in trans.app.toolbox.tool_panel.keys() or not available_tool_section_id: + if available_tool_version.id in app.toolbox.tool_panel.keys() or not available_tool_section_id: replacement_tool_key = 'tool_%s' % str( available_tool_version.id ) replacement_tool_version = available_tool_version break if replacement_tool_key and replacement_tool_version: # Get the index of the tool_key in the tool_section. - for tool_panel_index, key in enumerate( trans.app.toolbox.tool_panel.keys() ): + for tool_panel_index, key in enumerate( app.toolbox.tool_panel.keys() ): if key == tool_key: break # Remove the tool from the tool panel. - del trans.app.toolbox.tool_panel[ tool_key ] + del app.toolbox.tool_panel[ tool_key ] # Add the replacement tool at the same location in the tool panel. - trans.app.toolbox.tool_panel.insert( tool_panel_index, replacement_tool_key, replacement_tool_version ) + app.toolbox.tool_panel.insert( tool_panel_index, replacement_tool_key, replacement_tool_version ) else: - del trans.app.toolbox.tool_panel[ tool_key ] + del app.toolbox.tool_panel[ tool_key ] else: - del trans.app.toolbox.tool_panel[ tool_key ] + del app.toolbox.tool_panel[ tool_key ] if uninstall: - if tool_key in trans.app.toolbox.integrated_tool_panel: - del trans.app.toolbox.integrated_tool_panel[ tool_key ] + if tool_key in app.toolbox.integrated_tool_panel: + del app.toolbox.integrated_tool_panel[ tool_key ] config_elems_to_remove.append( config_elem ) for config_elem in config_elems_to_remove: # Remove the element from the in-memory list of elements. config_elems.remove( config_elem ) # Update the config_elems of the in-memory shed_tool_conf_dict. shed_tool_conf_dict[ 'config_elems' ] = config_elems - trans.app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict - trans.app.toolbox_search = ToolBoxSearch( trans.app.toolbox ) - if uninstall and trans.app.config.update_integrated_tool_panel: + app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict + app.toolbox_search = ToolBoxSearch( app.toolbox ) + if uninstall and app.config.update_integrated_tool_panel: # Write the current in-memory version of the integrated_tool_panel.xml file to disk. - trans.app.toolbox.write_integrated_tool_panel_config_file() + app.toolbox.write_integrated_tool_panel_config_file() def reset_tool_data_tables( app ): # Reset the tool_data_tables to an empty dictionary. diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 lib/tool_shed/util/workflow_util.py --- a/lib/tool_shed/util/workflow_util.py +++ b/lib/tool_shed/util/workflow_util.py @@ -61,7 +61,10 @@ # We're in the tool shed. for tool_dict in tools_metadata: if self.tool_id in [ tool_dict[ 'id' ], tool_dict[ 'guid' ] ]: - repository, self.tool, message = tool_util.load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_dict[ 'tool_config' ] ) + repository, self.tool, message = tool_util.load_tool_from_changeset_revision( trans.app, + repository_id, + changeset_revision, + tool_dict[ 'tool_config' ] ) if message and self.tool is None: self.errors = 'unavailable' break 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.