def process_parameter_line(self, line): """ Processes a single script line representing a parameter """ value, _ = self.split_tokens(line) description = RUtils.create_descriptive_name(value) output = create_output_from_string(line) if output is not None: output.setName(value) output.setDescription(description) if issubclass(output.__class__, QgsProcessingOutputDefinition): self.addOutput(output) else: # destination type parameter self.addParameter(output) else: line = RUtils.upgrade_parameter_line(line) # this is annoying, but required to work around a bug in early 3.8.0 versions try: param = getParameterFromString(line, context="") except TypeError: param = getParameterFromString(line) if param is not None: self.addParameter(param) else: self.error = self.tr('This script has a syntax error.\n' 'Problem with line: {0}').format(line)
def process_parameter_line(self, line): """ Processes a single script line representing a parameter """ value, _ = self.split_tokens(line) description = RUtils.create_descriptive_name(value) if not RUtils.is_valid_r_variable(value): self.error = self.tr( 'This script has a syntax error in variable name.\n' '"{1}" is not a valid variable name in R.' 'Problem with line: {0}').format(line, value) output = create_output_from_string(line) if output is not None: output.setName(value) output.setDescription(description) if issubclass(output.__class__, QgsProcessingOutputDefinition): self.addOutput(output) self.save_output_values = True else: # destination type parameter self.addParameter(output) else: line = RUtils.upgrade_parameter_line(line) # this is necessary to remove the otherwise unknown keyword line = line.replace("enum literal", "enum") # this is annoying, but required to work around a bug in early 3.8.0 versions try: param = getParameterFromString(line, context="") except TypeError: param = getParameterFromString(line) # set help parameter if Qgis.QGIS_VERSION_INT >= 31600: if self.descriptions is not None: param.setHelp(self.descriptions.get(param.name())) if param is not None: self.addParameter(param) else: self.error = self.tr('This script has a syntax error.\n' 'Problem with line: {0}').format(line)
def process_parameter_line(self, line): """ Processes a single script line representing a parameter """ value, _ = self.split_tokens(line) description = RUtils.create_descriptive_name(value) if not RUtils.is_valid_r_variable(value): self.add_error_message( self.tr('This script has a syntax error in variable name.\n' '"{1}" is not a valid variable name in R.' 'Problem with line: {0}').format(line, value)) output = create_output_from_string(line) if output is not None: output.setName(value) output.setDescription(description) if issubclass(output.__class__, QgsProcessingOutputDefinition): self.addOutput(output) self.save_output_values = True else: # destination type parameter self.addParameter(output) else: param = create_parameter_from_string(line) if param is not None: # set help parameter if Qgis.QGIS_VERSION_INT >= 31600: if self.descriptions is not None: param.setHelp(self.descriptions.get(param.name())) self.addParameter(param) else: self.add_error_message( self.tr('This script has a syntax error.\n' 'Problem with line: {0}').format(line))
def testDescriptiveName(self): """ Tests creating descriptive name """ self.assertEqual(RUtils.create_descriptive_name('a B_4324_asd'), 'a B 4324 asd')