Beispiel #1
0
 def defineCharacteristicsFromFile(self):
     self.script = ""
     self.commands = []
     self.showPlots = False
     self.showConsoleOutput = False
     self.verboseCommands = []
     filename = os.path.basename(self.descriptionFile)
     self.name = filename[:filename.rfind(".")].replace("_", " ")
     self.group = "User R scripts"
     lines = open(self.descriptionFile)
     line = lines.readline().strip("\n")
     while line != "":
         if line.startswith("##"):
             try:
                 self.processParameterLine(line)
             except Exception:
                 raise WrongScriptException("Could not load R script:" +
                                            self.descriptionFile +
                                            ".\n Problem with line \"" +
                                            line + "\"")
         elif line.startswith(">"):
             self.commands.append(line[1:])
             self.verboseCommands.append(line[1:])
             if not self.showConsoleOutput:
                 self.addOutput(
                     OutputHTML(RAlgorithm.R_CONSOLE_OUTPUT,
                                "R Console Output"))
             self.showConsoleOutput = True
         else:
             self.commands.append(line)
         self.script += line + "\n"
         line = lines.readline().strip("\n")
     lines.close()
Beispiel #2
0
 def processDescriptionParameterLine(self, line):
     try:
         if line.startswith("Parameter"):
             self.addParameter(ParameterFactory.getFromString(line))
         elif line.startswith("*Parameter"):
             param = ParameterFactory.getFromString(line[1:])
             param.isAdvanced = True
             self.addParameter(param)
         else:
             self.addOutput(OutputFactory.getFromString(line))
     except Exception:
         raise WrongScriptException("Could not load script:" + self.descriptionFile + ".\n Problem with line \"" + line + "\"")
Beispiel #3
0
 def defineCharacteristicsFromFile(self):
     self.script=""
     self.silentOutputs = []
     filename = os.path.basename(self.descriptionFile)
     self.name = filename[:filename.rfind(".")].replace("_", " ")
     self.group = "User scripts"
     lines = open(self.descriptionFile)
     line = lines.readline()
     while line != "":
         if line.startswith("##"):
             try:
                 self.processParameterLine(line.strip("\n"))
             except:
                 raise  WrongScriptException("Could not load script: " + self.descriptionFile +"\n" + "Problem with line: " + line)
         self.script += line
         line = lines.readline()
     lines.close()
Beispiel #4
0
 def parseDescription(self, lines):
     self.script = ""
     self.commands = []
     self.showPlots = False
     self.showConsoleOutput = False
     self.useRasterPackage = True
     self.passFileNames = False
     self.verboseCommands = []
     ender = 0
     line = lines.next().strip("\n").strip("\r")
     while ender < 10:
         if line.startswith("##"):
             try:
                 self.processParameterLine(line)
             except Exception:
                 raise WrongScriptException("Could not load R script:" +
                                            self.descriptionFile +
                                            ".\n Problem with line \"" +
                                            line + "\"")
         elif line.startswith(">"):
             self.commands.append(line[1:])
             self.verboseCommands.append(line[1:])
             if not self.showConsoleOutput:
                 self.addOutput(
                     OutputHTML(RAlgorithm.R_CONSOLE_OUTPUT,
                                "R Console Output"))
             self.showConsoleOutput = True
         else:
             if line == '':
                 ender += 1
             else:
                 ender = 0
             self.commands.append(line)
         self.script += line + "\n"
         try:
             line = lines.next().strip("\n").strip("\r")
         except:
             break
Beispiel #5
0
    def processParameterLine(self,line):
        param = None
        out = None
        line = line.replace("#", "");
        # If the line is in the format of the text description files for normal algorithms,
        # then process it using parameter and output factories
        if '|' in line:
            self.processDescriptionParameterLine(line)
            return
        tokens = line.split("=");
        desc = self.createDescriptiveName(tokens[0])
        if tokens[1].lower().strip() == "group":
            self.group = tokens[0]
            return
        if tokens[1].lower().strip() == "name":
            self.name = tokens[0]
            return
        if tokens[1].lower().strip() == "raster":
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "vector":
            param = ParameterVector(tokens[0],  desc,ParameterVector.VECTOR_TYPE_ANY)
        elif tokens[1].lower().strip() == "table":
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "multiple raster":
            param = ParameterMultipleInput(tokens[0], desc, ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == "multiple vector":
            param = ParameterMultipleInput(tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith("selection"):
            options = tokens[1].strip()[len("selection"):].split(";")
            param = ParameterSelection(tokens[0],  desc, options);
        elif tokens[1].lower().strip().startswith("boolean"):
            default = tokens[1].strip()[len("boolean")+1:]
            param = ParameterBoolean(tokens[0],  desc, default)
        elif tokens[1].lower().strip() == "extent":
            param = ParameterExtent(tokens[0],  desc)
        elif tokens[1].lower().strip() == "file":
            param = ParameterFile(tokens[0],  desc, False)
        elif tokens[1].lower().strip() == "folder":
            param = ParameterFile(tokens[0],  desc, True)
        elif tokens[    1].lower().strip().startswith("number"):
            default = tokens[1].strip()[len("number")+1:]
            param = ParameterNumber(tokens[0],  desc, default=default)
        elif tokens[1].lower().strip().startswith("field"):
            field = tokens[1].strip()[len("field")+1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0],  tokens[0], field)
        elif tokens[1].lower().strip().startswith("string"):
            default = tokens[1].strip()[len("string")+1:]
            param = ParameterString(tokens[0],  desc, default)
        elif tokens[1].lower().strip().startswith("output raster"):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith("output vector"):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith("output table"):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith("output html"):
            out = OutputHTML()
        elif tokens[1].lower().strip().startswith("output file"):
            out = OutputFile()
        elif tokens[1].lower().strip().startswith("output number"):
            out = OutputNumber()
        elif tokens[1].lower().strip().startswith("output string"):
            out = OutputString()

        if param != None:
            self.addParameter(param)
        elif out != None:
            out.name = tokens[0]
            out.description = tokens[0]
            self.addOutput(out)
        else:
            raise WrongScriptException("Could not load script:" + self.descriptionFile + ".\n Problem with line \"" + line + "\"")
Beispiel #6
0
    def processParameterLine(self, line):
        param = None
        out = None
        line = line.replace("#", "")
        if line.lower().strip().startswith("showplots"):
            self.showPlots = True
            self.addOutput(OutputHTML(RAlgorithm.RPLOTS, "R Plots"))
            return
        if line.lower().strip().startswith("dontuserasterpackage"):
            self.useRasterPackage = False
            return
        if line.lower().strip().startswith("passfilenames"):
            self.passFileNames = True
            return
        tokens = line.split("=")
        desc = self.createDescriptiveName(tokens[0])
        if tokens[1].lower().strip() == "group":
            self.group = tokens[0]
            return
        if tokens[1].lower().strip().startswith("raster"):
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "vector":
            param = ParameterVector(tokens[0], desc,
                                    ParameterVector.VECTOR_TYPE_ANY)
        elif tokens[1].lower().strip() == "table":
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip().startswith("multiple raster"):
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == "multiple vector":
            param = ParameterMultipleInput(
                tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith("selection"):
            options = tokens[1].strip()[len("selection"):].split(";")
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith("boolean"):
            default = tokens[1].strip()[len("boolean") + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith("number"):
            try:
                default = float(tokens[1].strip()[len("number") + 1:])
                param = ParameterNumber(tokens[0], desc, default=default)
            except:
                raise WrongScriptException("Could not load R script:" +
                                           self.descriptionFile +
                                           ".\n Problem with line \"" + line +
                                           "\"")
        elif tokens[1].lower().strip().startswith("field"):
            field = tokens[1].strip()[len("field") + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], tokens[0], field)
        elif tokens[1].lower().strip() == "extent":
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == "file":
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "folder":
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith("string"):
            default = tokens[1].strip()[len("string") + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith("output raster"):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith("output vector"):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith("output table"):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith("output file"):
            out = OutputFile()

        if param != None:
            self.addParameter(param)
        elif out != None:
            out.name = tokens[0]
            out.description = tokens[0]
            self.addOutput(out)
        else:
            raise WrongScriptException("Could not load R script:" +
                                       self.descriptionFile +
                                       ".\n Problem with line \"" + line +
                                       "\"")