details: http://www.bx.psu.edu/hg/galaxy/rev/cfe79f4c6673 changeset: 1706:cfe79f4c6673 user: Greg Von Kuster <greg@bx.psu.edu> date: Wed Jan 14 17:20:22 2009 -0500 description: Add a SelectToolParameterWrapper object and a wrap method to Tool.execute() that allows for things like the following in tool configs: <outputs> <data format="input" name="output" label="Blat on {<input_param>.value_label}" /> </outputs> Also replace EOL chars with <br> in a tool's output data.info so that they are displayed in HTML. 3 file(s) affected in this change: lib/galaxy/datatypes/data.py lib/galaxy/tools/__init__.py lib/galaxy/tools/actions/__init__.py diffs (108 lines): diff -r 4a067f42c725 -r cfe79f4c6673 lib/galaxy/datatypes/data.py --- a/lib/galaxy/datatypes/data.py Wed Jan 14 16:15:51 2009 -0500 +++ b/lib/galaxy/datatypes/data.py Wed Jan 14 17:20:22 2009 -0500 @@ -132,7 +132,8 @@ def display_info(self, dataset): """Returns formated html of dataset info""" try: - return escape(dataset.info) + # Change new line chars to html + return escape( dataset.info ).replace( "\r", "\n" ).replace( "\n", "<br>" ) except: return "info unavailable" def validate(self, dataset): diff -r 4a067f42c725 -r cfe79f4c6673 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py Wed Jan 14 16:15:51 2009 -0500 +++ b/lib/galaxy/tools/__init__.py Wed Jan 14 17:20:22 2009 -0500 @@ -1072,10 +1072,11 @@ datatypes_registry = self.app.datatypes_registry, tool = self, name = input.name ) + elif isinstance( input, SelectToolParameter ): + input_values[ input.name ] = SelectToolParameterWrapper( input, input_values[ input.name ], self.app ) else: - input_values[ input.name ] = \ - InputValueWrapper( input, input_values[ input.name ], param_dict ) - # HACK: only wrap if check_values is false, this deals with external + input_values[ input.name ] = InputValueWrapper( input, input_values[ input.name ], param_dict ) + # HACK: only wrap if check_values is not false, this deals with external # tools where the inputs don't even get passed through. These # tools (e.g. UCSC) should really be handled in a special way. if self.check_values: @@ -1416,7 +1417,21 @@ return self.input.to_param_dict_string( self.value, self._other_values ) def __getattr__( self, key ): return getattr( self.value, key ) - + +class SelectToolParameterWrapper( object ): + """ + Wraps a SelectTooParameter so that __str__ returns the selected value, but all other + attributes are accessible. + """ + def __init__( self, input, value, app ): + self.input = input + self.value = value + self.input.value_label = input.value_to_display_text( value, app ) + def __str__( self ): + return self.input.to_param_dict_string( self.value ) + def __getattr__( self, key ): + return getattr( self.input, key ) + class DatasetFilenameWrapper( object ): """ Wraps a dataset so that __str__ returns the filename, but all other diff -r 4a067f42c725 -r cfe79f4c6673 lib/galaxy/tools/actions/__init__.py --- a/lib/galaxy/tools/actions/__init__.py Wed Jan 14 16:15:51 2009 -0500 +++ b/lib/galaxy/tools/actions/__init__.py Wed Jan 14 17:20:22 2009 -0500 @@ -1,9 +1,11 @@ from galaxy.util.bunch import Bunch from galaxy.tools.parameters import * +from galaxy.tools.parameters.grouping import * from galaxy.util.template import fill_template from galaxy.util.none_like import NoneDataset from galaxy.web import url_for from galaxy.jobs import JOB_OK +import galaxy.tools import logging log = logging.getLogger( __name__ ) @@ -65,6 +67,26 @@ return input_datasets def execute(self, tool, trans, incoming={}, set_output_hid=True ): + def wrap_values( inputs, input_values ): + # Wrap tool inputs as necessary + for input in inputs.itervalues(): + if isinstance( input, Repeat ): + for d in input_values[ input.name ]: + wrap_values( input.inputs, d ) + elif isinstance( input, Conditional ): + values = input_values[ input.name ] + current = values["__current_case__"] + wrap_values( input.cases[current].inputs, values ) + elif isinstance( input, DataToolParameter ): + input_values[ input.name ] = \ + galaxy.tools.DatasetFilenameWrapper( input_values[ input.name ], + datatypes_registry = trans.app.datatypes_registry, + tool = tool, + name = input.name ) + elif isinstance( input, SelectToolParameter ): + input_values[ input.name ] = galaxy.tools.SelectToolParameterWrapper( input, input_values[ input.name ], tool.app ) + else: + input_values[ input.name ] = galaxy.tools.InputValueWrapper( input, input_values[ input.name ], incoming ) out_data = {} # Collect any input datasets from the incoming parameters inp_data = self.collect_input_datasets( tool, incoming, trans ) @@ -151,6 +173,11 @@ # Set output label if output.label: params = dict( incoming ) + # wrapping the params allows the tool config to contain things like + # <outputs> + # <data format="input" name="output" label="Blat on ${<input_param>.name}" /> + # </outputs> + wrap_values( tool.inputs, params ) params['tool'] = tool params['on_string'] = on_text data.name = fill_template( output.label, context=params )