def process_metadata_line(self, line): # pylint: disable=too-many-return-statements """ Processes a "metadata" (##) line """ line = line.replace('#', '') # special commands # showplots is the older version, should be considere obsolete if line.lower().strip().startswith('output_plots_to_html') or \ line.lower().strip().startswith('showplots'): self.show_plots = True self.addParameter( QgsProcessingParameterFileDestination( RAlgorithm.RPLOTS, self.tr('R Plots'), self.tr('HTML files (*.html)'), optional=True)) return # dontuserasterpackage is the older version, should be considere obsolete if line.lower().strip().startswith('load_raster_using_rgdal') or \ line.lower().strip().startswith('dontuserasterpackage'): self.r_templates.use_raster = False return if line.lower().strip().startswith('load_vector_using_rgdal'): self.r_templates.use_sf = False return # passfilenames is the older version, should be considere obsolete if line.lower().strip().startswith('pass_filenames') or\ line.lower().strip().startswith('passfilenames'): self.pass_file_names = True return if line.lower().strip().startswith('dont_load_any_packages'): self.r_templates.auto_load_packages = False return value, type_ = self.split_tokens(line) if type_.lower().strip() == 'group': self._group = value return if type_.lower().strip() == 'name': self._name = self._display_name = value self._name = RUtils.strip_special_characters(self._name.lower()) return if type_.lower().strip() == 'display_name': self._display_name = value return if type_.lower().strip() == 'github_install': self.r_templates.install_github = True self.r_templates.github_dependencies = value return # process enum with values and preparing its template if "=enum literal" in RUtils.upgrade_parameter_line(line): self.r_templates.add_literal_enum(value) self.process_parameter_line(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) 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 create_parameter_from_string(s: str): """ Tries to create an algorithm parameter from a line string """ if not ("|" in s and s.startswith("QgsProcessingParameter")): s = RUtils.upgrade_parameter_line(s) # this is necessary to remove the otherwise unknown keyword s = s.replace("enum literal", "enum") # this is annoying, but required to work around a bug in early 3.8.0 versions try: param = getParameterFromString(s, context="") except TypeError: param = getParameterFromString(s) return param
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)