commit/galaxy-central: greg: Fixes for managing installed repositories.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/fd2d4e257ee9/ changeset: fd2d4e257ee9 user: greg date: 2012-03-02 19:33:58 summary: Fixes for managing installed repositories. affected #: 4 files diff -r 80fa0f99e7e21c148900d25689f036de7023e5dc -r fd2d4e257ee9f8258dbb47ffc4c3a1ca21d49c24 lib/galaxy/tool_shed/install_manager.py --- a/lib/galaxy/tool_shed/install_manager.py +++ b/lib/galaxy/tool_shed/install_manager.py @@ -125,24 +125,17 @@ # The values for the keys in each of the following dictionaries will be a list to allow for the same tool to be displayed in multiple places # in the tool panel. tool_panel_dict_for_display = {} - tool_panel_dict_for_metadata = {} for tool_elem in repository_elem: # The tool_elem looks something like this: <tool id="EMBOSS: antigenic1" version="5.0.0" file="emboss_antigenic.xml" /> tool_config = tool_elem.get( 'file' ) guid = self.get_guid( repository_clone_url, relative_install_dir, tool_config ) # See if tool_config is defined inside of a section in self.proprietary_tool_panel_elems. is_displayed, tool_sections = self.get_containing_tool_sections( tool_config ) - tool_panel_dict_for_tool_config = generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=tool_sections ) - # The tool_panel_dict_for_tool_config dictionary contains a single entry that looks something like this. - # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} - # Add the new entry to the dictionary we're defining to set metadata. - for k, v in tool_panel_dict_for_tool_config.items(): - tool_panel_dict_for_metadata[ k ] = v if is_displayed: - # Add the new entry to the dictionary we're defining to set the tool panel display. + tool_panel_dict_for_tool_config = generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=tool_sections ) for k, v in tool_panel_dict_for_tool_config.items(): tool_panel_dict_for_display[ k ] = v - metadata_dict = generate_metadata( self.toolbox, relative_install_dir, repository_clone_url, tool_panel_dict=tool_panel_dict_for_metadata ) + metadata_dict = generate_metadata( self.toolbox, relative_install_dir, repository_clone_url ) # Add a new record to the tool_shed_repository table if one doesn't already exist. If one exists but is marked # deleted, undelete it. It is critical that this happens before the call to add_to_tool_panel() below because # tools will not be properly loaded if the repository is marked deleted. diff -r 80fa0f99e7e21c148900d25689f036de7023e5dc -r fd2d4e257ee9f8258dbb47ffc4c3a1ca21d49c24 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -175,40 +175,6 @@ if tool_shed_repository: # Only load tools if the repository is not deactivated or uninstalled. can_load = not tool_shed_repository.deleted - if can_load: - metadata = tool_shed_repository.metadata - update_needed = False - if 'tool_panel_section' in metadata: - if panel_entry_per_tool( metadata[ 'tool_panel_section' ] ): - # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} - tool_panel_dict = metadata[ 'tool_panel_section' ] - else: - # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>} - tool_section_dict = metadata[ 'tool_panel_section' ] - tool_section = generate_tool_section_element_from_dict( tool_section_dict ) - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata, tool_section=tool_section ) - if section: - # This means all tools are loaded into the same tool panel section or are all outside of any sections. - for tool_panel_dict_guid, tool_section_dicts in tool_panel_dict.items(): - for dict_index, tool_section_dict in enumerate( tool_section_dicts ): - if tool_section_dict [ 'id' ] != section.id or \ - tool_section_dict [ 'version' ] != section.version or \ - tool_section_dict [ 'name' ] != section.name: - tool_section_dict [ 'id' ] = section.id - tool_section_dict [ 'version' ] = section.version - tool_section_dict [ 'name' ] = section.name - tool_section_dicts[ dict_index ] = tool_section_dict - tool_panel_dict[ tool_panel_dict_guid ] = tool_section_dicts - update_needed = True - else: - # The tool_panel_section was introduced late, so set it's value if its missing in the metadata. - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( tool_shed_repository.metadata, tool_section=section ) - update_needed = True - if update_needed: - metadata[ 'tool_panel_section' ] = tool_panel_dict - tool_shed_repository.metadata = metadata - self.sa_session.add( tool_shed_repository ) - self.sa_session.flush() else: # If there is not yet a tool_shed_repository record, we're in the process of installing # a new repository, so any included tools can be loaded into the tool panel. diff -r 80fa0f99e7e21c148900d25689f036de7023e5dc -r fd2d4e257ee9f8258dbb47ffc4c3a1ca21d49c24 lib/galaxy/util/shed_util.py --- a/lib/galaxy/util/shed_util.py +++ b/lib/galaxy/util/shed_util.py @@ -274,7 +274,7 @@ if datatypes: metadata_dict[ 'datatypes' ] = datatypes return metadata_dict -def generate_metadata( toolbox, relative_install_dir, repository_clone_url, tool_section_dict=None, tool_panel_dict=None ): +def generate_metadata( toolbox, relative_install_dir, repository_clone_url ): """ Browse the repository files on disk to generate metadata. Since we are using disk files, it is imperative that the repository is updated to the desired change set revision before metadata is generated. @@ -282,24 +282,6 @@ metadata_dict = {} sample_files = [] datatypes_config = None - new_tool_panel_dict = {} - # Keep track of the section in the tool panel in which this repository's tools will be contained by using the information in either the - # tool_section_dict or the tool_panel_dict (at least 1 of these 2 dictionaries should be None). The tool_section_dict is passed when the - # Admin is manually installing a repository into a single selected section. It looks something like this. - # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>} - # The tool_panel_dict is fully populated with all tools in the repository that should be loaded into the tool panel. It is received when - # this method is called by the InstallManager or when metadata is being reset on an existing repository. This dictionary looks something - # like this. - # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} - # The tool_panel_dict enables each tool in the repository to be contained inside or outside a specified ToolSection in the tool panel. The - # new_tool_panel_dict with be populated with a subset of the items in the received tool_panel_dict. This will allow for the case where - # repository metadata is being updated where the previous change set revision included more tools than the current change set revision. - if tool_section_dict: - # The received tool_panel_dict must be None, so we'll populate it here. - for k, v in tool_section_dict.items(): - if v is None: - # Coerce None values into empty strings because ElementTree.tostring() throws exceptions on None values. - tool_section_dict[ k ] = '' # Find datatypes_conf.xml if it exists. for root, dirs, files in os.walk( relative_install_dir ): if root.find( '.hg' ) < 0: @@ -336,36 +318,6 @@ tool_config = os.path.join( root, name ) guid = generate_tool_guid( repository_clone_url, tool ) metadata_dict = generate_tool_metadata( tool_config, tool, repository_clone_url, metadata_dict ) - # Populate the tool_section_dict if necessary. - if tool_panel_dict and guid in tool_panel_dict: - # We're updating metadata on a previously installed repository. - old_tool_panel_dicts = tool_panel_dict[ guid ] - for dict_index, old_tool_panel_dict in enumerate( old_tool_panel_dicts ): - # Should we really do this? What if there is more than 1 old_tool_panel_dict in the list? - if 'tool_config' not in old_tool_panel_dict or old_tool_panel_dict[ 'tool_config' ] in [ None, '' ]: - old_tool_panel_dict[ 'tool_config' ] = name - old_tool_panel_dicts[ dict_index ] = old_tool_panel_dict - if guid in new_tool_panel_dict: - for old_tool_panel_dict in old_tool_panel_dicts: - new_tool_panel_dict[ guid ].append( old_tool_panel_dict ) - else: - new_tool_panel_dict[ guid ] = old_tool_panel_dicts - else: - # The admin is manually installing a new repository. - new_tool_section_dict = {} - if tool_section_dict: - for k, v in tool_section_dict.items(): - new_tool_section_dict[ k ] = v - else: - new_tool_section_dict[ 'id' ] = '' - new_tool_section_dict[ 'name' ] = '' - new_tool_section_dict[ 'version' ] = '' - if 'tool_config' not in new_tool_section_dict or new_tool_section_dict[ 'tool_config' ] in [ None, '' ]: - new_tool_section_dict[ 'tool_config' ] = name - if guid in new_tool_panel_dict: - new_tool_panel_dict[ guid ].append( new_tool_section_dict ) - else: - new_tool_panel_dict[ guid ] = [ new_tool_section_dict ] # Find all exported workflows elif name.endswith( '.ga' ): relative_path = os.path.join( root, name ) @@ -375,7 +327,6 @@ exported_workflow_dict = from_json_string( workflow_text ) if 'a_galaxy_workflow' in exported_workflow_dict and exported_workflow_dict[ 'a_galaxy_workflow' ] == 'true': metadata_dict = generate_workflow_metadata( relative_path, exported_workflow_dict, metadata_dict ) - metadata_dict[ 'tool_panel_section' ] = new_tool_panel_dict return metadata_dict def generate_tool_guid( repository_clone_url, tool ): """ @@ -433,7 +384,6 @@ return metadata_dict 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.""" - # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} elem_list = [] tool_elem = None tmp_url = clean_repository_clone_url( repository_clone_url ) @@ -487,34 +437,75 @@ else: elem_list.append( tool_elem ) return elem_list -def generate_tool_panel_dict_for_repository_tools( repository_metadata, tool_section=None, tool_section_dict=None ): +def generate_tool_panel_dict_for_new_install( tool_dicts, tool_section=None ): """ - Create a dictionary of the following type for every tool in the repository where the tools are all contained in the same tool section - or no tool section. If tool_section is None, tools will be displayed outside of any sections in the tool panel. - {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} + When installing a repository that contains tools, all tools must curently be defined within the same tool section in the tool + panel or outside of any sections. """ tool_panel_dict = {} - tool_dicts = repository_metadata[ 'tools' ] + if tool_section: + section_id = tool_section.id + section_name = tool_section.name + section_version = tool_section.version + else: + section_id = '' + section_name = '' + section_version = '' for tool_dict in tool_dicts: guid = tool_dict[ 'guid' ] tool_config = tool_dict[ 'tool_config' ] - new_tool_section_dict = {} - if tool_section_dict: - for k, v in tool_section_dict.items(): - new_tool_section_dict[ k ] = v - file_path, file_name = os.path.split( tool_config ) - new_tool_section_dict[ 'tool_config' ] = file_name - if guid in tool_panel_dict: - tool_panel_dict[ guid ].append( new_tool_section_dict ) - else: - tool_panel_dict[ guid ] = [ new_tool_section_dict ] + tool_section_dict = dict( tool_config=tool_config, id=section_id, name=section_name, version=section_version ) + if guid in tool_panel_dict: + tool_panel_dict[ guid ].append( tool_section_dict ) else: - new_tool_section_dicts = generate_tool_section_dicts( tool_config=tool_config, tool_section=tool_section ) - if guid in tool_panel_dict: - for new_tool_section_dict in new_tool_section_dicts: - tool_panel_dict[ guid ].append( new_tool_section_dict ) - else: - tool_panel_dict[ guid ] = new_tool_section_dicts + tool_panel_dict[ guid ] = [ tool_section_dict ] + return tool_panel_dict +def generate_tool_panel_dict_from_shed_tool_conf_entries( trans, repository ): + """ + Keep track of the section in the tool panel in which this repository's tools will be contained by parsing the shed-tool_conf in + which the repository's tools are defined and storing the tool panel definition of each tool in the repository. This method is called + only when the repository is being deactivated or uninstalled and allows for activation or reinstallation using the original layout. + """ + tool_panel_dict = {} + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( trans.app, repository ) + metadata = repository.metadata + # Create a dictionary of tool guid and tool config file name for each tool in the repository. + guids_and_configs = {} + for tool_dict in metadata[ 'tools' ]: + guid = tool_dict[ 'guid' ] + tool_config = tool_dict[ 'tool_config' ] + file_path, file_name = os.path.split( tool_config ) + guids_and_configs[ guid ] = file_name + # Parse the shed_tool_conf file in which all of this repository's tools are defined and generate the tool_panel_dict. + tree = util.parse_xml( shed_tool_conf ) + root = tree.getroot() + for elem in root: + if elem.tag == 'tool': + guid = elem.get( 'guid' ) + if guid in guids_and_configs: + # The tool is displayed in the tool panel outside of any tool sections. + tool_section_dict = dict( tool_config=guids_and_configs[ guid ], id='', name='', version='' ) + if guid in tool_panel_dict: + tool_panel_dict[ guid ].append( tool_section_dict ) + else: + tool_panel_dict[ guid ] = [ tool_section_dict ] + elif elem.tag == 'section': + section_id = elem.get( 'id' ) or '' + section_name = elem.get( 'name' ) or '' + section_version = elem.get( 'version' ) or '' + for section_elem in elem: + if section_elem.tag == 'tool': + guid = section_elem.get( 'guid' ) + if guid in guids_and_configs: + # The tool is displayed in the tool panel inside the current tool section. + tool_section_dict = dict( tool_config=guids_and_configs[ guid ], + id=section_id, + name=section_name, + version=section_version ) + if guid in tool_panel_dict: + tool_panel_dict[ guid ].append( tool_section_dict ) + else: + tool_panel_dict[ guid ] = [ tool_section_dict ] return tool_panel_dict def generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=None ): """ @@ -611,7 +602,6 @@ def get_in_memory_config_elems_to_remove( shed_tool_conf_dict, guids_to_remove ): config_elems = shed_tool_conf_dict[ 'config_elems' ] config_elems_to_remove = [] - tool_elements_removed = 0 for config_elem in config_elems: if config_elem.tag == 'section': tool_elems_to_remove = [] @@ -621,20 +611,12 @@ for tool_elem in tool_elems_to_remove: # Remove all of the appropriate tool sub-elements from the section element. config_elem.remove( tool_elem ) - log.debug( "Removed tool with guid '%s'." % str( tool_elem.get( 'guid' ) ) ) - tool_elements_removed += 1 if len( config_elem ) < 1: # Keep a list of all empty section elements so they can be removed. config_elems_to_remove.append( config_elem ) - if tool_elements_removed == len( guids_to_remove ): - break elif config_elem.tag == 'tool': if config_elem.get( 'guid' ) in guids_to_remove: config_elems_to_remove.append( config_elem ) - log.debug( "Removed tool with guid '%s'." % str( config_elem.get( 'guid' ) ) ) - tool_elements_removed += 1 - if tool_elements_removed == len( guids_to_remove ): - break return config_elems_to_remove def get_shed_tool_conf_dict( app, shed_tool_conf ): """ @@ -674,6 +656,68 @@ tool = app.toolbox.load_tool( os.path.abspath( relative_path ), guid=guid ) repository_tools_tups.append( ( relative_path, guid, tool ) ) return repository_tools_tups +def get_tool_panel_config_tool_path_install_dir( app, repository ): + # Return shed-related tool panel config, the tool_path configured in it, and the relative path to the directory where the + # repository is installed. This method assumes all repository tools are defined in a single shed-related tool panel config. + tool_shed = clean_tool_shed_url( repository.tool_shed ) + partial_install_dir = '%s/repos/%s/%s/%s' % ( tool_shed, repository.owner, repository.name, repository.installed_changeset_revision ) + # Get the relative tool installation paths from each of the shed tool configs. + relative_install_dir = None + for shed_tool_conf_dict in app.toolbox.shed_tool_confs: + shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ] + if repository.dist_to_shed: + # The repository is owned by devteam and contains tools migrated from the Galaxy distribution to the tool shed, so + # the reserved tool panel config is migrated_tools_conf.xml, to which app.config.migrated_tools_config refers. + if shed_tool_conf == app.config.migrated_tools_config: + tool_path = shed_tool_conf_dict[ 'tool_path' ] + relative_install_dir = os.path.join( tool_path, partial_install_dir ) + if tool_path and relative_install_dir: + return shed_tool_conf, tool_path, relative_install_dir + elif repository.uninstalled: + # Since the repository is uninstalled we don't know what tool panel config was originally used to + # define the tools in the repository, so we'll just make sure not to use the reserved migrated_tools_conf.xml. + if shed_tool_conf != app.config.migrated_tools_config: + tool_path = shed_tool_conf_dict[ 'tool_path' ] + relative_install_dir = os.path.join( tool_path, partial_install_dir ) + if tool_path and relative_install_dir: + return shed_tool_conf, tool_path, relative_install_dir + else: + if repository.includes_tools: + metadata = repository.metadata + for tool_dict in metadata[ 'tools' ]: + # Parse the tool panel config to get the entire set of config_elems. # We'll check config_elems until we + # find an element that matches one of the tools in the repository's metadata. + tool_panel_config = shed_tool_conf_dict[ 'config_filename' ] + tree = util.parse_xml( tool_panel_config ) + root = tree.getroot() + tool_path, relative_install_dir = get_tool_path_install_dir( partial_install_dir, + shed_tool_conf_dict, + tool_dict, + root ) + if tool_path and relative_install_dir: + return shed_tool_conf, tool_path, relative_install_dir + else: + # Nothing will be loaded into the tool panel, so look for the installed repository on disk. + tool_path = shed_tool_conf_dict[ 'tool_path' ] + relative_install_dir = os.path.join( tool_path, partial_install_dir ) + if tool_path and relative_install_dir and os.path.isdir( relative_install_dir ): + return shed_tool_conf, tool_path, relative_install_dir + return None, None, None +def get_tool_path_install_dir( partial_install_dir, shed_tool_conf_dict, tool_dict, config_elems ): + for elem in config_elems: + if elem.tag == 'tool': + if elem.get( 'guid' ) == tool_dict[ 'guid' ]: + tool_path = shed_tool_conf_dict[ 'tool_path' ] + relative_install_dir = os.path.join( tool_path, partial_install_dir ) + return tool_path, relative_install_dir + elif elem.tag == 'section': + for section_elem in elem: + if section_elem.tag == 'tool': + if section_elem.get( 'guid' ) == tool_dict[ 'guid' ]: + tool_path = shed_tool_conf_dict[ 'tool_path' ] + relative_install_dir = os.path.join( tool_path, partial_install_dir ) + return tool_path, relative_install_dir + return None, None def get_tool_version( app, tool_id ): sa_session = app.model.context.current return sa_session.query( app.model.ToolVersion ) \ @@ -829,31 +873,13 @@ if display_path: # Load or deactivate proprietary datatype display applications app.datatypes_registry.load_display_applications( installed_repository_dict=repository_dict, deactivate=deactivate ) -def load_repository_contents( trans, repository_name, description, owner, changeset_revision, tool_path, repository_clone_url, relative_install_dir, - current_working_dir, tmp_name, tool_panel_dict=None, tool_shed=None, tool_section=None, shed_tool_conf=None, - new_install=True ): - """ - Generate the metadata for the installed tool shed repository, among other things. It is critical that the installed repository - is updated to the desired changeset_revision before metadata is set because the process for setting metadata uses the repository - files on disk. If this method is called when a new repository is being installed, the value of tool_panel_dict will be None and - the value of tool_section (a ToolSection or None) will be used. This method is also called when updates have been pulled to a - previously installed repository, in which case the value of tool_panel_dict will be used and the value of new_install will be False. - """ - if tool_panel_dict: - # We're resetting metadata on a previously installed repository. For backward compatibility we have to handle 2 types of dictionaries. - # In the past, all repository tools had to be installed into a single ToolSection (or outside of any sections) in the tool panel. - if panel_entry_per_tool( tool_panel_dict ): - # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]} - metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url, tool_panel_dict=tool_panel_dict ) - else: - # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>} - metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url, tool_section_dict=tool_panel_dict ) - else: - # We're installing a new repository or reinstalling an uninstalled repository where all tools are contained in the same tool panel section - # or outside of any sections in the tool panel. We cannot pass a specific tool_config since we do not yet have one. - tool_section_dicts = generate_tool_section_dicts( tool_config=None, tool_sections=util.listify( tool_section ) ) - metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url, tool_section_dict=tool_section_dicts[ 0 ] ) - tool_panel_dict = metadata_dict[ 'tool_panel_section' ] +def load_repository_contents( trans, repository_name, description, owner, changeset_revision, tool_path, repository_clone_url, + relative_install_dir, current_working_dir, tmp_name, tool_shed=None, tool_section=None, shed_tool_conf=None ): + """Generate the metadata for the installed tool shed repository, among other things.""" + # It is critical that the installed repository is updated to the desired changeset_revision before metadata is set because the + # process for setting metadata uses the repository files on disk. This method is called when an admin is installing a new repository + # or reinstalling an uninstalled repository. + metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url ) # Add a new record to the tool_shed_repository table if one doesn't already exist. If one exists but is marked deleted, undelete it. This # must happen before the call to add_to_tool_panel() below because tools will not be properly loaded if the repository is marked deleted. log.debug( "Adding new row (or updating an existing row) for repository '%s' in the tool_shed_repository table." % repository_name ) @@ -865,6 +891,7 @@ metadata_dict, dist_to_shed=False ) if 'tools' in metadata_dict: + tool_panel_dict = generate_tool_panel_dict_for_new_install( metadata_dict[ 'tools' ], tool_section ) repository_tools_tups = get_repository_tools_tups( trans.app, metadata_dict ) if repository_tools_tups: sample_files = metadata_dict.get( 'sample_files', [] ) @@ -874,20 +901,15 @@ repository_tools_tups = handle_missing_index_file( trans.app, tool_path, sample_files, repository_tools_tups ) # Handle tools that use fabric scripts to install dependencies. handle_tool_dependencies( current_working_dir, relative_install_dir, repository_tools_tups ) - if new_install: - add_to_tool_panel( app=trans.app, - repository_name=repository_name, - repository_clone_url=repository_clone_url, - changeset_revision=changeset_revision, - repository_tools_tups=repository_tools_tups, - owner=owner, - shed_tool_conf=shed_tool_conf, - tool_panel_dict=tool_panel_dict, - new_install=new_install ) - elif trans.app.toolbox_search.enabled: - # If search support for tools is enabled, index the new installed tools. In the condition above, this happens in the - # add_to_tool_panel() method. - trans.app.toolbox_search = ToolBoxSearch( trans.app.toolbox ) + add_to_tool_panel( app=trans.app, + repository_name=repository_name, + repository_clone_url=repository_clone_url, + changeset_revision=changeset_revision, + repository_tools_tups=repository_tools_tups, + owner=owner, + shed_tool_conf=shed_tool_conf, + tool_panel_dict=tool_panel_dict, + new_install=True ) # Remove the temporary file try: os.unlink( tmp_name ) @@ -896,8 +918,7 @@ if 'datatypes_config' in metadata_dict: datatypes_config = os.path.abspath( metadata_dict[ 'datatypes_config' ] ) # Load data types required by tools. - override = not new_install - converter_path, display_path = alter_config_and_load_prorietary_datatypes( trans.app, datatypes_config, relative_install_dir, override=override ) + converter_path, display_path = alter_config_and_load_prorietary_datatypes( trans.app, datatypes_config, relative_install_dir, override=False ) if converter_path or display_path: # Create a dictionary of tool shed repository related information. repository_dict = create_repository_dict_for_proprietary_datatypes( tool_shed=tool_shed, @@ -937,7 +958,7 @@ os.chdir( current_working_dir ) tmp_stderr.close() return returncode, tmp_name -def remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove ): +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. @@ -948,7 +969,6 @@ root = tree.getroot() for elem in root: config_elems.append( elem ) - tool_elements_removed = 0 config_elems_to_remove = [] for config_elem in config_elems: if config_elem.tag == 'section': @@ -959,30 +979,30 @@ for tool_elem in tool_elems_to_remove: # Remove all of the appropriate tool sub-elements from the section element. config_elem.remove( tool_elem ) - tool_elements_removed += 1 if len( config_elem ) < 1: # Keep a list of all empty section elements so they can be removed. config_elems_to_remove.append( config_elem ) - if tool_elements_removed == len( guids_to_remove ): - break elif config_elem.tag == 'tool': if config_elem.get( 'guid' ) in guids_to_remove: config_elems_to_remove.append( config_elem ) - tool_elements_removed += 1 - if tool_elements_removed == len( guids_to_remove ): - break for config_elem in config_elems_to_remove: config_elems.remove( config_elem ) # Persist the altered in-memory version of the tool config. - config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path ) -def remove_from_tool_panel( app, shed_tool_conf, tool_panel_dict, uninstall ): + config_elems_to_xml_file( trans.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.""" - index, shed_tool_conf_dict = get_shed_tool_conf_dict( app, shed_tool_conf ) + # 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 = generate_tool_panel_dict_from_shed_tool_conf_entries( trans, repository ) + repository.metadata[ 'tool_panel_section' ] = tool_panel_dict + trans.sa_session.add( repository ) + trans.sa_session.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() ] + index, shed_tool_conf_dict = get_shed_tool_conf_dict( trans.app, shed_tool_conf ) if uninstall: # Remove from the shed_tool_conf file on disk. - remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove ) + remove_from_shed_tool_config( trans, shed_tool_conf_dict, guids_to_remove ) config_elems_to_remove = get_in_memory_config_elems_to_remove( shed_tool_conf_dict, guids_to_remove ) # Remove from the in-memory list of config_elems. config_elems = shed_tool_conf_dict[ 'config_elems' ] @@ -991,16 +1011,16 @@ config_elems.remove( config_elem ) if config_elem.tag == 'section': key = 'section_%s' % str( config_elem.get( "id" ) ) - del app.toolbox.tool_panel[ key ] + del trans.app.toolbox.tool_panel[ key ] elif config_elem.tag == 'tool': key = 'tool_%s' % str( config_elem.get( 'guid' ) ) - del app.toolbox.tool_panel[ key ] + del trans.app.toolbox.tool_panel[ key ] # Update the config_elems of the in-memory shed_tool_conf_dict. shed_tool_conf_dict[ 'config_elems' ] = config_elems - app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict - if app.toolbox_search.enabled: + trans.app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict + if trans.app.toolbox_search.enabled: # If search support for tools is enabled, index tools. - app.toolbox_search = ToolBoxSearch( app.toolbox ) + trans.app.toolbox_search = ToolBoxSearch( trans.app.toolbox ) def update_repository( current_working_dir, repo_files_dir, changeset_revision ): # Update the cloned repository to changeset_revision. It is imperative that the # installed repository is updated to the desired changeset_revision before metadata diff -r 80fa0f99e7e21c148900d25689f036de7023e5dc -r fd2d4e257ee9f8258dbb47ffc4c3a1ca21d49c24 lib/galaxy/web/controllers/admin_toolshed.py --- a/lib/galaxy/web/controllers/admin_toolshed.py +++ b/lib/galaxy/web/controllers/admin_toolshed.py @@ -79,48 +79,25 @@ def activate_repository( self, trans, **kwd ): """Activate a repository that was deactivated but not uninstalled.""" repository = get_repository( trans, kwd[ 'id' ] ) - shed_tool_conf, tool_path, relative_install_dir = self.__get_tool_panel_config_tool_path_install_dir( trans, repository ) + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( trans.app, repository ) repository_clone_url = self.__generate_clone_url( trans, repository ) repository.deleted = False trans.sa_session.add( repository ) trans.sa_session.flush() if repository.includes_tools: + metadata = repository.metadata + repository_tools_tups = get_repository_tools_tups( trans.app, metadata ) # Reload tools into the appropriate tool panel section. - metadata = repository.metadata - if 'tool_panel_section' in metadata: - if panel_entry_per_tool( metadata[ 'tool_panel_section' ] ): - tool_panel_dict = metadata[ 'tool_panel_section' ] - else: - # The value of tool_panel_section is the old dictionary type. - tool_section_dict = metadata[ 'tool_panel_section' ] - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata, tool_section_dict=tool_section_dict ) - repository.metadata[ 'tool_panel_section' ] = tool_panel_dict - trans.sa_session.add( repository ) - trans.sa_session.flush() - else: - # The tool_panel_section was introduced late, so set it's value if its missing in the metadata. - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata ) - repository.metadata[ 'tool_panel_section' ] = tool_panel_dict - trans.sa_session.add( repository ) - trans.sa_session.flush() - repository_tools_tups = get_repository_tools_tups( trans.app, metadata ) - guids_to_activate = [ repository_tool_tup[1] for repository_tool_tup in repository_tools_tups ] - # Make sure we have a tool_version for each guid. - for guid_to_activate in guids_to_activate: - if not get_tool_version( trans.app, guid_to_activate ): - # We're somehow missing a tool_version, so create a new one. - tool_version = trans.model.ToolVersion( tool_id=guid_to_activate, tool_shed_repository=repository ) - trans.sa_session.add( tool_version ) - trans.sa_session.flush() - add_to_tool_panel( trans.app, - repository.name, - repository_clone_url, - repository.changeset_revision, - repository_tools_tups, - repository.owner, - shed_tool_conf, - tool_panel_dict, - new_install=False ) + tool_panel_dict = repository.metadata[ 'tool_panel_section' ] + add_to_tool_panel( trans.app, + repository.name, + repository_clone_url, + repository.changeset_revision, + repository_tools_tups, + repository.owner, + shed_tool_conf, + tool_panel_dict, + new_install=False ) message = 'The <b>%s</b> repository has been activated.' % repository.name status = 'done' return trans.response.send_redirect( web.url_for( controller='admin_toolshed', @@ -197,37 +174,11 @@ remove_from_disk = params.get( 'remove_from_disk', '' ) remove_from_disk_checked = CheckboxField.is_checked( remove_from_disk ) repository = get_repository( trans, kwd[ 'id' ] ) - shed_tool_conf, tool_path, relative_install_dir = self.__get_tool_panel_config_tool_path_install_dir( trans, repository ) + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( trans.app, repository ) if params.get( 'deactivate_or_uninstall_repository_button', False ): - metadata = repository.metadata if repository.includes_tools: - repository_tools_tups = get_repository_tools_tups( trans.app, metadata ) - # Generate the list of tool panel keys derived from the tools included in the repository. - if repository_tools_tups: - repository_tool_panel_keys = [ 'tool_%s' % repository_tools_tup[ 1 ] for repository_tools_tup in repository_tools_tups ] - else: - repository_tool_panel_keys = [] - if 'tool_panel_section' in metadata: - if panel_entry_per_tool( metadata[ 'tool_panel_section' ] ): - tool_panel_dict = metadata[ 'tool_panel_section' ] - else: - # The tool_panel_section dictionary is the old definition of the tool_panel_section, so update it to the current dictionary. - # All of the repository tools will be installed in the same section or outside of any sections. - tool_section_dict = metadata[ 'tool_panel_section' ] - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata, tool_section_dict=tool_section_dict ) - repository.metadata[ 'tool_panel_section' ] = tool_panel_dict - else: - # The tool_panel_section was introduced late, so set it's value if its missing in the metadata. - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata ) - repository.metadata[ 'tool_panel_section' ] = tool_panel_dict - repository_clone_url = generate_clone_url( trans, repository ) - # The repository is either being deactivated or uninstalled, so handle tool panel alterations accordingly. - # If the repository is being uninstalled, the appropriate tools or tool sections will be removed from the - # appropriate shed-related tool config file on disk. - remove_from_tool_panel( app=trans.app, - shed_tool_conf=shed_tool_conf, - tool_panel_dict=tool_panel_dict, - uninstall=remove_from_disk_checked ) + # Handle tool panel alterations. + remove_from_tool_panel( trans, repository, shed_tool_conf, uninstall=remove_from_disk_checked ) if repository.includes_datatypes: # Deactivate proprietary datatypes. load_datatype_items( trans.app, repository, relative_install_dir, deactivate=True ) @@ -360,13 +311,9 @@ relative_install_dir=relative_install_dir, current_working_dir=current_working_dir, tmp_name=tmp_name, - tool_panel_dict=None, tool_shed=tool_shed, tool_section=tool_section, - shed_tool_conf=shed_tool_conf, - new_install=True ) - - + shed_tool_conf=shed_tool_conf ) if 'tools' in metadata_dict: # Get the tool_versions from the tool shed for each tool in the installed change set. url = '%s/repository/get_tool_versions?name=%s&owner=%s&changeset_revision=%s&webapp=galaxy' % \ @@ -438,7 +385,7 @@ status = params.get( 'status', 'done' ) repository = get_repository( trans, kwd[ 'id' ] ) description = util.restore_text( params.get( 'description', repository.description ) ) - shed_tool_conf, tool_path, relative_install_dir = self.__get_tool_panel_config_tool_path_install_dir( trans, repository ) + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( trans.app, repository ) repo_files_dir = os.path.abspath( os.path.join( relative_install_dir, repository.name ) ) if params.get( 'edit_repository_button', False ): if description != repository.description: @@ -448,23 +395,7 @@ message = "The repository information has been updated." elif params.get( 'set_metadata_button', False ): repository_clone_url = generate_clone_url( trans, repository ) - # In case metadata was previously generated for this repository, we'll check to see if it has information needed for the tool_section_dict. - metadata = repository.metadata - if 'tool_panel_section' in metadata: - # For backward compatibility we have to handle 2 types of dictionaries. In the past, all repository tools had to be installed into - # a single ToolSection (or outside of any sections) in the tool panel. In this case. the dictionary looks like this. - # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>} - # Later, each tool from a repository could be installed into the tool panel inside or outside a specified ToolSection in the tool panel. - if panel_entry_per_tool( metadata[ 'tool_panel_section' ] ): - tool_panel_dict = metadata[ 'tool_panel_section' ] - metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url, tool_panel_dict=tool_panel_dict ) - else: - tool_section_dict = metadata[ 'tool_panel_section' ] - metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url, tool_section_dict=tool_section_dict ) - else: - # Not sure if we'll ever reach here, but just in case... - tool_section_dict = dict( id='', version='', name='' ) - metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url, tool_section_dict=tool_section_dict ) + metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url ) if metadata_dict: repository.metadata = metadata_dict trans.sa_session.add( repository ) @@ -482,7 +413,7 @@ repository = get_repository( trans, kwd[ 'id' ] ) no_changes = kwd.get( 'no_changes', '' ) no_changes_checked = CheckboxField.is_checked( no_changes ) - shed_tool_conf, tool_path, relative_install_dir = self.__get_tool_panel_config_tool_path_install_dir( trans, repository ) + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( trans.app, repository ) current_working_dir = os.getcwd() repository_clone_url = generate_clone_url( trans, repository ) clone_dir = os.path.join( tool_path, self.__generate_tool_path( repository_clone_url, repository.installed_changeset_revision ) ) @@ -491,82 +422,58 @@ if returncode == 0: returncode, tmp_name = update_repository( current_working_dir, relative_install_dir, repository.installed_changeset_revision ) if returncode == 0: - # Get the location in the tool panel in which the tool was originally loaded. - metadata = repository.metadata - if 'tool_panel_section' in metadata: - if panel_entry_per_tool( metadata[ 'tool_panel_section' ] ): + if repository.includes_tools: + # Get the location in the tool panel in which each tool was originally loaded. + metadata = repository.metadata + if 'tool_panel_section' in metadata: tool_panel_dict = metadata[ 'tool_panel_section' ] - # TODO: Fix this to handle the case where the tools are distributed across in more than 1 ToolSection. The - # following assumes everything was loaded into 1 section (or no section) in the tool panel. - tool_section_dicts = tool_panel_dict[ tool_panel_dict.keys()[ 0 ] ] - tool_section_dict = tool_section_dicts[ 0 ] else: - tool_section_dict = metadata[ 'tool_panel_section' ] - tool_section = generate_tool_section_element_from_dict( tool_section_dict ) - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata, tool_section=tool_section ) + # This should never happen. + tool_panel_dict = generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] ) + # TODO: Fix this to handle the case where the tools are distributed across in more than 1 ToolSection. The + # following assumes everything was loaded into 1 section (or no section) in the tool panel. + tool_section_dicts = tool_panel_dict[ tool_panel_dict.keys()[ 0 ] ] + tool_section_dict = tool_section_dicts[ 0 ] original_section_id = tool_section_dict[ 'id' ] original_section_name = tool_section_dict[ 'name' ] - else: - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata ) - original_section_id = '' - original_section_name = '' - if no_changes_checked: - if original_section_id in [ '' ]: - tool_section = None + if no_changes_checked: + if original_section_id in [ '' ]: + tool_section = None + else: + section_key = 'section_%s' % str( original_section_id ) + if section_key in trans.app.toolbox.tool_panel: + tool_section = trans.app.toolbox.tool_panel[ section_key ] + else: + # The section in which the tool was originally loaded used to be in the tool panel, but no longer is. + elem = Element( 'section' ) + elem.attrib[ 'name' ] = original_section_name + elem.attrib[ 'id' ] = original_section_id + elem.attrib[ 'version' ] = '' + tool_section = tools.ToolSection( elem ) + trans.app.toolbox.tool_panel[ section_key ] = tool_section else: - section_key = 'section_%s' % str( original_section_id ) - if section_key in trans.app.toolbox.tool_panel: + # The user elected to change the tool panel section to contain the tools. + new_tool_panel_section = kwd.get( 'new_tool_panel_section', '' ) + tool_panel_section = kwd.get( 'tool_panel_section', '' ) + if new_tool_panel_section: + section_id = new_tool_panel_section.lower().replace( ' ', '_' ) + new_section_key = 'section_%s' % str( section_id ) + if new_section_key in trans.app.toolbox.tool_panel: + # Appending a tool to an existing section in trans.app.toolbox.tool_panel + log.debug( "Appending to tool panel section: %s" % new_tool_panel_section ) + tool_section = trans.app.toolbox.tool_panel[ new_section_key ] + else: + # Appending a new section to trans.app.toolbox.tool_panel + log.debug( "Loading new tool panel section: %s" % new_tool_panel_section ) + elem = Element( 'section' ) + elem.attrib[ 'name' ] = new_tool_panel_section + elem.attrib[ 'id' ] = section_id + elem.attrib[ 'version' ] = '' + tool_section = tools.ToolSection( elem ) + trans.app.toolbox.tool_panel[ new_section_key ] = tool_section + elif tool_panel_section: + section_key = 'section_%s' % tool_panel_section tool_section = trans.app.toolbox.tool_panel[ section_key ] - else: - # The section in which the tool was originally loaded used to be in the tool panel, but no longer is. - elem = Element( 'section' ) - elem.attrib[ 'name' ] = original_section_name - elem.attrib[ 'id' ] = original_section_id - elem.attrib[ 'version' ] = '' - tool_section = tools.ToolSection( elem ) - trans.app.toolbox.tool_panel[ section_key ] = tool_section - else: - # The user elected to change the tool panel section to contain the tools. - new_tool_panel_section = kwd.get( 'new_tool_panel_section', '' ) - tool_panel_section = kwd.get( 'tool_panel_section', '' ) - if new_tool_panel_section: - section_id = new_tool_panel_section.lower().replace( ' ', '_' ) - # Update each tool_section dictionary in tool_panel_dict with the new section attributes. - for guid, tool_section_dicts in tool_panel_dict.items(): - for dict_index, tool_section_dict in enumerate( tool_section_dicts ): - tool_section_dict[ 'id' ] = section_id - tool_section_dict[ 'name' ] = new_tool_panel_section - tool_section_dict[ 'version' ] = '' - tool_section_dicts[ dict_index ] = tool_section_dict - tool_panel_dict[ guid ] = tool_section_dicts - new_section_key = 'section_%s' % str( section_id ) - if new_section_key in trans.app.toolbox.tool_panel: - # Appending a tool to an existing section in trans.app.toolbox.tool_panel - log.debug( "Appending to tool panel section: %s" % new_tool_panel_section ) - tool_section = trans.app.toolbox.tool_panel[ new_section_key ] - else: - # Appending a new section to trans.app.toolbox.tool_panel - log.debug( "Loading new tool panel section: %s" % new_tool_panel_section ) - elem = Element( 'section' ) - elem.attrib[ 'name' ] = new_tool_panel_section - elem.attrib[ 'id' ] = section_id - elem.attrib[ 'version' ] = '' - tool_section = tools.ToolSection( elem ) - trans.app.toolbox.tool_panel[ new_section_key ] = tool_section - elif tool_panel_section: - section_key = 'section_%s' % tool_panel_section - tool_section = trans.app.toolbox.tool_panel[ section_key ] - else: - # Update each tool_section dictionary in tool_panel_dict in case the tools used to be contained in a panel section - # but are now being moved outside of any panel sections. - for guid, tool_section_dicts in tool_panel_dict.items(): - for dict_index, tool_section_dict in enumerate( tool_section_dicts ): - tool_section_dict[ 'id' ] = '' - tool_section_dict[ 'name' ] = '' - tool_section_dict[ 'version' ] = '' - tool_section_dicts[ dict_index ] = tool_section_dict - tool_panel_dict[ guid ] = tool_section_dicts - tool_section = None tool_shed_repository, metadata_dict = load_repository_contents( trans, repository_name=repository.name, description=repository.description, @@ -577,11 +484,9 @@ relative_install_dir=relative_install_dir, current_working_dir=current_working_dir, tmp_name=tmp_name, - tool_panel_dict=tool_panel_dict, tool_shed=repository.tool_shed, tool_section=tool_section, - shed_tool_conf=shed_tool_conf, - new_install=True ) + shed_tool_conf=shed_tool_conf ) repository.uninstalled = False repository.deleted = False trans.sa_session.add( repository ) @@ -595,36 +500,6 @@ @web.expose @web.require_admin def reselect_tool_panel_section( self, trans, **kwd ): - """ - INSIDE SECTION: - "{"tool_panel_section": {"gvk.bx.psu.edu:9009/repos/test/grouping/Grouping1/1.9.0": {"id": "group", - "name": "Group", - "tool_config": "grouping.xml", - "version": ""}}, - "tools": [{"description": "data by a column and perform aggregate operation on other columns.", - "guid": "gvk.bx.psu.edu:9009/repos/test/grouping/Grouping1/1.9.0", - "id": "Grouping1", - "name": "Group", - "requirements": [{"fabfile": null, "method": null, "name": "rpy", "type": "python-module", "version": null}], - "tests": [{"inputs": [["input1", "1.bed", {"children": [], "value": "1.bed"}], ["groupcol", "1", {"children": [], "value": "1"}], ["ignorecase", "true", {"children": [], "value": "true"}], ["optype", "mean", {"children": [], "value": "mean"}], ["opcol", "2", {"children": [], "value": "2"}], ["opround", "no", {"children": [], "value": "no"}]], "name": "Test-1", "outputs": [["out_file1", "groupby_out1.dat", {"assert_list": null, "compare": "diff", "delta": 10000, "extra_files": [], "lines_diff": 0, "sort": false}]], "required_files": [["1.bed", {"children": [], "value": "1.bed"}]]}, {"inputs": [["input1", "1.tabular", {"children": [], "value": "1.tabular"}], ["groupcol", "1", {"children": [], "value": "1"}], ["ignorecase", "true", {"children": [], "value": "true"}], ["optype", "mean", {"children": [], "value": "mean"}], ["opcol", "2", {"children": [], "value": "2"}], ["opround", "no", {"children": [], "value": "no"}]], "name": "Test-2", "outputs": [["out_file1", "groupby_out2.dat", {"assert_list": null, "compare": "diff", "delta": 10000, "extra_files": [], "lines_diff": 0, "sort": false}]], "required_files": [["1.tabular", {"children": [], "value": "1.tabular"}]]}], - "tool_config": "../shed_tools/gvk.bx.psu.edu/repos/test/grouping/935f00105de8/grouping/grouping.xml", - "version": "1.9.0", - "version_string_cmd": null}]}" - OUTSIDE SECTION: - "{"tool_panel_section": {"gvk.bx.psu.edu:9009/repos/test/filter/Filter1/1.0.1": {"id": "", - "name": "", - "tool_config": "filtering.xml", - "version": ""}}, - "tools": [{"description": "data on any column using simple expressions", - "guid": "gvk.bx.psu.edu:9009/repos/test/filter/Filter1/1.0.1", - "id": "Filter1", - "name": "Filter", - "requirements": [], - "tests": [{"inputs": [["input", "1.bed", {"children": [], "value": "1.bed"}], ["cond", "c1=='chr22'", {"children": [], "value": "c1=='chr22'"}]], "name": "Test-1", "outputs": [["out_file1", "filter1_test1.bed", {"assert_list": null, "compare": "diff", "delta": 10000, "extra_files": [], "lines_diff": 0, "sort": false}]], "required_files": [["1.bed", {"children": [], "value": "1.bed"}]]}, {"inputs": [["input", "7.bed", {"children": [], "value": "7.bed"}], ["cond", "c1=='chr1' and c3-c2>=2000 and c6=='+'", {"children": [], "value": "c1=='chr1' and c3-c2>=2000 and c6=='+'"}]], "name": "Test-2", "outputs": [["out_file1", "filter1_test2.bed", {"assert_list": null, "compare": "diff", "delta": 10000, "extra_files": [], "lines_diff": 0, "sort": false}]], "required_files": [["7.bed", {"children": [], "value": "7.bed"}]]}], - "tool_config": "../shed_tools/gvk.bx.psu.edu/repos/test/filter/b2df18d723c5/filter/filtering.xml", - "version": "1.0.1", - "version_string_cmd": null}]}" - """ repository = get_repository( trans, kwd[ 'id' ] ) # Get the location in the tool panel in which the tool was originally loaded. metadata = repository.metadata @@ -679,7 +554,7 @@ message += "Reset all of this reppository's metadata in the tool shed, then set the installed tool versions " message ++ "from the installed repository's <b>Repository Actions</b> menu. " status = 'error' - shed_tool_conf, tool_path, relative_install_dir = self.__get_tool_panel_config_tool_path_install_dir( trans, repository ) + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( trans.app, repository ) repo_files_dir = os.path.abspath( os.path.join( relative_install_dir, repository.name ) ) return trans.fill_template( '/admin/tool_shed_repository/manage_repository.mako', repository=repository, @@ -700,23 +575,12 @@ changeset_revision = params.get( 'changeset_revision', None ) latest_changeset_revision = params.get( 'latest_changeset_revision', None ) repository = get_repository_by_shed_name_owner_changeset_revision( trans.app, tool_shed_url, name, owner, changeset_revision ) - # Get the location in the tool panel in which the tool was originally loaded. - metadata = repository.metadata - if 'tool_panel_section' in metadata: - if panel_entry_per_tool( metadata[ 'tool_panel_section' ] ): - tool_panel_dict = metadata[ 'tool_panel_section' ] - else: - tool_section_dict = metadata[ 'tool_panel_section' ] - tool_section = generate_tool_section_element_from_dict( tool_section_dict ) - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata, tool_section=tool_section ) - else: - tool_panel_dict = generate_tool_panel_dict_for_repository_tools( metadata ) if changeset_revision and latest_changeset_revision: if changeset_revision == latest_changeset_revision: message = "The cloned tool shed repository named '%s' is current (there are no updates available)." % name else: current_working_dir = os.getcwd() - shed_tool_conf, tool_path, relative_install_dir = self.__get_tool_panel_config_tool_path_install_dir( trans, repository ) + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( trans.app, repository ) if relative_install_dir: repo_files_dir = os.path.join( relative_install_dir, name ) returncode, tmp_name = pull_repository( current_working_dir, repo_files_dir, name ) @@ -726,21 +590,8 @@ # Update the repository metadata. repository_clone_url = os.path.join( tool_shed_url, 'repos', owner, name ) tool_shed = clean_tool_shed_url( tool_shed_url ) - tool_shed_repository, metadata_dict = load_repository_contents( trans, - repository_name=name, - description=repository.description, - owner=owner, - changeset_revision=changeset_revision, - tool_path=tool_path, - repository_clone_url=repository_clone_url, - relative_install_dir=relative_install_dir, - current_working_dir=current_working_dir, - tmp_name=tmp_name, - tool_panel_dict=tool_panel_dict, - tool_shed=tool_shed, - tool_section=None, - shed_tool_conf=None, - new_install=False ) + metadata_dict = generate_metadata( trans.app.toolbox, relative_install_dir, repository_clone_url ) + repository.metadata = metadata_dict # Update the repository changeset_revision in the database. repository.changeset_revision = latest_changeset_revision repository.update_available = False @@ -809,77 +660,6 @@ repo_path = items[ 1 ] tool_shed_url = clean_tool_shed_url( tool_shed_url ) return '%s/repos%s/%s' % ( tool_shed_url, repo_path, changeset_revision ) - def __get_tool_panel_config_tool_path_install_dir( self, trans, repository ): - # Return shed-related tool panel config, the tool_path configured in it, and the relative path to the directory where the - # repository is installed. This method assumes all repository tools are defined in a single shed-related tool panel config. - tool_shed = clean_tool_shed_url( repository.tool_shed ) - partial_install_dir = '%s/repos/%s/%s/%s' % ( tool_shed, repository.owner, repository.name, repository.installed_changeset_revision ) - # Get the relative tool installation paths from each of the shed tool configs. - relative_install_dir = None - for shed_tool_conf_dict in trans.app.toolbox.shed_tool_confs: - shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ] - if repository.dist_to_shed: - # The repository is owned by devteam and contains tools migrated from the Galaxy distribution to the tool shed, so - # the reserved tool panel config is migrated_tools_conf.xml, to which trans.app.config.migrated_tools_config refers. - if shed_tool_conf == trans.app.config.migrated_tools_config: - tool_path = shed_tool_conf_dict[ 'tool_path' ] - relative_install_dir = os.path.join( tool_path, partial_install_dir ) - if tool_path and relative_install_dir: - return shed_tool_conf, tool_path, relative_install_dir - elif repository.uninstalled: - # Since the repository is uninstalled we don't know what tool panel config was originally used to - # define the tools in the repository, so we'll just make sure not to use the reserved migrated_tools_conf.xml. - if shed_tool_conf != trans.app.config.migrated_tools_config: - tool_path = shed_tool_conf_dict[ 'tool_path' ] - relative_install_dir = os.path.join( tool_path, partial_install_dir ) - if tool_path and relative_install_dir: - return shed_tool_conf, tool_path, relative_install_dir - else: - if repository.includes_tools: - # We'll check config_elems until we find an element that matches one of the tools in the repository's metadata. - metadata = repository.metadata - tool_dict = metadata[ 'tools' ][ 0 ] - config_elems = shed_tool_conf_dict[ 'config_elems' ] - if config_elems: - tool_path, relative_install_dir = self.__get_tool_path_install_dir( partial_install_dir, - shed_tool_conf_dict, - tool_dict, - config_elems ) - if tool_path and relative_install_dir: - return shed_tool_conf, tool_path, relative_install_dir - else: - # Parse the tool panel config since we have no in-memory config_elems (not sure if this will ever occur). - tool_panel_config = shed_tool_conf_dict[ 'config_filename' ] - tree = util.parse_xml( tool_panel_config ) - root = tree.getroot() - tool_path, relative_install_dir = self.__get_tool_path_install_dir( partial_install_dir, - shed_tool_conf_dict, - tool_dict, - root ) - if tool_path and relative_install_dir: - return shed_tool_conf, tool_path, relative_install_dir - else: - # Nothing will be loaded into the tool panel, so look for the installed repository on disk. - tool_path = shed_tool_conf_dict[ 'tool_path' ] - relative_install_dir = os.path.join( tool_path, partial_install_dir ) - if tool_path and relative_install_dir and os.path.isdir( relative_install_dir ): - return shed_tool_conf, tool_path, relative_install_dir - return None, None, None - def __get_tool_path_install_dir( self, partial_install_dir, shed_tool_conf_dict, tool_dict, config_elems ): - for elem in config_elems: - if elem.tag == 'tool': - if elem.get( 'guid' ) == tool_dict[ 'guid' ]: - tool_path = shed_tool_conf_dict[ 'tool_path' ] - relative_install_dir = os.path.join( tool_path, partial_install_dir ) - return tool_path, relative_install_dir - elif elem.tag == 'section': - for section_elem in elem: - if section_elem.tag == 'tool': - if section_elem.get( 'guid' ) == tool_dict[ 'guid' ]: - tool_path = shed_tool_conf_dict[ 'tool_path' ] - relative_install_dir = os.path.join( tool_path, partial_install_dir ) - return tool_path, relative_install_dir - return None, None ## ---- Utility methods ------------------------------------------------------- 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.
participants (1)
-
Bitbucket