1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/97ec62934b6b/ changeset: 97ec62934b6b user: greg date: 2012-12-13 22:19:54 summary: Eliminate unnecessary trans object when only the app is needed downstream. More tool shed util refactoring. affected #: 5 files diff -r 90b28e58bb11eb65bd4f461e0b380c5921c626e2 -r 97ec62934b6b17e674706f2c41ce4b34032fa338 lib/galaxy/tool_shed/install_manager.py --- a/lib/galaxy/tool_shed/install_manager.py +++ b/lib/galaxy/tool_shed/install_manager.py @@ -39,7 +39,7 @@ root = tree.getroot() self.tool_shed = suc.clean_tool_shed_url( root.get( 'name' ) ) self.repository_owner = common_util.REPOSITORY_OWNER - index, self.shed_config_dict = shed_util.get_shed_tool_conf_dict( app, self.migrated_tools_config ) + index, self.shed_config_dict = suc.get_shed_tool_conf_dict( app, self.migrated_tools_config ) # Since tool migration scripts can be executed any number of times, we need to make sure the appropriate tools are defined in # tool_conf.xml. If no tools associated with the migration stage are defined, no repositories will be installed on disk. # The default behavior is that the tool shed is down. @@ -202,7 +202,7 @@ tool_index_sample_files = shed_util.get_tool_index_sample_files( sample_files ) shed_util.copy_sample_files( self.app, tool_index_sample_files, tool_path=self.tool_path ) sample_files_copied = [ s for s in tool_index_sample_files ] - repository_tools_tups = shed_util.get_repository_tools_tups( self.app, metadata_dict ) + repository_tools_tups = suc.get_repository_tools_tups( self.app, metadata_dict ) if repository_tools_tups: # Handle missing data table entries for tool parameters that are dynamically generated select lists. repository_tools_tups = shed_util.handle_missing_data_table_entry( self.app, relative_install_dir, self.tool_path, repository_tools_tups ) diff -r 90b28e58bb11eb65bd4f461e0b380c5921c626e2 -r 97ec62934b6b17e674706f2c41ce4b34032fa338 lib/galaxy/util/shed_util.py --- a/lib/galaxy/util/shed_util.py +++ b/lib/galaxy/util/shed_util.py @@ -34,12 +34,12 @@ for elem_entry in elem_list: config_elems.append( elem_entry ) # Persist the altered shed_tool_config file. - config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path ) + suc.config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path ) def add_to_tool_panel( app, repository_name, repository_clone_url, changeset_revision, repository_tools_tups, owner, shed_tool_conf, tool_panel_dict, new_install=True ): """A tool shed repository is being installed or updated so handle tool panel alterations accordingly.""" # We need to change the in-memory version and the file system version of the shed_tool_conf file. - index, shed_tool_conf_dict = get_shed_tool_conf_dict( app, shed_tool_conf ) + index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf ) tool_path = shed_tool_conf_dict[ 'tool_path' ] # Generate the list of ElementTree Element objects for each section or tool. elem_list = generate_tool_panel_elem_list( repository_name, @@ -155,17 +155,6 @@ except: pass return converter_path, display_path -def config_elems_to_xml_file( app, config_elems, config_filename, tool_path ): - # Persist the current in-memory list of config_elems to a file named by the value of config_filename. - fd, filename = tempfile.mkstemp() - os.write( fd, '<?xml version="1.0"?>\n' ) - os.write( fd, '<toolbox tool_path="%s">\n' % str( tool_path ) ) - for elem in config_elems: - os.write( fd, '%s' % util.xml_to_string( elem, pretty=True ) ) - os.write( fd, '</toolbox>\n' ) - os.close( fd ) - shutil.move( filename, os.path.abspath( config_filename ) ) - os.chmod( config_filename, 0644 ) def copy_sample_files( app, sample_files, tool_path=None, sample_files_copied=None, dest_path=None ): """ Copy all appropriate files to dest_path in the local Galaxy environment that have not already been copied. Those that have been copied @@ -289,26 +278,6 @@ set_status=set_status ) tool_dependency_objects.append( tool_dependency ) return tool_dependency_objects -def generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, tool_section ): - if tool_section is not None: - tool_elem = SubElement( tool_section, 'tool' ) - else: - tool_elem = Element( 'tool' ) - tool_elem.attrib[ 'file' ] = tool_file_path - tool_elem.attrib[ 'guid' ] = tool.guid - tool_shed_elem = SubElement( tool_elem, 'tool_shed' ) - tool_shed_elem.text = tool_shed - repository_name_elem = SubElement( tool_elem, 'repository_name' ) - repository_name_elem.text = repository_name - repository_owner_elem = SubElement( tool_elem, 'repository_owner' ) - repository_owner_elem.text = owner - changeset_revision_elem = SubElement( tool_elem, 'installed_changeset_revision' ) - changeset_revision_elem.text = changeset_revision - id_elem = SubElement( tool_elem, 'id' ) - id_elem.text = tool.id - version_elem = SubElement( tool_elem, 'version' ) - version_elem.text = tool.version - return tool_elem 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 = [] @@ -340,9 +309,9 @@ if tup_guid == guid: break if inside_section: - tool_elem = 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 = 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 @@ -497,34 +466,6 @@ tmp_url = suc.clean_repository_clone_url( repository_clone_url ) tool_shed = tmp_url.split( 'repos' )[ 0 ].rstrip( '/' ) return get_repository_owner( tmp_url ) -def get_repository_tools_tups( app, metadata_dict ): - repository_tools_tups = [] - index, shed_conf_dict = get_shed_tool_conf_dict( app, metadata_dict.get( 'shed_config_filename' ) ) - if 'tools' in metadata_dict: - for tool_dict in metadata_dict[ 'tools' ]: - load_relative_path = relative_path = tool_dict.get( 'tool_config', None ) - if shed_conf_dict.get( 'tool_path' ): - load_relative_path = os.path.join( shed_conf_dict.get( 'tool_path' ), relative_path ) - guid = tool_dict.get( 'guid', None ) - if relative_path and guid: - tool = app.toolbox.load_tool( os.path.abspath( load_relative_path ), guid=guid ) - else: - tool = None - if tool: - repository_tools_tups.append( ( relative_path, guid, tool ) ) - return repository_tools_tups -def get_shed_tool_conf_dict( app, shed_tool_conf ): - """ - Return the in-memory version of the shed_tool_conf file, which is stored in the config_elems entry - in the shed_tool_conf_dict associated with the file. - """ - for index, shed_tool_conf_dict in enumerate( app.toolbox.shed_tool_confs ): - if shed_tool_conf == shed_tool_conf_dict[ 'config_filename' ]: - return index, shed_tool_conf_dict - else: - file_name = suc.strip_path( shed_tool_conf_dict[ 'config_filename' ] ) - if shed_tool_conf == file_name: - return index, shed_tool_conf_dict def get_tool_index_sample_files( sample_files ): """Try to return the list of all appropriate tool data sample files included in the repository.""" tool_index_sample_files = [] @@ -839,12 +780,12 @@ 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( trans.app, config_elems, shed_tool_conf, tool_path ) + suc.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.""" # 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, repository ) + tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( trans.app, repository ) repository.metadata[ 'tool_panel_section' ] = tool_panel_dict trans.sa_session.add( repository ) trans.sa_session.flush() @@ -854,7 +795,7 @@ 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 = get_shed_tool_conf_dict( trans.app, shed_tool_conf ) + index, shed_tool_conf_dict = suc.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( trans, shed_tool_conf_dict, guids_to_remove ) diff -r 90b28e58bb11eb65bd4f461e0b380c5921c626e2 -r 97ec62934b6b17e674706f2c41ce4b34032fa338 lib/galaxy/util/shed_util_common.py --- a/lib/galaxy/util/shed_util_common.py +++ b/lib/galaxy/util/shed_util_common.py @@ -479,6 +479,17 @@ else: message = '' return message +def config_elems_to_xml_file( app, config_elems, config_filename, tool_path ): + # Persist the current in-memory list of config_elems to a file named by the value of config_filename. + fd, filename = tempfile.mkstemp() + os.write( fd, '<?xml version="1.0"?>\n' ) + os.write( fd, '<toolbox tool_path="%s">\n' % str( tool_path ) ) + for elem in config_elems: + os.write( fd, '%s' % util.xml_to_string( elem, pretty=True ) ) + os.write( fd, '</toolbox>\n' ) + os.close( fd ) + shutil.move( filename, os.path.abspath( config_filename ) ) + os.chmod( config_filename, 0644 ) 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.""" sample_files = [] @@ -570,9 +581,9 @@ repository_dependencies, metadata.get( 'tool_dependencies', None ) ) return repo_info_dict -def generate_clone_url_for_installed_repository( trans, repository ): +def generate_clone_url_for_installed_repository( app, repository ): """Generate the URL for cloning a repository that has been installed into a Galaxy instance.""" - tool_shed_url = get_url_from_repository_tool_shed( trans.app, repository ) + tool_shed_url = get_url_from_repository_tool_shed( app, repository ) return url_join( tool_shed_url, 'repos', repository.owner, repository.name ) def generate_clone_url_for_repository_in_tool_shed( trans, repository ): """Generate the URL for cloning a repository that is in the tool shed.""" @@ -949,6 +960,26 @@ handle_existing_tool_dependencies_that_changed_in_update( app, repository, original_tool_dependencies_dict, tool_dependencies_dict ) metadata_dict[ 'tool_dependencies' ] = tool_dependencies_dict return metadata_dict +def generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, tool_section ): + if tool_section is not None: + tool_elem = SubElement( tool_section, 'tool' ) + else: + tool_elem = Element( 'tool' ) + tool_elem.attrib[ 'file' ] = tool_file_path + tool_elem.attrib[ 'guid' ] = tool.guid + tool_shed_elem = SubElement( tool_elem, 'tool_shed' ) + tool_shed_elem.text = tool_shed + repository_name_elem = SubElement( tool_elem, 'repository_name' ) + repository_name_elem.text = repository_name + repository_owner_elem = SubElement( tool_elem, 'repository_owner' ) + repository_owner_elem.text = owner + changeset_revision_elem = SubElement( tool_elem, 'installed_changeset_revision' ) + changeset_revision_elem.text = changeset_revision + id_elem = SubElement( tool_elem, 'id' ) + id_elem.text = tool.id + version_elem = SubElement( tool_elem, 'version' ) + version_elem.text = tool.version + return tool_elem 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 @@ -1003,14 +1034,14 @@ else: metadata_dict[ 'tools' ] = [ tool_dict ] return metadata_dict -def generate_tool_panel_dict_from_shed_tool_conf_entries( trans, repository ): +def generate_tool_panel_dict_from_shed_tool_conf_entries( app, 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 ) + shed_tool_conf, tool_path, relative_install_dir = get_tool_panel_config_tool_path_install_dir( 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 = {} @@ -1386,6 +1417,22 @@ .filter( and_( trans.model.RepositoryMetadata.table.c.repository_id == trans.security.decode_id( id ), trans.model.RepositoryMetadata.table.c.changeset_revision == changeset_revision ) ) \ .first() +def get_repository_tools_tups( app, metadata_dict ): + repository_tools_tups = [] + index, shed_conf_dict = get_shed_tool_conf_dict( app, metadata_dict.get( 'shed_config_filename' ) ) + if 'tools' in metadata_dict: + for tool_dict in metadata_dict[ 'tools' ]: + load_relative_path = relative_path = tool_dict.get( 'tool_config', None ) + if shed_conf_dict.get( 'tool_path' ): + load_relative_path = os.path.join( shed_conf_dict.get( 'tool_path' ), relative_path ) + guid = tool_dict.get( 'guid', None ) + if relative_path and guid: + tool = app.toolbox.load_tool( os.path.abspath( load_relative_path ), guid=guid ) + else: + tool = None + if tool: + repository_tools_tups.append( ( relative_path, guid, tool ) ) + return repository_tools_tups def get_relative_path_to_repository_file( root, name, relative_install_dir, work_dir, shed_config_dict, resetting_all_metadata_on_repository ): if resetting_all_metadata_on_repository: full_path_to_file = os.path.join( root, name ) @@ -1428,6 +1475,18 @@ relative_path_to_sample_file = relative_path_to_sample_file[ len( tool_path ) + 1 :] sample_file_metadata_paths.append( relative_path_to_sample_file ) return sample_file_metadata_paths, sample_file_copy_paths +def get_shed_tool_conf_dict( app, shed_tool_conf ): + """ + Return the in-memory version of the shed_tool_conf file, which is stored in the config_elems entry + in the shed_tool_conf_dict associated with the file. + """ + for index, shed_tool_conf_dict in enumerate( app.toolbox.shed_tool_confs ): + if shed_tool_conf == shed_tool_conf_dict[ 'config_filename' ]: + return index, shed_tool_conf_dict + else: + file_name = suc.strip_path( shed_tool_conf_dict[ 'config_filename' ] ) + if shed_tool_conf == file_name: + return index, shed_tool_conf_dict 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. @@ -1852,7 +1911,7 @@ """Reset all metadata on a single tool shed repository installed into a Galaxy instance.""" repository = get_installed_tool_shed_repository( trans, id ) tool_shed_url = get_url_from_repository_tool_shed( trans.app, repository ) - repository_clone_url = generate_clone_url_for_installed_repository( trans, repository ) + repository_clone_url = generate_clone_url_for_installed_repository( trans.app, repository ) tool_path, relative_install_dir = repository.get_tool_relative_path( trans.app ) if relative_install_dir: original_metadata_dict = repository.metadata @@ -2178,15 +2237,9 @@ shed_conf_dict = repository.get_shed_config_dict( app ) shed_tool_conf = shed_conf_dict[ 'config_filename' ] tool_path = shed_conf_dict[ 'tool_path' ] - - # TODO Fix this - we should be able to pass only app - we should not need trans... - #hack for 'trans.app' used in lots of places. These places should just directly use app - trans = util.bunch.Bunch() - trans.app = app - - tool_panel_dict = generate_tool_panel_dict_from_shed_tool_conf_entries( trans, repository ) + tool_panel_dict = generate_tool_panel_dict_from_shed_tool_conf_entries( app, repository ) repository_tools_tups = get_repository_tools_tups( app, repository.metadata ) - cleaned_repository_clone_url = clean_repository_clone_url( generate_clone_url_for_installed_repository( trans, repository ) ) + cleaned_repository_clone_url = clean_repository_clone_url( generate_clone_url_for_installed_repository( app, repository ) ) tool_shed = tool_shed_from_repository_clone_url( cleaned_repository_clone_url ) owner = repository.owner if not owner: diff -r 90b28e58bb11eb65bd4f461e0b380c5921c626e2 -r 97ec62934b6b17e674706f2c41ce4b34032fa338 lib/galaxy/webapps/community/controllers/repository.py --- a/lib/galaxy/webapps/community/controllers/repository.py +++ b/lib/galaxy/webapps/community/controllers/repository.py @@ -2,6 +2,7 @@ from time import gmtime, strftime from datetime import date, datetime from galaxy import util +from galaxy.util.odict import odict from galaxy.web.base.controller import * from galaxy.web.form_builder import CheckboxField from galaxy.webapps.community import model diff -r 90b28e58bb11eb65bd4f461e0b380c5921c626e2 -r 97ec62934b6b17e674706f2c41ce4b34032fa338 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 @@ -310,13 +310,13 @@ """Activate a repository that was deactivated but not uninstalled.""" repository = suc.get_installed_tool_shed_repository( trans, kwd[ 'id' ] ) shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( trans.app, repository ) - repository_clone_url = suc.generate_clone_url_for_installed_repository( trans, repository ) + repository_clone_url = suc.generate_clone_url_for_installed_repository( trans.app, repository ) repository.deleted = False repository.status = trans.model.ToolShedRepository.installation_status.INSTALLED if repository.includes_tools: metadata = repository.metadata try: - repository_tools_tups = shed_util.get_repository_tools_tups( trans.app, metadata ) + repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata ) except Exception, e: error = "Error activating repository %s: %s" % ( repository.name, str( e ) ) log.debug( error ) @@ -795,7 +795,7 @@ tool_index_sample_files = shed_util.get_tool_index_sample_files( sample_files ) shed_util.copy_sample_files( self.app, tool_index_sample_files, tool_path=tool_path ) sample_files_copied = [ str( s ) for s in tool_index_sample_files ] - repository_tools_tups = shed_util.get_repository_tools_tups( trans.app, metadata_dict ) + repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata_dict ) if repository_tools_tups: # Handle missing data table entries for tool parameters that are dynamically generated select lists. repository_tools_tups = shed_util.handle_missing_data_table_entry( trans.app, relative_install_dir, tool_path, repository_tools_tups ) @@ -1295,7 +1295,7 @@ new_tool_panel_section = kwd.get( 'new_tool_panel_section', '' ) tool_panel_section = kwd.get( 'tool_panel_section', '' ) shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( trans.app, tool_shed_repository ) - repository_clone_url = suc.generate_clone_url_for_installed_repository( trans, tool_shed_repository ) + repository_clone_url = suc.generate_clone_url_for_installed_repository( trans.app, tool_shed_repository ) clone_dir = os.path.join( tool_path, self.generate_tool_path( repository_clone_url, tool_shed_repository.installed_changeset_revision ) ) relative_install_dir = os.path.join( clone_dir, tool_shed_repository.name ) tool_shed_url = suc.get_url_from_repository_tool_shed( trans.app, tool_shed_repository ) @@ -1466,7 +1466,7 @@ metadata = tool_shed_repository.metadata tool_shed_url = suc.get_url_from_repository_tool_shed( trans.app, tool_shed_repository ) ctx_rev = shed_util.get_ctx_rev( tool_shed_url, tool_shed_repository.name, tool_shed_repository.owner, tool_shed_repository.installed_changeset_revision ) - repository_clone_url = suc.generate_clone_url_for_installed_repository( trans, tool_shed_repository ) + repository_clone_url = suc.generate_clone_url_for_installed_repository( trans.app, tool_shed_repository ) repository_dependencies = self.get_repository_dependencies( trans=trans, repository_id=repository_id, repository_name=tool_shed_repository.name, @@ -1572,7 +1572,7 @@ """Reset all metadata on a single installed tool shed repository.""" repository = suc.get_installed_tool_shed_repository( trans, id ) tool_shed_url = suc.get_url_from_repository_tool_shed( trans.app, repository ) - repository_clone_url = suc.generate_clone_url_for_installed_repository( trans, repository ) + repository_clone_url = suc.generate_clone_url_for_installed_repository( trans.app, repository ) tool_path, relative_install_dir = repository.get_tool_relative_path( trans.app ) if relative_install_dir: original_metadata_dict = repository.metadata 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.