commit/galaxy-central: dan: Give Data Managers from Tool Sheds their own guid.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/8484a745317e/ changeset: 8484a745317e user: dan date: 2013-02-15 18:01:44 summary: Give Data Managers from Tool Sheds their own guid. affected #: 3 files diff -r ef0e9bf34c0b22dd355759478aa85fc2d46d49d4 -r 8484a745317e5402e987401c85359e8c7a513445 lib/galaxy/tools/data_manager/manager.py --- a/lib/galaxy/tools/data_manager/manager.py +++ b/lib/galaxy/tools/data_manager/manager.py @@ -64,31 +64,38 @@ self.managed_data_tables[ data_table_name ].append( data_manager ) def get_manager( self, *args, **kwds ): return self.data_managers.get( *args, **kwds ) - def remove_manager( self, manager_id ): - data_manager = self.get_manager( manager_id, None ) - if data_manager is not None: - del self.data_managers[ manager_id ] - #remove tool from toolbox - if data_manager.tool: - self.app.toolbox.remove_tool_by_id( data_manager.tool.id ) - #determine if any data_tables are no longer tracked - for data_table_name in data_manager.data_tables.keys(): - remove_data_table_tracking = True - for other_data_manager in self.data_managers.itervalues(): - if data_table_name in other_data_manager.data_tables: - remove_data_table_tracking = False - break - if remove_data_table_tracking and data_table_name in self.managed_data_tables: - del self.managed_data_tables[ data_table_name ] + def remove_manager( self, manager_ids ): + if not isinstance( manager_ids, list ): + manager_ids = [ manager_ids ] + for manager_id in manager_ids: + data_manager = self.get_manager( manager_id, None ) + if data_manager is not None: + del self.data_managers[ manager_id ] + #remove tool from toolbox + if data_manager.tool: + self.app.toolbox.remove_tool_by_id( data_manager.tool.id ) + #determine if any data_tables are no longer tracked + for data_table_name in data_manager.data_tables.keys(): + remove_data_table_tracking = True + for other_data_manager in self.data_managers.itervalues(): + if data_table_name in other_data_manager.data_tables: + remove_data_table_tracking = False + break + if remove_data_table_tracking and data_table_name in self.managed_data_tables: + del self.managed_data_tables[ data_table_name ] class DataManager( object ): + GUID_TYPE = 'data_manager' + DEFAULT_VERSION = "0.0.1" + def __init__( self, data_managers, elem=None, tool_path=None ): self.data_managers = data_managers self.declared_id = None self.name = None self.description = None + self.version = self.DEFAULT_VERSION + self.guid = None self.tool = None - self.tool_guid = None self.data_tables = odict() self.output_ref_by_data_table = {} self.move_by_data_table_column = {} @@ -98,12 +105,14 @@ def load_from_element( self, elem, tool_path ): assert elem.tag == 'data_manager', 'A data manager configuration must have a "data_manager" tag as the root. "%s" is present' % ( root.tag ) self.declared_id = elem.get( 'id', None ) + self.guid = elem.get( 'guid', None ) path = elem.get( 'tool_file', None ) + tool_guid = None if path is None: tool_elem = elem.find( 'tool' ) assert tool_elem is not None, "Error loading tool for data manager. Make sure that a tool_file attribute or a tool tag set has been defined:\n%s" % ( util.xml_to_string( elem ) ) path = tool_elem.get( "file", None ) - self.tool_guid = tool_elem.get( "guid", None ) + tool_guid = tool_elem.get( "guid", None ) #use shed_conf_file to determine tool_path shed_conf_file = elem.get( "shed_conf_file", None ) if shed_conf_file: @@ -111,7 +120,7 @@ if shed_conf: tool_path = shed_conf.get( "tool_path", tool_path ) assert path is not None, "A tool file path could not be determined:\n%s" % ( util.xml_to_string( elem ) ) - self.load_tool( os.path.join( tool_path, path ), guid=self.tool_guid, data_manager_id=self.id ) + self.load_tool( os.path.join( tool_path, path ), guid=tool_guid, data_manager_id=self.id ) self.name = elem.get( 'name', self.tool.name ) self.description = elem.get( 'description', self.tool.description ) @@ -164,7 +173,7 @@ self.move_by_data_table_column[ data_table_name ][ data_table_coumn_name ] = dict( type=move_type, source_base=source_base, source_value=source_value, target_base=target_base, target_value=target_value, relativize_symlinks=relativize_symlinks ) @property def id( self ): - return self.tool_guid or self.declared_id #if we have a tool with a guid, we will use that as the tool_manager id + return self.guid or self.declared_id #if we have a guid, we will use that as the data_manager id def load_tool( self, tool_filename, guid=None, data_manager_id=None ): tool = self.data_managers.app.toolbox.load_tool( tool_filename, guid=guid, data_manager_id=data_manager_id ) self.data_managers.app.toolbox.data_manager_tools[ tool.id ] = tool diff -r ef0e9bf34c0b22dd355759478aa85fc2d46d49d4 -r 8484a745317e5402e987401c85359e8c7a513445 lib/galaxy/util/shed_util.py --- a/lib/galaxy/util/shed_util.py +++ b/lib/galaxy/util/shed_util.py @@ -1194,7 +1194,11 @@ if data_manager_dict is None: log.error( "Data manager metadata is not defined properly for '%s'." % ( data_manager_id ) ) continue - + guid = data_manager_dict.get( 'guid', None ) + if guid is None: + log.error( "Data manager guid '%s' is not set in metadata for '%s'." % ( guid, data_manager_id ) ) + continue + elem.set( 'guid', guid ) tool_guid = data_manager_dict.get( 'tool_guid', None ) if tool_guid is None: log.error( "Data manager tool guid '%s' is not set in metadata for '%s'." % ( tool_guid, data_manager_id ) ) @@ -1510,27 +1514,18 @@ def remove_from_data_manager( app, repository ): metadata_dict = repository.metadata if metadata_dict and 'data_manager' in metadata_dict: - data_manager_tool_guids = [ data_manager_dict.get( 'tool_guid' ) for data_manager_dict in metadata_dict.get( 'data_manager', {} ).get( 'data_managers', {} ).itervalues() if 'tool_guid' in data_manager_dict ] shed_data_manager_conf_filename = app.config.shed_data_manager_config_file tree = util.parse_xml( shed_data_manager_conf_filename ) root = tree.getroot() assert root.tag == 'data_managers', 'The file provided (%s) for removing data managers from is not a valid data manager xml file.' % ( shed_data_manager_conf_filename ) + guids = [ data_manager_dict.get( 'guid' ) for data_manager_dict in metadata_dict.get( 'data_manager', {} ).get( 'data_managers', {} ).itervalues() if 'guid' in data_manager_dict ] config_elems = [] for elem in root: - keep_elem = True - if elem.tag == 'data_manager': - tool_elem = elem.find( 'tool' ) - if tool_elem is not None: - tool_guid = tool_elem.get( 'guid', None ) - if tool_guid in data_manager_tool_guids: - keep_elem = False - if keep_elem: + if elem.tag != 'data_manager' or elem.get( 'guid', None ) not in guids: config_elems.append( elem ) - #remove data manager from in memory - for data_manager_tool_guids in data_manager_tool_guids: - #for shed-based data managers, the data_manager id is the same as the tool guid - app.data_managers.remove_manager( data_manager_tool_guids ) - # Persist the altered shed_tool_config file. + #remove data managers from in memory + app.data_managers.remove_manager( guids ) + # Persist the altered shed_data_manager_config file. suc.data_manager_config_elems_to_xml_file( app, config_elems, shed_data_manager_conf_filename ) 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 diff -r ef0e9bf34c0b22dd355759478aa85fc2d46d49d4 -r 8484a745317e5402e987401c85359e8c7a513445 lib/galaxy/util/shed_util_common.py --- a/lib/galaxy/util/shed_util_common.py +++ b/lib/galaxy/util/shed_util_common.py @@ -13,6 +13,7 @@ import sqlalchemy.orm.exc from galaxy.tools.parameters import dynamic_options from galaxy.tool_shed import encoding_util +from galaxy.tools.data_manager.manager import DataManager from galaxy import eggs import pkg_resources @@ -1012,7 +1013,7 @@ def generate_clone_url_for_repository_in_tool_shed( trans, repository ): """Generate the URL for cloning a repository that is in the tool shed.""" base_url = url_for( '/', qualified=True ).rstrip( '/' ) - if trans.user: + if trans and trans.user: protocol, base = base_url.split( '://' ) username = '%s@' % trans.user.username return '%s://%s%s/repos/%s/%s' % ( protocol, username, base, repository.user.username, repository.name ) @@ -1038,10 +1039,14 @@ tools[tool_conf_name] = tool repo_path = repository.repo_path( app ) try: + #Galaxy Side repo_files_directory = repository.repo_files_directory( app ) repo_dir = repo_files_directory + repository_clone_url = generate_clone_url_for_installed_repository( app, repository ) except AttributeError: + #Tool Shed side repo_files_directory = repo_path + repository_clone_url = generate_clone_url_for_repository_in_tool_shed( None, repository ) relative_data_manager_dir = util.relpath( os.path.split( data_manager_config_filename )[0], repo_dir ) rel_data_manager_config_filename = os.path.join( relative_data_manager_dir, os.path.split( data_manager_config_filename )[1] ) data_managers = {} @@ -1057,6 +1062,8 @@ if data_manager_id is None: log.error( 'Data Manager entry is missing id attribute in "%s".' % ( data_manager_config_filename ) ) continue + version = data_manager_elem.get( 'version', DataManager.DEFAULT_VERSION ) + guid = generate_guid_for_object( repository_clone_url, DataManager.GUID_TYPE, data_manager_id, version ) data_tables = [] if tool_file is None: log.error( 'Data Manager entry is missing tool_file attribute in "%s".' % ( data_manager_config_filename ) ) @@ -1073,7 +1080,7 @@ if tool is None: log.error( "Unable to determine tools metadata for '%s'." % ( data_manager_metadata_tool_file ) ) continue - data_managers[ data_manager_id ] = { 'tool_config_file': data_manager_metadata_tool_file, 'data_tables': data_tables, 'tool_guid': tool['guid'] } + data_managers[ data_manager_id ] = { 'guid': guid, 'version': version, 'tool_config_file': data_manager_metadata_tool_file, 'data_tables': data_tables, 'tool_guid': tool['guid'] } log.debug( 'Loaded Data Manager tool_files: %s' % ( tool_file ) ) return metadata_dict def generate_datatypes_metadata( datatypes_config, metadata_dict ): @@ -1555,6 +1562,9 @@ version_elem = SubElement( tool_elem, 'version' ) version_elem.text = tool.version return tool_elem +def generate_guid_for_object( repository_clone_url, guid_type, obj_id, version ): + tmp_url = clean_repository_clone_url( repository_clone_url ) + return '%s/%s/%s/%s' % ( tmp_url, guid_type, obj_id, version ) def generate_tool_guid( repository_clone_url, tool ): """ Generate a guid for the installed tool. It is critical that this guid matches the guid for 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