Пример #1
0
    def RScriptsFolder():
        folder = ProcessingConfig.getSetting(RUtils.RSCRIPTS_FOLDER)
        if folder is None:
            folder = unicode(os.path.join(userFolder(), 'rscripts'))
        mkdir(folder)

        return os.path.abspath(folder)
Пример #2
0
 def RLibs():
     folder = ProcessingConfig.getSetting(RUtils.R_LIBS_USER)
     if folder is None:
         folder = unicode(os.path.join(userFolder(), 'rlibs'))
     mkdir(folder)
     
     return os.path.abspath(unicode(folder))
 def workflowPath():
     folder = ProcessingConfig.getSetting(WorkflowUtils.WORKFLOW_FOLDER)
     if folder == None:
         folder = os.path.join(os.path.dirname(__file__), "workflows")
     mkdir(folder)
     
     return folder
Пример #4
0
    def modelsFolder():
        folder = ProcessingConfig.getSetting(ModelerUtils.MODELS_FOLDER)
        if folder is None:
            folder = unicode(os.path.join(userFolder(), 'models'))
        mkdir(folder)

        return os.path.abspath(folder)
Пример #5
0
    def processAlgorithm(self, progress):
        layer = dataobjects.getObjectFromUri(
            self.getParameterValue(self.INPUT))
        fieldName = self.getParameterValue(self.FIELD)
        directory = self.getOutputValue(self.OUTPUT)

        mkdir(directory)

        fieldIndex = layer.fieldNameIndex(fieldName)
        uniqueValues = vector.uniqueValues(layer, fieldIndex)
        baseName = os.path.join(directory, '{0}_{1}'.format(layer.name(), fieldName))

        fields = layer.pendingFields()
        crs = layer.crs()
        geomType = layer.wkbType()

        total = 100.0 / len(uniqueValues)

        for current, i in enumerate(uniqueValues):
            fName = u'{0}_{1}.shp'.format(baseName, unicode(i).strip())

            writer = vector.VectorWriter(fName, None, fields, geomType, crs)
            for f in vector.features(layer):
                if f[fieldName] == i:
                    writer.addFeature(f)
            del writer

            progress.setPercentage(int(current * total))
Пример #6
0
 def grassMapsetFolder():
     """
     Creates and returns the GRASS temporary DB LOCATION directory.
     """
     folder = os.path.join(Grass7Utils.grassDataFolder(), 'temp_location')
     mkdir(folder)
     return folder
Пример #7
0
    def scriptsFolder():
        folder = ProcessingConfig.getSetting(ScriptUtils.SCRIPTS_FOLDER)
        if folder == None:
            folder = unicode(os.path.join(userFolder(), "scripts"))
        mkdir(folder)

        return os.path.abspath(folder)
Пример #8
0
 def grassDataFolder():
     """
     Creates and returns the GRASS temporary DB directory.
     """
     tempfolder = os.path.normpath(
         os.path.join(QgsProcessingUtils.tempFolder(), 'grassdata'))
     mkdir(tempfolder)
     return tempfolder
Пример #9
0
 def RLibs():
     folder = ProcessingConfig.getSetting(RUtils.R_LIBS_USER)
     if folder is None:
         folder = str(os.path.join(userFolder(), 'rlibs'))
     try:
         mkdir(folder)
     except:
         folder = str(os.path.join(userFolder(), 'rlibs'))
         mkdir(folder)
     return os.path.abspath(str(folder))
Пример #10
0
def createBaseHelpFile(alg, folder):
    folder = os.path.join(folder, alg.provider.getName().lower())
    mkdir(folder)
    cmdLineName = alg.commandLineName()[
            alg.commandLineName().find(':') + 1:].lower()
    validChars = \
            'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    safeFilename = ''.join(c for c in cmdLineName if c in validChars)
    filepath = os.path.join(folder, safeFilename + '.rst')
    file = open(filepath, 'w')
    file.write(alg.name.upper())
    file.write('\n')
    file.write('=' * len(alg.name))
    file.write('\n\n')
    file.write('Description\n')
    file.write('-----------\n\n')
    file.write('Parameters\n')
    file.write('----------\n\n')
    for param in alg.parameters:
        file.write('- ``' + param.description + '[' +
                   param.parameterName()[9:] + ']``:\n')
    file.write('\nOutputs\n')
    file.write('-------\n\n')
    for out in alg.outputs:
        file.write('- ``' + out.description + '[' +
                   out.outputTypeName()[6:] + ']``:\n')
    file.write('\nSee also\n')
    file.write('---------\n\n')
    file.write('\nConsole usage\n')
    file.write('-------------\n\n')
    file.write('\n::\n\n')
    s = "\tprocessing.runalg('" + alg.commandLineName() + "', "
    for param in alg.parameters:
        s += str(param.name.lower().strip()) + ', '
    for out in alg.outputs:
        if not out.hidden:
            s += str(out.name.lower().strip()) + ', '
    s = s[:-2] + ')\n'
    file.write(s)

    s = ''
    hasSelection = False
    for param in alg.parameters:
        if isinstance(param, ParameterSelection):
            hasSelection = True
            s += '\n\t' + param.name.lower() + '(' + param.description + ')\n'
            i = 0
            for option in param.options:
                s += '\t\t' + str(i) + ' - ' + str(option) + '\n'
                i += 1
    if hasSelection:
        file.write('\n\tAvailable options for selection parameters:\n')
        file.write(s)
    file.close()
Пример #11
0
def configFile(alg, outputTxt=False):
    """ Handle inline configuration """
    # Where is the GRASS7 user directory ?
    userGrass7Path = rliPath()
    if not os.path.isdir(userGrass7Path):
        mkdir(userGrass7Path)
    if not os.path.isdir(os.path.join(userGrass7Path, 'output')):
        mkdir(os.path.join(userGrass7Path, 'output'))
    origConfigFile = alg.getParameterValue('config')

    # Handle inline configuration
    configTxt = alg.getParameterFromName('config_txt')
    if configTxt.value:
        # Creates a temporary txt file in user r.li directory
        tempConfig = alg.getTempFilename()
        configFilePath = os.path.join(userGrass7Path, tempConfig)
        # Inject rules into temporary txt file
        with open(configFilePath, "w") as f:
            f.write(configTxt.value)

        # Use temporary file as rules file
        alg.setParameterValue('config', os.path.basename(configFilePath))
        alg.parameters.remove(configTxt)

    # If we have a configuration file, we need to copy it into user dir
    if origConfigFile:
        configFilePath = os.path.join(userGrass7Path, os.path.basename(origConfigFile))
        # Copy the file
        shutil.copy(origConfigFile, configFilePath)

        # Change the parameter value
        alg.setParameterValue('config', os.path.basename(configFilePath))

    origOutput = alg.getOutputFromName('output')
    if outputTxt:
        param = getParameterFromString("ParameterString|output|txt output|None|False|True")
        param.value = os.path.basename(origOutput.value)
        alg.addParameter(param)
        alg.removeOutputFromName('output')

    alg.processCommand()

    # Remove Config file:
    removeConfigFile(alg)

    # re-add configTxt
    alg.addParameter(configTxt)
    alg.setParameterValue('config', origConfigFile)
    if outputTxt:
        for param in [f for f in alg.parameters if f.name == 'output']:
            alg.parameters.remove(param)
        alg.addOutput(origOutput)
Пример #12
0
def configFile(alg, parameters, outputTxt=False):
    """ Handle inline configuration
    :param parameters:
    """
    # Where is the GRASS7 user directory ?

    new_parameters = deepcopy(parameters)

    userGrass7Path = rliPath()
    if not os.path.isdir(userGrass7Path):
        mkdir(userGrass7Path)
    if not os.path.isdir(os.path.join(userGrass7Path, 'output')):
        mkdir(os.path.join(userGrass7Path, 'output'))
    origConfigFile = new_parameters['config']

    # Handle inline configuration
    if new_parameters['config_txt']:
        # Creates a temporary txt file in user r.li directory
        tempConfig = alg.getTempFilename()
        configFilePath = os.path.join(userGrass7Path, tempConfig)
        # Inject rules into temporary txt file
        with open(configFilePath, "w") as f:
            f.write(new_parameters['config_txt'])

        # Use temporary file as rules file
        new_parameters['config'] = os.path.basename(configFilePath)
        del new_parameters['config_txt']

    # If we have a configuration file, we need to copy it into user dir
    if origConfigFile:
        configFilePath = os.path.join(userGrass7Path, os.path.basename(origConfigFile))
        # Copy the file
        shutil.copy(origConfigFile, configFilePath)

        # Change the parameter value
        new_parameters['config'] = os.path.basename(configFilePath)

    origOutput = alg.getOutputFromName('output')
    if new_parameters['output']:
        param = getParameterFromString("ParameterString|output|txt output|None|False|True")
        new_parameters[param.name()] = origOutput.value
        alg.removeOutputFromName('output')

    alg.processCommand(new_parameters)

    # Remove Config file:
    removeConfigFile(alg)

    # re-add configTxt
    if outputTxt:
        alg.addOutput(origOutput)
Пример #13
0
def createBaseHelpFile(alg, folder):
    folder = os.path.join(folder, alg.provider.getName().lower())
    mkdir(folder)
    cmdLineName = alg.commandLineName()[alg.commandLineName().find(":") + 1 :].lower()
    validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    safeFilename = "".join(c for c in cmdLineName if c in validChars)
    filepath = os.path.join(folder, safeFilename + ".rst")
    file = open(filepath, "w")
    file.write(alg.name.upper())
    file.write("\n")
    file.write("=" * len(alg.name))
    file.write("\n\n")
    file.write("Description\n")
    file.write("-----------\n\n")
    file.write("Parameters\n")
    file.write("----------\n\n")
    for param in alg.parameters:
        file.write("- ``" + param.description + "[" + param.parameterName()[9:] + "]``:\n")
    file.write("\nOutputs\n")
    file.write("-------\n\n")
    for out in alg.outputs:
        file.write("- ``" + out.description + "[" + out.outputTypeName()[6:] + "]``:\n")
    file.write("\nSee also\n")
    file.write("---------\n\n")
    file.write("\nConsole usage\n")
    file.write("-------------\n\n")
    file.write("\n::\n\n")
    s = "\tprocessing.runalg('" + alg.commandLineName() + "', "
    for param in alg.parameters:
        s += str(param.name.lower().strip()) + ", "
    for out in alg.outputs:
        if not out.hidden:
            s += str(out.name.lower().strip()) + ", "
    s = s[:-2] + ")\n"
    file.write(s)

    s = ""
    hasSelection = False
    for param in alg.parameters:
        if isinstance(param, ParameterSelection):
            hasSelection = True
            s += "\n\t" + param.name.lower() + "(" + param.description + ")\n"
            i = 0
            for option in param.options:
                s += "\t\t" + str(i) + " - " + str(option) + "\n"
                i += 1
    if hasSelection:
        file.write("\n\tAvailable options for selection parameters:\n")
        file.write(s)
    file.close()
Пример #14
0
    def processAlgorithm(self, parameters, context, feedback):
        source = self.parameterAsSource(parameters, self.INPUT, context)
        if source is None:
            raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))

        fieldName = self.parameterAsString(parameters, self.FIELD, context)
        directory = self.parameterAsString(parameters, self.OUTPUT, context)

        mkdir(directory)

        fieldIndex = source.fields().lookupField(fieldName)
        uniqueValues = source.uniqueValues(fieldIndex)
        baseName = os.path.join(directory, '{0}'.format(fieldName))

        fields = source.fields()
        crs = source.sourceCrs()
        geomType = source.wkbType()

        total = 100.0 / len(uniqueValues) if uniqueValues else 1
        output_layers = []

        for current, i in enumerate(uniqueValues):
            if feedback.isCanceled():
                break
            fName = '{0}_{1}.gpkg'.format(baseName, str(i).strip())
            feedback.pushInfo(self.tr('Creating layer: {}').format(fName))

            sink, dest = QgsProcessingUtils.createFeatureSink(fName, context, fields, geomType, crs)

            filter = '{} = {}'.format(QgsExpression.quotedColumnRef(fieldName), QgsExpression.quotedValue(i))
            req = QgsFeatureRequest().setFilterExpression(filter)

            count = 0
            for f in source.getFeatures(req):
                if feedback.isCanceled():
                    break
                sink.addFeature(f, QgsFeatureSink.FastInsert)
                count += 1
            feedback.pushInfo(self.tr('Added {} features to layer').format(count))
            output_layers.append(fName)
            del sink

            feedback.setProgress(int(current * total))

        return {self.OUTPUT: directory, self.OUTPUT_LAYERS: output_layers}
Пример #15
0
def configFile(alg, parameters, context, feedback, outputTxt=False):
    """Handle inline configuration
    :param parameters:
    """
    # Where is the GRASS7 user directory ?
    userGrass7Path = rliPath()
    if not os.path.isdir(userGrass7Path):
        mkdir(userGrass7Path)
    if not os.path.isdir(os.path.join(userGrass7Path, 'output')):
        mkdir(os.path.join(userGrass7Path, 'output'))

    # If we have a configuration file, we need to copy it into user dir
    if parameters['config']:
        fileName = alg.parameterAsString(parameters, 'config', context)
        configFilePath = os.path.join(userGrass7Path, os.path.basename(fileName))
        # Copy the file
        shutil.copy(parameters['config'], configFilePath)
        # Change the parameter value
        parameters['config'] = os.path.basename(configFilePath)
    # Handle inline configuration
    elif parameters['config_txt']:
        # Creates a temporary txt file in user r.li directory
        tempConfig = os.path.basename(getTempFilename())
        configFilePath = os.path.join(userGrass7Path, tempConfig)
        # Inject rules into temporary txt file
        with open(configFilePath, "w") as f:
            f.write(alg.parameterAsString(parameters, 'config_txt', context))
            f.write("\n")

        # Use temporary file as rules file
        parameters['config'] = os.path.basename(configFilePath)
        alg.removeParameter('config_txt')

    # For ascii output, we need a virtual output
    if outputTxt:
        param = QgsProcessingParameterString(
            'output', 'virtual output',
            'a' + os.path.basename(getTempFilename()),
            False, False)
        alg.addParameter(param)

    alg.processCommand(parameters, context, feedback, outputTxt)

    # Remove Config file:
    removeConfigFile(alg, parameters, context)
Пример #16
0
def configFile(alg, outputTxt=False):
    """ Handle inline configuration """
    # Where is the GRASS7 user directory ?
    userGrass7Path = rliPath()
    mkdir(userGrass7Path)
    origConfigFile = alg.getParameterValue("config")

    # Handle inline configuration
    configTxt = alg.getParameterFromName("config_txt")
    if configTxt.value:
        # Creates a temporary txt file in user r.li directory
        tempConfig = alg.getTempFilename()
        configFilePath = path.join(userGrass7, tempConfig)
        # Inject rules into temporary txt file
        with open(configFilePath, "w") as f:
            f.write(configTxt.value)

        # Use temporary file as rules file
        alg.setParameterValue("config", configFilePath)
        alg.parameters.remove(configTxt)

    # If we have a configuration file, we need to copy it into user dir
    if origConfigFile:
        configFilePath = path.join(userGrass7Path, path.basename(origConfigFile))
        # Copy the file
        shutil.copy(origConfigFile, configFilePath)

        # Change the parameter value
        alg.setParameterValue("config", configFilePath)

    if outputTxt:
        origOutput = alg.getOutputValue("output")
        alg.setOutputValue("output", path.basename(origOutput))

    alg.processCommand()

    # Remove Config file:
    removeConfigFile(alg)

    # re-add configTxt
    alg.addParameter(configTxt)
    alg.setParameterValue("config", origConfigFile)
Пример #17
0
def configFile(alg, parameters, outputTxt=False):
    """ Handle inline configuration
    :param parameters:
    """
    new_parameters = deepcopy(parameters)

    # Where is the GRASS7 user directory ?
    userGrass7Path = rliPath()
    mkdir(userGrass7Path)
    origConfigFile = new_parameters['config']

    # Handle inline configuration
    if new_parameters['config_txt']:
        # Creates a temporary txt file in user r.li directory
        tempConfig = alg.getTempFilename()
        configFilePath = path.join(userGrass7Path, tempConfig)
        # Inject rules into temporary txt file
        with open(configFilePath, "w") as f:
            f.write(new_parameters['config_txt'])

        # Use temporary file as rules file
        new_parameters['config'] = configFilePath
        del new_parameters['config_txt']

    # If we have a configuration file, we need to copy it into user dir
    if origConfigFile:
        configFilePath = path.join(userGrass7Path, path.basename(origConfigFile))
        # Copy the file
        shutil.copy(origConfigFile, configFilePath)

        # Change the parameter value
        new_parameters['config'] = configFilePath

    if outputTxt:
        origOutput = alg.getOutputValue('output')
        alg.setOutputValue('output', path.basename(origOutput))

    alg.processCommand(new_parameters)

    # Remove Config file:
    removeConfigFile(alg)
 def execute(self):
     dlg = ScriptSelector()
     dlg.exec_()
     if dlg.scripts:
         mkdir(dlg.folder)
         initFile = os.path.join(dlg.folder, "__init__.py")
         with open(initFile, "w") as f:
             f.write(initTemplate)
         metadataFile = os.path.join(dlg.folder, "metadata.txt")
         with open(metadataFile, "w") as f:
             f.write(metadataTemplate.replace("$name$", dlg.name).replace("$description$", dlg.description)
                     .replace("$author$", dlg.author).replace("$email$", dlg.email))
         pluginFile = os.path.join(dlg.folder, "plugin.py")
         with open(pluginFile, "w") as f:
             f.write(pluginTemplate)
         scriptsFolder = os.path.join(dlg.folder, "scripts")
         mkdir(scriptsFolder)
         for script in dlg.scripts:
             scriptFile = os.path.join(scriptsFolder, os.path.basename(script.descriptionFile))
             with open(scriptFile, "w") as f:
                 f.write(script.script)
Пример #19
0
    def createTempMapset():
        '''Creates a temporary location and mapset(s) for GRASS data
        processing. A minimal set of folders and files is created in the
        system's default temporary directory. The settings files are
        written with sane defaults, so GRASS can do its work. The mapset
        projection will be set later, based on the projection of the first
        input image or vector
        '''

        folder = Grass7Utils.grassMapsetFolder()
        mkdir(os.path.join(folder, 'PERMANENT'))
        mkdir(os.path.join(folder, 'PERMANENT', '.tmp'))
        Grass7Utils.writeGrass7Window(
            os.path.join(folder, 'PERMANENT', 'DEFAULT_WIND'))
        outfile = open(os.path.join(folder, 'PERMANENT', 'MYNAME'), 'w')
        outfile.write(
            'QGIS GRASS GIS 7 interface: temporary data processing location.\n'
        )
        outfile.close()

        Grass7Utils.writeGrass7Window(
            os.path.join(folder, 'PERMANENT', 'WIND'))
        mkdir(os.path.join(folder, 'PERMANENT', 'sqlite'))
        outfile = open(os.path.join(folder, 'PERMANENT', 'VAR'), 'w')
        outfile.write('DB_DRIVER: sqlite\n')
        outfile.write(
            'DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db\n')
        outfile.close()
Пример #20
0
    def createTempMapset():
        """Creates a temporary location and mapset(s) for GRASS data
        processing. A minimal set of folders and files is created in the
        system's default temporary directory. The settings files are
        written with sane defaults, so GRASS can do its work. The mapset
        projection will be set later, based on the projection of the first
        input image or vector
        """

        folder = GrassUtils.grassMapsetFolder()
        mkdir(os.path.join(folder, "PERMANENT"))
        mkdir(os.path.join(folder, "PERMANENT", ".tmp"))
        GrassUtils.writeGrassWindow(os.path.join(folder, "PERMANENT", "DEFAULT_WIND"))
        with codecs.open(os.path.join(folder, "PERMANENT", "MYNAME"), "w", encoding="utf-8") as outfile:
            outfile.write("QGIS GRASS interface: temporary data processing location.\n")

        GrassUtils.writeGrassWindow(os.path.join(folder, "PERMANENT", "WIND"))
        mkdir(os.path.join(folder, "PERMANENT", "dbf"))
        with codecs.open(os.path.join(folder, "PERMANENT", "VAR"), "w", encoding="utf-8") as outfile:
            outfile.write("DB_DRIVER: dbf\n")
            outfile.write("DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n")
def preconfiguredAlgorithmsFolder():
    folder = str(os.path.join(userFolder(), 'preconfigured'))
    mkdir(folder)
    return folder
Пример #22
0
 def grassMapsetFolder():
     folder = os.path.join(GrassUtils.grassDataFolder(), 'temp_location')
     mkdir(folder)
     return folder
Пример #23
0
 def grassDataFolder():
     tempfolder = os.path.join(tempFolder(), 'grassdata')
     mkdir(tempfolder)
     return tempfolder
Пример #24
0
 def defaultRScriptsFolder():
     folder = unicode(os.path.join(userFolder(), 'rscripts'))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #25
0
 def grassDataFolder():
     tempfolder = os.path.join(QgsProcessingUtils.tempFolder(), 'grassdata')
     mkdir(tempfolder)
     return tempfolder
 def default_models_folder(self):
     """Return the default location of the processing models folder."""
     folder = Path(userFolder(), MODELS_PROCESSING_FOLDER)
     mkdir(str(folder))
     return str(folder)
Пример #27
0
def baseHelpForAlgorithm(alg, folder):
    baseDir = os.path.join(folder, alg.provider.getName().lower())
    mkdir(baseDir)

    groupName = alg.group.lower()
    groupName = groupName.replace('[', '').replace(']', '').replace(' - ', '_')
    groupName = groupName.replace(' ', '_')
    cmdLineName = alg.commandLineName()
    algName = cmdLineName[cmdLineName.find(':') + 1:].lower()
    validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
    safeGroupName = ''.join(c for c in groupName if c in validChars)
    safeAlgName = ''.join(c for c in algName if c in validChars)

    dirName = os.path.join(baseDir, safeGroupName)
    mkdir(dirName)
    filePath = os.path.join(dirName, safeAlgName + '.rst')

    with codecs.open(filePath, 'w', encoding='utf-8') as f:
        f.write('{}\n'.format(alg.name))
        f.write('{}\n\n'.format('=' * len(alg.name)))
        f.write('Description\n')
        f.write('-----------\n\n<put algorithm description here>\n\n')

        # Algorithm parameters
        f.write('Parameters\n')
        f.write('----------\n\n')
        for p in alg.parameters:
            if isinstance(p, (ParameterMultipleInput, ParameterTableField, ParameterVector)):
                f.write('``{}`` [{}: {}]\n'.format(p.description, p.typeName(), p.dataType()))
            else:
                f.write('``{}`` [{}]\n'.format(p.description, p.typeName()))

            if hasattr(p, 'optional'):
                if p.optional:
                    f.write('  Optional.\n\n')

            f.write('  <put parameter description here>\n\n')

            if isinstance(p, ParameterSelection):
                f.write('  Options:\n\n')
                for count, opt in enumerate(p.options):
                    f.write('  * {} --- {}\n'.format(count, opt))
                f.write('\n')

            if hasattr(p, 'default'):
                f.write('  Default: *{}*\n\n'.format(p.default if p.default != '' else '(not set)'))

        # Algorithm outputs
        f.write('Outputs\n')
        f.write('-------\n\n')
        for o in alg.outputs:
            f.write('``{}`` [{}]\n'.format(o.description, o.typeName()))
            f.write('  <put output description here>\n\n')

        # Console usage
        f.write('Console usage\n')
        f.write('-------------\n')
        f.write('\n::\n\n')
        cmd = "  processing.runalg('{}', ".format(alg.commandLineName())
        for p in alg.parameters:
            cmd += '{}, '.format(p.name.lower().strip())

        for o in alg.outputs:
            if not o.hidden:
                cmd += '{}, '.format(o.name.lower().strip())
        cmd = cmd[:-2] + ')\n\n'
        f.write(cmd)

        f.write('See also\n')
        f.write('--------\n\n')
Пример #28
0
 def grassDataFolder():
     tempfolder = os.path.join(QgsProcessingUtils.tempFolder(), 'grassdata')
     mkdir(tempfolder)
     return tempfolder
Пример #29
0
 def defaultScriptsFolder():
     folder = str(os.path.join(userFolder(), "scripts"))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #30
0
 def grassMapsetFolder():
     folder = os.path.join(Grass7Utils.grassDataFolder(), 'temp_location')
     mkdir(folder)
     return folder
Пример #31
0
 def commandsFolder(self):
     folder = str(os.path.join(userFolder(), 'commander'))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #32
0
 def grassDataFolder():
     tempfolder = os.path.join(tempFolder(), 'grassdata')
     mkdir(tempfolder)
     return tempfolder
Пример #33
0
 def defaultScriptsFolder():
     folder = str(os.path.join(userFolder(), 'scripts'))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #34
0
 def default_models_folder(self):
     """Return the default location of the processing models folder."""
     folder = str(os.path.join(userFolder(), 'models'))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #35
0
 def defaultModelsFolder():
     folder = str(os.path.join(userFolder(), 'models'))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #36
0
def baseHelpForAlgorithm(alg, folder):
    baseDir = os.path.join(folder, alg.provider.id().lower())
    mkdir(baseDir)

    groupName = alg.group.lower()
    groupName = groupName.replace('[', '').replace(']', '').replace(' - ', '_')
    groupName = groupName.replace(' ', '_')
    cmdLineName = alg.commandLineName()
    algName = cmdLineName[cmdLineName.find(':') + 1:].lower()
    validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
    safeGroupName = ''.join(c for c in groupName if c in validChars)
    safeAlgName = ''.join(c for c in algName if c in validChars)

    dirName = os.path.join(baseDir, safeGroupName)
    mkdir(dirName)
    filePath = os.path.join(dirName, safeAlgName + '.rst')

    with codecs.open(filePath, 'w', encoding='utf-8') as f:
        f.write('{}\n'.format(alg.name))
        f.write('{}\n\n'.format('=' * len(alg.name)))
        f.write('Description\n')
        f.write('-----------\n\n<put algorithm description here>\n\n')

        # Algorithm parameters
        f.write('Parameters\n')
        f.write('----------\n\n')
        for p in alg.parameters:
            if isinstance(p, (ParameterMultipleInput, ParameterTableField, ParameterVector)):
                f.write('``{}`` [{}: {}]\n'.format(p.description, p.typeName(), p.dataType()))
            else:
                f.write('``{}`` [{}]\n'.format(p.description, p.typeName()))

            if hasattr(p, 'optional'):
                if p.optional:
                    f.write('  Optional.\n\n')

            f.write('  <put parameter description here>\n\n')

            if isinstance(p, ParameterSelection):
                f.write('  Options:\n\n')
                for count, opt in enumerate(p.options):
                    f.write('  * {} --- {}\n'.format(count, opt))
                f.write('\n')

            if hasattr(p, 'default'):
                f.write('  Default: *{}*\n\n'.format(p.default if p.default != '' else '(not set)'))

        # Algorithm outputs
        f.write('Outputs\n')
        f.write('-------\n\n')
        for o in alg.outputs:
            f.write('``{}`` [{}]\n'.format(o.description, o.typeName()))
            f.write('  <put output description here>\n\n')

        # Console usage
        f.write('Console usage\n')
        f.write('-------------\n')
        f.write('\n::\n\n')
        cmd = "  processing.runalg('{}', ".format(alg.commandLineName())
        for p in alg.parameters:
            cmd += '{}, '.format(p.name.lower().strip())

        for o in alg.outputs:
            if not o.hidden:
                cmd += '{}, '.format(o.name.lower().strip())
        cmd = cmd[:-2] + ')\n\n'
        f.write(cmd)

        f.write('See also\n')
        f.write('--------\n\n')
Пример #37
0
 def commandsFolder(self):
     folder = unicode(os.path.join(userFolder(), "commander"))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #38
0
 def commandsFolder(self):
     folder = str(os.path.join(userFolder(), 'commander'))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #39
0
 def defaultRScriptsFolder():
     folder = unicode(os.path.join(userFolder(), 'rscripts'))
     mkdir(folder)
     return os.path.abspath(folder)
Пример #40
0
 def defaultModelsFolder():
     folder = str(os.path.join(userFolder(), 'models'))
     mkdir(folder)
     return os.path.abspath(folder)