Skip to content
Permalink
Browse files

Adapt more python code to new API

  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent 6517470 commit 0c3ad14c79f18aa3dd407b26dc075fded294c30c
Showing with 157 additions and 637 deletions.
  1. +1 −1 python/plugins/processing/algs/gdal/translate.py
  2. +14 −27 python/plugins/processing/algs/grass7/ext/i.py
  3. +10 −12 python/plugins/processing/algs/grass7/ext/r_colors.py
  4. +17 −17 python/plugins/processing/algs/grass7/ext/r_li.py
  5. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_cwed.py
  6. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_cwed_ascii.py
  7. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_dominance.py
  8. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_dominance_ascii.py
  9. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_edgedensity.py
  10. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_edgedensity_ascii.py
  11. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_mpa.py
  12. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_mpa_ascii.py
  13. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_mps.py
  14. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_mps_ascii.py
  15. +14 −14 python/plugins/processing/algs/grass7/ext/r_li_orig.py
  16. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_padcv.py
  17. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_padcv_ascii.py
  18. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_padrange.py
  19. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_padrange_ascii.py
  20. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_padsd.py
  21. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_padsd_ascii.py
  22. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_patchdensity.py
  23. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_patchnum.py
  24. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_patchnum_ascii.py
  25. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_pielou.py
  26. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_pielou_ascii.py
  27. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_renyi.py
  28. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_renyi_ascii.py
  29. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_richness.py
  30. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_richness_ascii.py
  31. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_shannon.py
  32. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_shannon_ascii.py
  33. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_shape.py
  34. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_shape_ascii.py
  35. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_simpson.py
  36. +1 −1 python/plugins/processing/algs/grass7/ext/r_li_simpson_ascii.py
  37. +9 −17 python/plugins/processing/algs/grass7/ext/v_net.py
  38. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_alloc.py
  39. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_allpairs.py
  40. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_connectivity.py
  41. +7 −19 python/plugins/processing/algs/grass7/ext/v_net_distance.py
  42. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_flow.py
  43. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_iso.py
  44. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_path.py
  45. +4 −4 python/plugins/processing/algs/grass7/ext/v_net_salesman.py
  46. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_steiner.py
  47. +27 −26 python/plugins/processing/algs/saga/SagaAlgorithm.py
  48. +3 −43 python/plugins/processing/core/GeoAlgorithm.py
  49. +0 −408 python/plugins/processing/core/parameters.py
  50. +2 −2 python/plugins/processing/modeler/ModelerAlgorithm.py
  51. +4 −2 python/plugins/processing/preconfigured/PreconfiguredAlgorithm.py
  52. +5 −5 python/plugins/processing/script/ScriptAlgorithm.py
  53. +2 −2 python/plugins/processing/tests/AlgorithmsTestBase.py
@@ -109,7 +109,7 @@ def getConsoleCommands(self, parameters):
outsize = str(self.getParameterValue(self.OUTSIZE))
outsizePerc = str(self.getParameterValue(self.OUTSIZE_PERC))
noData = self.getParameterValue(self.NO_DATA)
expand = self.getParameterFromName(self.EXPAND).options[self.getParameterValue(self.EXPAND)][1]
expand = parameters[self.EXPAND].options[self.getParameterValue(self.EXPAND)][1]
projwin = str(self.getParameterValue(self.PROJWIN))
if not projwin:
projwin = QgsProcessingUtils.combineLayerExtents([inLayer])
@@ -33,6 +33,7 @@
from processing.tools.system import isWindows
from ..Grass7Utils import Grass7Utils
from os import path
from copy import deepcopy


def multipleOutputDir(alg, field, basename=None):
@@ -112,58 +113,44 @@ def regroupRasters(alg, parameters, field, groupField, subgroupField=None, extFi
:param parameters:
"""
# List of rasters names

new_parameters = deepcopy(parameters)

rasters = alg.getParameterFromName(field)
rastersList = rasters.value.split(';')
alg.parameters.remove(rasters)
del new_parameters[field]

# Insert a i.group command
group = getParameterFromString("ParameterString|{}|group of rasters|None|False|False".format(groupField))
group.value = alg.getTempFilename()
alg.addParameter(group)
new_parameters[group.name()] = alg.getTempFilename()

if subgroupField:
subgroup = getParameterFromString("ParameterString|{}|subgroup of rasters|None|False|False".format(subgroupField))
subgroup.value = alg.getTempFilename()
alg.addParameter(subgroup)
new_parameters[subgroup.name()] = alg.getTempFilename()

command = 'i.group group={}{} input={}'.format(
group.value,
' subgroup={}'.format(subgroup.value) if subgroupField else '',
new_parameters[group.name()],
' subgroup={}'.format(new_parameters[subgroup.name()]) if subgroupField else '',
','.join([alg.exportedLayers[f] for f in rastersList])
)
alg.commands.append(command)

# Handle external files
origExtParams = {}
if subgroupField and extFile:
for ext in list(extFile.keys()):
extFileName = alg.getParameterValue(ext)
extFileName = new_parameters[ext]
if extFileName:
shortFileName = path.basename(extFileName)
destPath = path.join(Grass7Utils.grassMapsetFolder(),
'PERMANENT',
'group', group.value,
'subgroup', subgroup.value,
'group', new_parameters[group.name()],
'subgroup', new_parameters[subgroup.name()],
extFile[ext], shortFileName)
copyFile(alg, extFileName, destPath)
origExtParams[ext] = extFileName
alg.setParameterValue(ext, shortFileName)
new_parameters[ext] = shortFileName

# modify parameters values
alg.processCommand()

# Re-add input rasters
alg.addParameter(rasters)

# replace external files value with original value
for param in list(origExtParams.keys()):
alg.setParameterValue(param, origExtParams[param])

# Delete group:
alg.parameters.remove(group)
if subgroupField:
alg.parameters.remove(subgroup)
return group.value, subgroup.value
alg.processCommand(new_parameters)

return group.value

@@ -27,6 +27,7 @@
__revision__ = '$Format:%H$'

import os
from copy import deepcopy


def checkParameterValuesBeforeExecuting(alg):
@@ -74,32 +75,29 @@ def processInputs(alg):

def processCommand(alg, parameters):
# remove output before processCommand
new_parameters = deepcopy(parameters)

output = alg.getOutputFromName('output_dir')
alg.removeOutputFromName('output_dir')
color = alg.getParameterFromName('color')
if color.value == 0:
alg.parameters.remove(color)
if new_parameters[color.name()] == 0:
del new_parameters[color.name()]

# Handle rules
txtRules = alg.getParameterFromName('rules_txt')
if txtRules.value:
if new_parameters[txtRules.name()]:
# Creates a temporary txt file
tempRulesName = alg.getTempFilename()

# Inject rules into temporary txt file
with open(tempRulesName, "w") as tempRules:
tempRules.write(txtRules.value)
tempRules.write(new_parameters[txtRules.name()])

# Use temporary file as rules file
alg.setParameterValue('rules', tempRulesName)
alg.parameters.remove(txtRules)

alg.processCommand()
new_parameters['rules'] = tempRulesName
del new_parameters[textRules.name()]

# re-add the previous output
alg.addOutput(output)
alg.addParameter(color)
alg.addParameter(txtRules)
alg.processCommand(new_parameters)


def processOutputs(alg):
@@ -29,6 +29,7 @@
from processing.tools.system import isWindows, mkdir
from processing.core.parameters import getParameterFromString
import os
from copy import deepcopy

# for MS-Windows users who have MBCS chars in their name:
if os.name == 'nt':
@@ -83,29 +84,33 @@ def checkMovingWindow(alg, outputTxt=False):
return None


def configFile(alg, outputTxt=False):
""" Handle inline configuration """
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 = alg.getParameterValue('config')
origConfigFile = new_parameters['config']

# Handle inline configuration
configTxt = alg.getParameterFromName('config_txt')
if configTxt.value:
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(configTxt.value)
f.write(new_parameters['config_txt'])

# Use temporary file as rules file
alg.setParameterValue('config', os.path.basename(configFilePath))
alg.parameters.remove(configTxt)
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:
@@ -114,26 +119,21 @@ def configFile(alg, outputTxt=False):
shutil.copy(origConfigFile, configFilePath)

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

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

alg.processCommand()
alg.processCommand(new_parameters)

# 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)


@@ -34,4 +34,4 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg)
configFile(alg, parameters)
@@ -34,7 +34,7 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg, True)
configFile(alg, parameters, True)


def processOutputs(alg):
@@ -34,4 +34,4 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg)
configFile(alg, parameters)
@@ -34,7 +34,7 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg, True)
configFile(alg, parameters, True)


def processOutputs(alg):
@@ -34,4 +34,4 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg)
configFile(alg, parameters)
@@ -34,7 +34,7 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg, True)
configFile(alg, parameters, True)


def processOutputs(alg):
@@ -34,4 +34,4 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg)
configFile(alg, parameters)
@@ -34,7 +34,7 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg, True)
configFile(alg, parameters, True)


def processOutputs(alg):
@@ -34,4 +34,4 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg)
configFile(alg, parameters)
@@ -34,7 +34,7 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg, True)
configFile(alg, parameters, True)


def processOutputs(alg):
@@ -28,6 +28,7 @@
import shutil
from processing.tools.system import isWindows, userFolder, mkdir
from os import path
from copy import deepcopy


def rliPath():
@@ -73,26 +74,29 @@ def checkMovingWindow(alg):
return None


def configFile(alg, outputTxt=False):
""" Handle inline configuration """
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 = alg.getParameterValue('config')
origConfigFile = new_parameters['config']

# Handle inline configuration
configTxt = alg.getParameterFromName('config_txt')
if configTxt.value:
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(configTxt.value)
f.write(new_parameters['config_txt'])

# Use temporary file as rules file
alg.setParameterValue('config', configFilePath)
alg.parameters.remove(configTxt)
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:
@@ -101,21 +105,17 @@ def configFile(alg, outputTxt=False):
shutil.copy(origConfigFile, configFilePath)

# Change the parameter value
alg.setParameterValue('config', configFilePath)
new_parameters['config'] = configFilePath

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

alg.processCommand()
alg.processCommand(new_parameters)

# Remove Config file:
removeConfigFile(alg)

# re-add configTxt
alg.addParameter(configTxt)
alg.setParameterValue('config', origConfigFile)


def moveOutputTxtFile(alg):
# Find output file name:
@@ -34,4 +34,4 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg)
configFile(alg, parameters)
@@ -34,7 +34,7 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg, True)
configFile(alg, parameters, True)


def processOutputs(alg):
@@ -34,4 +34,4 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg)
configFile(alg, parameters)
@@ -34,7 +34,7 @@ def checkParameterValuesBeforeExecuting(alg):


def processCommand(alg, parameters):
configFile(alg, True)
configFile(alg, parameters, True)


def processOutputs(alg):

0 comments on commit 0c3ad14

Please sign in to comment.
You can’t perform that action at this time.