コード例 #1
0
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     for descriptionFile in os.listdir(folder):
         if descriptionFile.endswith("model"):
             try:
                 alg = ModelerAlgorithm()
                 fullpath = os.path.join(ModelerUtils.modelsFolder(),descriptionFile)
                 alg.openModel(fullpath)
                 if alg.name.strip() != "":
                     alg.provider = self
                     self.algs.append(alg)
             except WrongModelException,e:
                 SextanteLog.addToLog(SextanteLog.LOG_ERROR,"Could not load model " + descriptionFile + "\n" + e.msg)
コード例 #2
0
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     for descriptionFile in os.listdir(folder):
         if descriptionFile.endswith("model"):
             try:
                 alg = ModelerAlgorithm()
                 fullpath = os.path.join(ModelerUtils.modelsFolder(),descriptionFile)
                 alg.openModel(fullpath)
                 if alg.name.strip() != "":
                     alg.provider = self
                     self.algs.append(alg)
             except WrongModelException,e:
                 SextanteLog.addToLog(SextanteLog.LOG_ERROR,"Could not load model " + descriptionFile + "\n" + e.msg)
コード例 #3
0
    def openModel(self, filename):
        self.algPos = []
        self.paramPos = []
        self.algs = []
        self.algParameters = []
        self.algOutputs = []
        self.paramValues = {}
        self.dependencies = []

        self.descriptionFile = filename
        lines = codecs.open(filename, "r", encoding='utf-8')
        line = lines.readline().strip("\n")
        iAlg = 0
        try:
            while line != "":
                if line.startswith("PARAMETER:"):
                    paramLine = line[len("PARAMETER:"):]
                    param = ParameterFactory.getFromString(paramLine)
                    if param:
                        self.parameters.append(param)
                    else:
                        raise WrongModelException("Error in line: " + line)
                    line = lines.readline().strip("\n")
                    tokens = line.split(",")
                    self.paramPos.append(QtCore.QPointF(float(tokens[0]), float(tokens[1])))
                elif line.startswith("VALUE:"):
                    valueLine = line[len("VALUE:"):]
                    tokens = valueLine.split("===")

                    self.paramValues[tokens[0]] = tokens[1].replace(ModelerAlgorithm.LINE_BREAK_STRING, '\n')
                elif line.startswith("NAME:"):
                    self.name = line[len("NAME:"):]
                elif line.startswith("GROUP:"):
                    self.group = line[len("GROUP:"):]
                elif line.startswith("ALGORITHM:"):
                    algParams={}
                    algOutputs={}
                    algLine = line[len("ALGORITHM:"):]
                    alg = ModelerUtils.getAlgorithm(algLine)
                    if alg:
                        posline = lines.readline().strip("\n")
                        tokens = posline.split(",")
                        self.algPos.append(QtCore.QPointF(float(tokens[0]), float(tokens[1])))
                        self.algs.append(alg)
                        dependenceline = lines.readline().strip("\n")
                        dependencies = [];
                        if dependenceline != str(None):
                            for index in dependenceline.split(","):
                                dependencies.append(int(index))
                        for param in alg.parameters:
                            line = lines.readline().strip("\n")
                            if line==str(None):
                                algParams[param.name] = None
                            else:
                                tokens = line.split("|")
                                algParams[param.name] = AlgorithmAndParameter(int(tokens[0]), tokens[1])
                        for out in alg.outputs:
                            line = lines.readline().strip("\n")
                            if str(None)!=line:
                                algOutputs[out.name] = line
                                #we add the output to the algorithm, with a name indicating where it comes from
                                #that guarantees that the name is unique
                                output = copy.deepcopy(out)
                                output.description = line
                                output.name = self.getSafeNameForOutput(iAlg, output)
                                self.addOutput(output)
                            else:
                                algOutputs[out.name] = None
                        self.algOutputs.append(algOutputs)
                        self.algParameters.append(algParams)
                        self.dependencies.append(dependencies)
                        iAlg += 1
                    else:
                        raise WrongModelException("Error in line: " + line)
                line = lines.readline().strip("\n")
        except:
            raise WrongModelException("Error in line: " + line)
コード例 #4
0
    def openModel(self, filename):
        self.algPos = []
        self.paramPos = []
        self.algs = []
        self.algParameters = []
        self.algOutputs = []
        self.paramValues = {}

        self.descriptionFile = filename
        lines = codecs.open(filename, "r", encoding='utf-8')
        line = lines.readline().strip("\n")
        iAlg = 0
        try:
            while line != "":
                if line.startswith("PARAMETER:"):
                    paramLine = line[len("PARAMETER:"):]
                    param = ParameterFactory.getFromString(paramLine)
                    if param:
                        self.parameters.append(param)
                    else:
                        raise WrongModelException("Error in line: " + line)
                    line = lines.readline().strip("\n")
                    tokens = line.split(",")
                    self.paramPos.append(
                        QtCore.QPointF(float(tokens[0]), float(tokens[1])))
                elif line.startswith("VALUE:"):
                    valueLine = line[len("VALUE:"):]
                    tokens = valueLine.split("=")
                    self.paramValues[tokens[0]] = tokens[1]
                elif line.startswith("NAME:"):
                    self.name = line[len("NAME:"):]
                elif line.startswith("GROUP:"):
                    self.group = line[len("GROUP:"):]
                elif line.startswith("ALGORITHM:"):
                    algParams = {}
                    algOutputs = {}
                    algLine = line[len("ALGORITHM:"):]
                    alg = ModelerUtils.getAlgorithm(algLine)
                    if alg:
                        posline = lines.readline().strip("\n")
                        tokens = posline.split(",")
                        self.algPos.append(
                            QtCore.QPointF(float(tokens[0]), float(tokens[1])))
                        self.algs.append(alg)
                        for param in alg.parameters:
                            line = lines.readline().strip("\n")
                            if line == str(None):
                                algParams[param.name] = None
                            else:
                                tokens = line.split("|")
                                algParams[param.name] = AlgorithmAndParameter(
                                    int(tokens[0]), tokens[1])
                        for out in alg.outputs:
                            line = lines.readline().strip("\n")
                            if str(None) != line:
                                algOutputs[out.name] = line
                                #we add the output to the algorithm, with a name indicating where it comes from
                                #that guarantees that the name is unique
                                output = copy.deepcopy(out)
                                output.description = line
                                output.name = self.getSafeNameForOutput(
                                    iAlg, output)
                                self.addOutput(output)
                            else:
                                algOutputs[out.name] = None
                        self.algOutputs.append(algOutputs)
                        self.algParameters.append(algParams)
                        iAlg += 1
                    else:
                        raise WrongModelException("Error in line: " + line)
                line = lines.readline().strip("\n")
        except WrongModelException:
            raise WrongModelException(line)
コード例 #5
0
    def openModel(self, filename):
        self.algPos = []
        self.paramPos = []
        self.algs = []
        self.algParameters = []
        self.algOutputs = []
        self.paramValues = {}
        self.dependencies = []

        self.descriptionFile = filename
        lines = codecs.open(filename, "r", encoding='utf-8')
        line = lines.readline().strip("\n").strip("\r")
        iAlg = 0
        try:
            while line != "":
                if line.startswith("PARAMETER:"):
                    paramLine = line[len("PARAMETER:"):]
                    param = ParameterFactory.getFromString(paramLine)
                    if param:
                        self.parameters.append(param)
                    else:
                        raise WrongModelException("Error in parameter line: " +
                                                  line)
                    line = lines.readline().strip("\n")
                    tokens = line.split(",")
                    self.paramPos.append(
                        QtCore.QPointF(float(tokens[0]), float(tokens[1])))
                elif line.startswith("VALUE:"):
                    valueLine = line[len("VALUE:"):]
                    tokens = valueLine.split("===")
                    self.paramValues[tokens[0]] = tokens[1].replace(
                        ModelerAlgorithm.LINE_BREAK_STRING, '\n')
                elif line.startswith("NAME:"):
                    self.name = line[len("NAME:"):]
                elif line.startswith("GROUP:"):
                    self.group = line[len("GROUP:"):]
                elif line.startswith("ALGORITHM:"):
                    algParams = {}
                    algOutputs = {}
                    algLine = line[len("ALGORITHM:"):]
                    alg = ModelerUtils.getAlgorithm(algLine)
                    if alg is not None:
                        posline = lines.readline().strip("\n").strip("\r")
                        tokens = posline.split(",")
                        self.algPos.append(
                            QtCore.QPointF(float(tokens[0]), float(tokens[1])))
                        self.algs.append(alg)
                        dependenceline = lines.readline().strip("\n").strip(
                            "\r")
                        dependencies = []
                        if dependenceline != str(None):
                            for index in dependenceline.split(","):
                                try:
                                    dependencies.append(int(index))
                                except:
                                    pass  #a quick fix fwhile I figure out how to solve problems when parsing this
                        for param in alg.parameters:
                            line = lines.readline().strip("\n").strip("\r")
                            if line == str(None):
                                algParams[param.name] = None
                            else:
                                tokens = line.split("|")
                                algParams[param.name] = AlgorithmAndParameter(
                                    int(tokens[0]), tokens[1])
                        for out in alg.outputs:
                            line = lines.readline().strip("\n").strip("\r")
                            if str(None) != line:
                                algOutputs[out.name] = line
                                #we add the output to the algorithm, with a name indicating where it comes from
                                #that guarantees that the name is unique
                                output = copy.deepcopy(out)
                                output.description = line
                                output.name = self.getSafeNameForOutput(
                                    iAlg, output)
                                self.addOutput(output)
                            else:
                                algOutputs[out.name] = None
                        self.algOutputs.append(algOutputs)
                        self.algParameters.append(algParams)
                        self.dependencies.append(dependencies)
                        iAlg += 1
                    else:
                        raise WrongModelException("Error in algorithm name: " +
                                                  algLine)
                line = lines.readline().strip("\n").strip("\r")
        except Exception, e:
            if isinstance(e, WrongModelException):
                raise e
            else:
                raise WrongModelException("Error in model definition line:" +
                                          line.strip() + " : " +
                                          traceback.format_exc())
コード例 #6
0
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     self.loadFromFolder(folder)
     folder = os.path.join(os.path.dirname(__file__), "models")
     self.loadFromFolder(folder)
コード例 #7
0
 def modelsFolder(self):
     return ModelerUtils.modelsFolder()
コード例 #8
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     SextanteConfig.addSetting(
         Setting(self.getDescription(), ModelerUtils.MODELS_FOLDER,
                 "Models folder", ModelerUtils.modelsFolder()))
コード例 #9
0
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     self.loadFromFolder(folder)
     folder = os.path.join(os.path.dirname(__file__), "models")
     self.loadFromFolder(folder)
コード例 #10
0
 def modelsFolder(self):
     return ModelerUtils.modelsFolder()
コード例 #11
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     SextanteConfig.addSetting(Setting(self.getDescription(), ModelerUtils.MODELS_FOLDER, "Models folder", ModelerUtils.modelsFolder()))