10 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/9e973ebf7272/ Changeset: 9e973ebf7272 User: jmchilton Date: 2014-12-22 18:16:25+00:00 Summary: Remove some unused imports from lib/galaxy/tools/__init__.py. Affected #: 1 file diff -r 815d38c48a5639d47eed92806ef4c196406f58f1 -r 9e973ebf7272bcd1ff684e82bfb62b4938875f94 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -7,20 +7,15 @@ import json import logging import os -import pipes import re import shutil -import sys import string import tarfile import tempfile import threading -import traceback import types import urllib -from math import isinf - from galaxy import eggs eggs.require( "MarkupSafe" ) # MarkupSafe must load before mako eggs.require( "Mako" ) @@ -35,10 +30,8 @@ from sqlalchemy import and_ from galaxy import jobs, model -from galaxy.jobs.error_level import StdioErrorLevel from galaxy.datatypes.metadata import JobExternalOutputMetadataWrapper from galaxy import exceptions -from galaxy.jobs import ParallelismInfo from galaxy.tools import watcher from galaxy.tools.actions import DefaultToolAction from galaxy.tools.actions.data_source import DataSourceToolAction @@ -58,12 +51,11 @@ from galaxy.tools.test import parse_tests from galaxy.tools.parser import get_tool_source from galaxy.tools.parser.xml import XmlPageSource -from galaxy.util import listify, parse_xml, rst_to_html, string_as_bool, string_to_object, xml_text, xml_to_string +from galaxy.util import listify, parse_xml, rst_to_html, string_as_bool, string_to_object from galaxy.tools.parameters.meta import expand_meta_parameters from galaxy.util.bunch import Bunch from galaxy.util.expressions import ExpressionContext from galaxy.util.hash_util import hmac_new -from galaxy.util.none_like import NoneDataset from galaxy.util.odict import odict from galaxy.util.template import fill_template from galaxy.web import url_for @@ -73,7 +65,7 @@ from galaxy.model import Workflow from tool_shed.util import common_util from tool_shed.util import shed_util_common as suc -from .loader import load_tool, template_macro_params, raw_tool_xml_tree, imported_macro_paths +from .loader import template_macro_params, raw_tool_xml_tree, imported_macro_paths from .execute import execute as execute_job from .wrappers import ( ToolParameterValueWrapper, https://bitbucket.org/galaxy/galaxy-central/commits/6e956fdb0034/ Changeset: 6e956fdb0034 User: jmchilton Date: 2014-12-22 18:16:25+00:00 Summary: More PEP-8 style tweaks to lib/galaxy/tools/__init__.py. Affected #: 1 file diff -r 9e973ebf7272bcd1ff684e82bfb62b4938875f94 -r 6e956fdb003441f699e24750f02c61c43992a784 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -257,8 +257,9 @@ return tool_path def __add_tool_to_tool_panel( self, tool, panel_component, section=False ): - # See if a version of this tool is already loaded into the tool panel. The value of panel_component - # will be a ToolSection (if the value of section=True) or self.tool_panel (if section=False). + # See if a version of this tool is already loaded into the tool panel. + # The value of panel_component will be a ToolSection (if the value of + # section=True) or self.tool_panel (if section=False). tool_id = str( tool.id ) tool = self.tools_by_id[ tool_id ] if section: @@ -300,13 +301,17 @@ if not inserted: inserted = True if not inserted: - if tool.guid is None or \ - tool.tool_shed is None or \ - tool.repository_name is None or \ - tool.repository_owner is None or \ - tool.installed_changeset_revision is None: - # We have a tool that was not installed from the Tool Shed, but is also not yet defined in - # integrated_tool_panel.xml, so append it to the tool panel. + if ( + tool.guid is None or + tool.tool_shed is None or + tool.repository_name is None or + tool.repository_owner is None or + tool.installed_changeset_revision is None + ): + # We have a tool that was not installed from the Tool + # Shed, but is also not yet defined in + # integrated_tool_panel.xml, so append it to the tool + # panel. panel_dict[ key ] = tool log.debug( "Loaded tool id: %s, version: %s into tool panel.." % ( tool.id, tool.version ) ) else: @@ -364,9 +369,10 @@ def load_integrated_tool_panel_keys( self ): """ - Load the integrated tool panel keys, setting values for tools and workflows to None. The values will - be reset when the various tool panel config files are parsed, at which time the tools and workflows are - loaded. + Load the integrated tool panel keys, setting values for tools and + workflows to None. The values will be reset when the various tool + panel config files are parsed, at which time the tools and workflows + are loaded. """ tree = parse_xml( self.integrated_tool_panel_config ) root = tree.getroot() @@ -499,11 +505,11 @@ # We store only the port, if one exists, in the database. tool_shed = common_util.remove_protocol_from_tool_shed_url( tool_shed ) return self.app.install_model.context.query( self.app.install_model.ToolShedRepository ) \ - .filter( and_( self.app.install_model.ToolShedRepository.table.c.tool_shed == tool_shed, - self.app.install_model.ToolShedRepository.table.c.name == name, - self.app.install_model.ToolShedRepository.table.c.owner == owner, - self.app.install_model.ToolShedRepository.table.c.installed_changeset_revision == installed_changeset_revision ) ) \ - .first() + .filter( and_( self.app.install_model.ToolShedRepository.table.c.tool_shed == tool_shed, + self.app.install_model.ToolShedRepository.table.c.name == name, + self.app.install_model.ToolShedRepository.table.c.owner == owner, + self.app.install_model.ToolShedRepository.table.c.installed_changeset_revision == installed_changeset_revision ) ) \ + .first() def get_tool_components( self, tool_id, tool_version=None, get_loaded_tools_by_lineage=False, set_selected=False ): """ @@ -627,12 +633,14 @@ log.exception( "Error reading tool from path: %s" % path ) def __add_tool( self, tool, load_panel_dict, panel_dict ): - # Allow for the same tool to be loaded into multiple places in the tool panel. We have to handle - # the case where the tool is contained in a repository installed from the tool shed, and the Galaxy - # administrator has retrieved updates to the installed repository. In this case, the tool may have - # been updated, but the version was not changed, so the tool should always be reloaded here. We used - # to only load the tool if it was not found in self.tools_by_id, but performing that check did - # not enable this scenario. + # Allow for the same tool to be loaded into multiple places in the + # tool panel. We have to handle the case where the tool is contained + # in a repository installed from the tool shed, and the Galaxy + # administrator has retrieved updates to the installed repository. In + # this case, the tool may have been updated, but the version was not + # changed, so the tool should always be reloaded here. We used to + # only load the tool if it was not found in self.tools_by_id, but + # performing that check did not enable this scenario. self.tools_by_id[ tool.id ] = tool if load_panel_dict: self.__add_tool_to_tool_panel( tool, panel_dict, section=isinstance( panel_dict, ToolSection ) ) @@ -787,8 +795,6 @@ :param tool_id: the tool ID from app.toolbox :returns: tuple of tarball filename, success True/False, message/None """ - message = '' - success = True # Make sure the tool is actually loaded. if tool_id not in self.tools_by_id: return None, False, "No tool with id %s" % escape( tool_id ) @@ -870,7 +876,6 @@ if os.path.exists( sample_file ): tarfile_path, tarfile_name = os.path.split( tar_file ) tarfile_path = os.path.join( 'tool-data', tarfile_name ) - sample_name = tarfile_path + '.sample' tarball_files.append( ( sample_file, tarfile_path ) ) data_table_definitions.append( data_table.xml_string ) if len( data_table_definitions ) > 0: https://bitbucket.org/galaxy/galaxy-central/commits/50a4c5ef908c/ Changeset: 50a4c5ef908c User: jmchilton Date: 2014-12-22 18:16:26+00:00 Summary: Small simplifications to lib/galaxy/tools/__init__.py. Affected #: 1 file diff -r 6e956fdb003441f699e24750f02c61c43992a784 -r 50a4c5ef908c38ecf6530d7ac9dd3a497d1ec313 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -289,8 +289,7 @@ for index, integrated_panel_key in enumerate( self.integrated_tool_panel.keys() ): if key == integrated_panel_key: panel_dict.insert( index, key, tool ) - if not inserted: - inserted = True + inserted = True if not inserted: # Check the tool's installed versions. for lineage_id in tool.lineage_ids: @@ -298,8 +297,7 @@ for index, integrated_panel_key in enumerate( self.integrated_tool_panel.keys() ): if lineage_id_key == integrated_panel_key: panel_dict.insert( index, key, tool ) - if not inserted: - inserted = True + inserted = True if not inserted: if ( tool.guid is None or @@ -322,8 +320,7 @@ if lineage_id in self.tools_by_id: loaded_version_key = 'tool_%s' % lineage_id if loaded_version_key in panel_dict: - if not already_loaded: - already_loaded = True + already_loaded = True if not already_loaded: # If the tool is not defined in integrated_tool_panel.xml, append it to the tool panel. panel_dict[ key ] = tool https://bitbucket.org/galaxy/galaxy-central/commits/de3fff02e89f/ Changeset: de3fff02e89f User: jmchilton Date: 2014-12-22 18:16:26+00:00 Summary: Remove broken method fix_integrated_tool_panel_dict. As of 5f6c670 (Jan 10, 2014) this does nothing (``if section_value is None`` followed by ``if isinstance( section_value, Tool ):``) and nobody seemed to notice - so I assume it is unneeded. If still needed - someone needs to fix it :). Affected #: 1 file diff -r 50a4c5ef908c38ecf6530d7ac9dd3a497d1ec313 -r de3fff02e89fd4697e9656742ca8e3f4928b1a53 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -163,24 +163,8 @@ # This will cover cases where the Galaxy administrator manually edited one or more of the tool panel # config files, adding or removing locally developed tools or workflows. The value of integrated_tool_panel # will be False when things like functional tests are the caller. - self.fix_integrated_tool_panel_dict() self.write_integrated_tool_panel_config_file() - def fix_integrated_tool_panel_dict( self ): - # HACK: instead of fixing after the fact, I suggest some combination of: - # 1) adjusting init_tools() and called methods to get this right - # 2) redesigning the code and/or data structure used to read/write integrated_tool_panel.xml - for key, value in self.integrated_tool_panel.iteritems(): - if isinstance( value, ToolSection ): - for section_key, section_value in value.elems.iteritems(): - if section_value is None: - if isinstance( section_value, Tool ): - tool_id = section_key[5:] - value.elems[section_key] = self.tools_by_id.get( tool_id ) - elif isinstance( section_value, Workflow ): - workflow_id = section_key[9:] - value.elems[section_key] = self.workflows_by_id.get( workflow_id ) - def init_tools( self, config_filename ): """ Read the configuration file and load each tool. The following tags are currently supported: @@ -723,7 +707,6 @@ # This will cover cases where the Galaxy administrator manually edited one or more of the tool panel # config files, adding or removing locally developed tools or workflows. The value of integrated_tool_panel # will be False when things like functional tests are the caller. - self.fix_integrated_tool_panel_dict() self.write_integrated_tool_panel_config_file() return tool.id except Exception: https://bitbucket.org/galaxy/galaxy-central/commits/79f06cadb486/ Changeset: 79f06cadb486 User: jmchilton Date: 2014-12-22 18:16:27+00:00 Summary: Slightly rework lib/galaxy/workflow/modules.py for readability. Affected #: 1 file diff -r de3fff02e89fd4697e9656742ca8e3f4928b1a53 -r 79f06cadb4861bc6e66a1733a0c3bbfa4606240c lib/galaxy/workflow/modules.py --- a/lib/galaxy/workflow/modules.py +++ b/lib/galaxy/workflow/modules.py @@ -506,16 +506,17 @@ @classmethod def from_workflow_step( Class, trans, step ): + toolbox = trans.app.toolbox tool_id = step.tool_id - if trans.app.toolbox and tool_id not in trans.app.toolbox.tools_by_id: + if toolbox and tool_id not in toolbox.tools_by_id: # See if we have access to a different version of the tool. # TODO: If workflows are ever enhanced to use tool version # in addition to tool id, enhance the selection process here # to retrieve the correct version of the tool. - tool = trans.app.toolbox.get_tool( tool_id ) + tool = toolbox.get_tool( tool_id ) if tool: tool_id = tool.id - if ( trans.app.toolbox and tool_id in trans.app.toolbox.tools_by_id ): + if ( toolbox and tool_id in toolbox.tools_by_id ): if step.config: # This step has its state saved in the config field due to the # tool being previously unavailable. https://bitbucket.org/galaxy/galaxy-central/commits/4be779372d6b/ Changeset: 4be779372d6b User: jmchilton Date: 2014-12-22 18:16:27+00:00 Summary: Rework toolbox 'fix' tool tags when multiple configs are loaded. Looks like the tool tag stuff still assumed there was just one config file - that said toolbox doesn't have a self.sa_session so I think tool tags are broken and have been for some time. Affected #: 1 file diff -r 79f06cadb4861bc6e66a1733a0c3bbfa4606240c -r 4be779372d6b89656276307f4ae1ed4a8e6a5737 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -143,6 +143,26 @@ self.tool_watcher = watcher.get_watcher( self, app.config ) self.filter_factory = FilterFactory( self ) self.init_dependency_manager() + self.init_tools_from_configs( config_filenames ) + if self.app.name == 'galaxy' and self.integrated_tool_panel_config_has_contents: + # Load self.tool_panel based on the order in self.integrated_tool_panel. + self.load_tool_panel() + if app.config.update_integrated_tool_panel: + # Write the current in-memory integrated_tool_panel to the integrated_tool_panel.xml file. + # This will cover cases where the Galaxy administrator manually edited one or more of the tool panel + # config files, adding or removing locally developed tools or workflows. The value of integrated_tool_panel + # will be False when things like functional tests are the caller. + self.write_integrated_tool_panel_config_file() + + def init_tools_from_configs( self, config_filenames ): + """ Read through all tool config files and initialize tools in each + with init_tools_from_config below. + """ + if self.app.config.get_bool( 'enable_tool_tags', False ): + log.info("removing all tool tag associations (" + str( self.sa_session.query( self.app.model.ToolTagAssociation ).count() ) + ")" ) + self.sa_session.query( self.app.model.ToolTagAssociation ).delete() + self.sa_session.flush() + config_filenames = listify( config_filenames ) for config_filename in config_filenames: if os.path.isdir( config_filename ): @@ -152,20 +172,11 @@ config_filenames.extend( directory_config_files ) for config_filename in config_filenames: try: - self.init_tools( config_filename ) + self.init_tools_from_config( config_filename ) except: log.exception( "Error loading tools defined in config %s", config_filename ) - if self.app.name == 'galaxy' and self.integrated_tool_panel_config_has_contents: - # Load self.tool_panel based on the order in self.integrated_tool_panel. - self.load_tool_panel() - if app.config.update_integrated_tool_panel: - # Write the current in-memory integrated_tool_panel to the integrated_tool_panel.xml file. - # This will cover cases where the Galaxy administrator manually edited one or more of the tool panel - # config files, adding or removing locally developed tools or workflows. The value of integrated_tool_panel - # will be False when things like functional tests are the caller. - self.write_integrated_tool_panel_config_file() - - def init_tools( self, config_filename ): + + def init_tools_from_config( self, config_filename ): """ Read the configuration file and load each tool. The following tags are currently supported: @@ -183,10 +194,6 @@ </toolbox> """ - if self.app.config.get_bool( 'enable_tool_tags', False ): - log.info("removing all tool tag associations (" + str( self.sa_session.query( self.app.model.ToolTagAssociation ).count() ) + ")" ) - self.sa_session.query( self.app.model.ToolTagAssociation ).delete() - self.sa_session.flush() log.info( "Parsing the tool configuration %s" % config_filename ) tree = parse_xml( config_filename ) root = tree.getroot() https://bitbucket.org/galaxy/galaxy-central/commits/267fa4b9ab6a/ Changeset: 267fa4b9ab6a User: jmchilton Date: 2014-12-22 18:16:28+00:00 Summary: Refactor tool tag handling out of toolbox. Pretty sure this had been broken (toolbox didn't have a self.sa_session). Anyway - this probably didn't fix that but at least now the big read tool tag loop is more readable (cyclomatic complexity of that method down from 18 to 12). Affected #: 3 files diff -r 4be779372d6b89656276307f4ae1ed4a8e6a5737 -r 267fa4b9ab6a80a0ae0a1f2ab5f157303f68d46d lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -51,6 +51,7 @@ from galaxy.tools.test import parse_tests from galaxy.tools.parser import get_tool_source from galaxy.tools.parser.xml import XmlPageSource +from galaxy.tools.toolbox import tool_tag_manager from galaxy.util import listify, parse_xml, rst_to_html, string_as_bool, string_to_object from galaxy.tools.parameters.meta import expand_meta_parameters from galaxy.util.bunch import Bunch @@ -143,6 +144,7 @@ self.tool_watcher = watcher.get_watcher( self, app.config ) self.filter_factory = FilterFactory( self ) self.init_dependency_manager() + self.tool_tag_manager = tool_tag_manager( app ) self.init_tools_from_configs( config_filenames ) if self.app.name == 'galaxy' and self.integrated_tool_panel_config_has_contents: # Load self.tool_panel based on the order in self.integrated_tool_panel. @@ -158,11 +160,7 @@ """ Read through all tool config files and initialize tools in each with init_tools_from_config below. """ - if self.app.config.get_bool( 'enable_tool_tags', False ): - log.info("removing all tool tag associations (" + str( self.sa_session.query( self.app.model.ToolTagAssociation ).count() ) + ")" ) - self.sa_session.query( self.app.model.ToolTagAssociation ).delete() - self.sa_session.flush() - + self.tool_tag_manager.reset_tags() config_filenames = listify( config_filenames ) for config_filename in config_filenames: if os.path.isdir( config_filename ): @@ -588,27 +586,7 @@ self.app.install_model.context.flush() # Load the tool's lineage ids. tool.lineage_ids = tool.tool_version.get_version_ids( self.app ) - if self.app.config.get_bool( 'enable_tool_tags', False ): - tag_names = elem.get( "tags", "" ).split( "," ) - for tag_name in tag_names: - if tag_name == '': - continue - tag = self.sa_session.query( self.app.model.Tag ).filter_by( name=tag_name ).first() - if not tag: - tag = self.app.model.Tag( name=tag_name ) - self.sa_session.add( tag ) - self.sa_session.flush() - tta = self.app.model.ToolTagAssociation( tool_id=tool.id, tag_id=tag.id ) - self.sa_session.add( tta ) - self.sa_session.flush() - else: - for tagged_tool in tag.tagged_tools: - if tagged_tool.tool_id == tool.id: - break - else: - tta = self.app.model.ToolTagAssociation( tool_id=tool.id, tag_id=tag.id ) - self.sa_session.add( tta ) - self.sa_session.flush() + self.tool_tag_manager.handle_tags( tool.id, elem ) self.__add_tool( tool, load_panel_dict, panel_dict ) # Always load the tool into the integrated_panel_dict, or it will not be included in the integrated_tool_panel.xml file. if key in integrated_panel_dict or index is None: diff -r 4be779372d6b89656276307f4ae1ed4a8e6a5737 -r 267fa4b9ab6a80a0ae0a1f2ab5f157303f68d46d lib/galaxy/tools/toolbox/__init__.py --- /dev/null +++ b/lib/galaxy/tools/toolbox/__init__.py @@ -0,0 +1,7 @@ +""" API for this module containing functionality related to the tool box. +""" + +from .tags import tool_tag_manager + + +__all__ = ["tool_tag_manager"] diff -r 4be779372d6b89656276307f4ae1ed4a8e6a5737 -r 267fa4b9ab6a80a0ae0a1f2ab5f157303f68d46d lib/galaxy/tools/toolbox/tags.py --- /dev/null +++ b/lib/galaxy/tools/toolbox/tags.py @@ -0,0 +1,76 @@ +""" Handle details of tool tagging - perhaps a deprecated feature. +""" +from abc import ABCMeta +from abc import abstractmethod + +import logging +log = logging.getLogger( __name__ ) + + +def tool_tag_manager( app ): + """ Build a tool tag manager according to app's configuration + and return it. + """ + if hasattr( app.config, "get_bool" ) and app.config.get_bool( 'enable_tool_tags', False ): + return PersistentToolTagManager( app ) + else: + return NullToolTagManager() + + +class AbstractToolTagManager( object ): + __metaclass__ = ABCMeta + + @abstractmethod + def reset_tags( self ): + """ Starting to load tool panels, reset all tags. + """ + + @abstractmethod + def handle_tags( self, tool_id, tool_definition_source ): + """ Parse out tags and persist them. + """ + + +class NullToolTagManager( AbstractToolTagManager ): + + def reset_tags( self ): + return None + + def handle_tags( self, tool_id, tool_definition_source ): + return None + + +class PersistentToolTagManager( AbstractToolTagManager ): + + def __init__( self, app ): + self.app = app + self.sa_session = app.sa_session + + def reset_tags( self ): + log.info("removing all tool tag associations (" + str( self.sa_session.query( self.app.model.ToolTagAssociation ).count() ) + ")" ) + self.sa_session.query( self.app.model.ToolTagAssociation ).delete() + self.sa_session.flush() + + def handle_tags( self, tool_id, tool_definition_source ): + elem = tool_definition_source + if self.app.config.get_bool( 'enable_tool_tags', False ): + tag_names = elem.get( "tags", "" ).split( "," ) + for tag_name in tag_names: + if tag_name == '': + continue + tag = self.sa_session.query( self.app.model.Tag ).filter_by( name=tag_name ).first() + if not tag: + tag = self.app.model.Tag( name=tag_name ) + self.sa_session.add( tag ) + self.sa_session.flush() + tta = self.app.model.ToolTagAssociation( tool_id=tool_id, tag_id=tag.id ) + self.sa_session.add( tta ) + self.sa_session.flush() + else: + for tagged_tool in tag.tagged_tools: + if tagged_tool.tool_id == tool_id: + break + else: + tta = self.app.model.ToolTagAssociation( tool_id=tool_id, tag_id=tag.id ) + self.sa_session.add( tta ) + self.sa_session.flush() https://bitbucket.org/galaxy/galaxy-central/commits/d0c38a7861e5/ Changeset: d0c38a7861e5 User: jmchilton Date: 2014-12-22 18:16:28+00:00 Summary: Tweak completely broken DataTransfer._execute_workflow to respect toolbox abstraction. Least of the brokeness at this point I suppose - but I would like to not expose tools_by_id external to the Toolbox. Affected #: 1 file diff -r 267fa4b9ab6a80a0ae0a1f2ab5f157303f68d46d -r d0c38a7861e5d42f6068963f0917a78cdc9e6860 lib/galaxy/jobs/deferred/data_transfer.py --- a/lib/galaxy/jobs/deferred/data_transfer.py +++ b/lib/galaxy/jobs/deferred/data_transfer.py @@ -356,7 +356,7 @@ for i, step in enumerate( workflow.steps ): job = None if step.type == 'tool' or step.type is None: - tool = self.app.toolbox.tools_by_id[ step.tool_id ] + tool = self.app.toolbox.get_tool( step.tool_id ) def callback( input, value, prefixed_name, prefixed_label ): if isinstance( input, DataToolParameter ): if prefixed_name in step.input_connections_by_name: https://bitbucket.org/galaxy/galaxy-central/commits/34b3e1ca729d/ Changeset: 34b3e1ca729d User: jmchilton Date: 2014-12-22 18:16:30+00:00 Summary: Start decoupling Toolbox elements from XML (sections+labels). Just a small tweak and some tests to verify these things can indeed be created from dictionaries. Also slightly simplifies galaxy.tools. Affected #: 2 files diff -r d0c38a7861e5d42f6068963f0917a78cdc9e6860 -r 34b3e1ca729df33c32e96ca9202d3a80836c21ed lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -330,12 +330,13 @@ elif isinstance( val, ToolSectionLabel ): self.tool_panel[ key ] = val elif isinstance( val, ToolSection ): - elem = ElementTree.Element( 'section' ) - elem.attrib[ 'id' ] = val.id or '' - elem.attrib[ 'name' ] = val.name or '' - elem.attrib[ 'version' ] = val.version or '' - section = ToolSection( elem ) - log.debug( "Loading section: %s" % elem.get( 'name' ) ) + section_dict = { + 'id': val.id or '', + 'name': val.name or '', + 'version': val.version or '', + } + section = ToolSection( section_dict ) + log.debug( "Loading section: %s" % section_dict.get( 'name' ) ) for section_key, section_val in val.elems.items(): if isinstance( section_val, Tool ): tool_id = section_key.replace( 'tool_', '', 1 ) @@ -1050,6 +1051,8 @@ dict_collection_visible_keys = ( 'id', 'name', 'version' ) def __init__( self, elem=None ): + """ Build a ToolSection from an ElementTree element or a dictionary. + """ f = lambda elem, val: elem is not None and elem.get( val ) or '' self.name = f( elem, 'name' ) self.id = f( elem, 'id' ) @@ -1089,6 +1092,9 @@ dict_collection_visible_keys = ( 'id', 'text', 'version' ) def __init__( self, elem ): + """ Build a ToolSectionLabel from an ElementTree element or a + dictionary. + """ self.text = elem.get( "text" ) self.id = elem.get( "id" ) self.version = elem.get( "version" ) or '' diff -r d0c38a7861e5d42f6068963f0917a78cdc9e6860 -r 34b3e1ca729df33c32e96ca9202d3a80836c21ed test/unit/tools/test_tool_panel.py --- /dev/null +++ b/test/unit/tools/test_tool_panel.py @@ -0,0 +1,26 @@ +from xml.etree import ElementTree as ET +from galaxy.tools import ToolSection + + +def test_tool_section( ): + elem = ET.Element( 'section' ) + elem.attrib[ 'name' ] = "Cool Tools" + elem.attrib[ 'id' ] = "cool1" + + section = ToolSection( elem ) + assert section.id == "cool1" + assert section.name == "Cool Tools" + assert section.version == "" + + section = ToolSection( dict( + id="cool1", + name="Cool Tools" + ) ) + assert section.id == "cool1" + assert section.name == "Cool Tools" + assert section.version == "" + + section = ToolSection() + assert section.id == "" + assert section.name == "" + assert section.version == "" https://bitbucket.org/galaxy/galaxy-central/commits/1aa8a57c5994/ Changeset: 1aa8a57c5994 User: jmchilton Date: 2014-12-22 18:16:30+00:00 Summary: Add comment to auto-generated integrated_tool_panel.xml. Someone more familiar with integrated_tool_panel.xml should feel free to make this comment sharper - but something is better nothing I think. Affected #: 1 file diff -r 34b3e1ca729df33c32e96ca9202d3a80836c21ed -r 1aa8a57c599455b2a9faeeadb980b62b8abecc1f lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -96,6 +96,16 @@ HELP_UNINITIALIZED = threading.Lock() +INTEGRATED_TOOL_PANEL_DESCRIPTION = """ +This is Galaxy's integrated tool panel and probably should not be modified +directly. It will be regenerated each time Galaxy starts up. To modify locally +managed tools (e.g. from tool_conf.xml) modify that file directly and restart +Galaxy. Whenever possible Tool Shed managed tools (e.g. from shed_tool_conf.xml) +should be managed from within the Galaxy interface of via is UI - but if changes +are nessecary (such as to hide a tool or re-assign its section) modify that file +and restart Galaxy. +""" + class ToolNotFoundException( Exception ): pass @@ -396,6 +406,9 @@ fd, filename = tempfile.mkstemp() os.write( fd, '<?xml version="1.0"?>\n' ) os.write( fd, '<toolbox>\n' ) + os.write( fd, ' <!--\n ') + os.write( fd, '\n '.join( [ l for l in INTEGRATED_TOOL_PANEL_DESCRIPTION.split("\n") if l ] ) ) + os.write( fd, '\n -->\n') for key, item in self.integrated_tool_panel.items(): if item: if isinstance( item, Tool ): 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.