def __init__(self, dataset, datatypes_registry=None, tool=None, name=None, compute_environment=None, identifier=None, io_type="input", formats=None): if not dataset: try: # TODO: allow this to work when working with grouping ext = tool.inputs[name].extensions[0] except Exception: ext = 'data' self.dataset = wrap_with_safe_string( NoneDataset(datatypes_registry=datatypes_registry, ext=ext), no_wrap_classes=ToolParameterValueWrapper) else: # Tool wrappers should not normally be accessing .dataset directly, # so we will wrap it and keep the original around for file paths # Should we name this .value to maintain consistency with most other ToolParameterValueWrapper? if formats: direct_match, target_ext, converted_dataset = dataset.find_conversion_destination( formats) if not direct_match and target_ext and converted_dataset: dataset = converted_dataset self.unsanitized = dataset self.dataset = wrap_with_safe_string( dataset, no_wrap_classes=ToolParameterValueWrapper) self.metadata = self.MetadataWrapper(dataset, compute_environment) if hasattr(dataset, 'tags'): self.groups = { tag.user_value.lower() for tag in dataset.tags if tag.user_tname == 'group' } else: # May be a 'FakeDatasetAssociation' self.groups = set() self.compute_environment = compute_environment # TODO: lazy initialize this... self.__io_type = io_type if self.__io_type == "input": path_rewrite = compute_environment and dataset and compute_environment.input_path_rewrite( dataset) if path_rewrite: self.false_path = path_rewrite else: self.false_path = None else: path_rewrite = compute_environment and compute_environment.output_path_rewrite( dataset) if path_rewrite: self.false_path = path_rewrite else: self.false_path = None self.datatypes_registry = datatypes_registry self._element_identifier = identifier
def __sanitize_param_dict(self, param_dict): """ Sanitize all values that will be substituted on the command line, with the exception of ToolParameterValueWrappers, which already have their own specific sanitization rules and also exclude special-cased named values. We will only examine the first level for values to skip; the wrapping function will recurse as necessary. Note: this method follows the style of the similar populate calls, in that param_dict is modified in-place. """ # chromInfo is a filename, do not sanitize it. skip = ['chromInfo'] + list(self.tool.template_macro_params.keys()) if not self.tool or not self.tool.options or self.tool.options.sanitize: for key, value in list(param_dict.items()): if key not in skip: # Remove key so that new wrapped object will occupy key slot del param_dict[key] # And replace with new wrapped key param_dict[wrap_with_safe_string(key, no_wrap_classes=ToolParameterValueWrapper)] = wrap_with_safe_string(value, no_wrap_classes=ToolParameterValueWrapper)
def __getattr__(self, name: str) -> Any: rval = self.metadata.get(name, None) if name in self.metadata.spec: if rval is None: rval = self.metadata.spec[name].no_value metadata_param = self.metadata.spec[name].param from galaxy.model.metadata import FileParameter rval = metadata_param.to_safe_string(rval) if isinstance(metadata_param, FileParameter) and self.compute_environment: rewrite = self.compute_environment.input_metadata_rewrite( self.dataset, rval) if rewrite is not None: rval = rewrite # Store this value, so we don't need to recalculate if needed # again setattr(self, name, rval) else: # escape string value of non-defined metadata value rval = wrap_with_safe_string(rval) return rval