Skip to content
Browse files
Fix MS-Windows implementation for* algorithms
  • Loading branch information
Médéric RIBREUX committed Mar 3, 2016
1 parent 63eab87 commit 2275ce4166d609f08b9053cc0835a16c6422eef2
Showing with 22 additions and 17 deletions.
  1. +22 −17 python/plugins/processing/algs/grass7/ext/
@@ -28,24 +28,29 @@
import shutil
from import isWindows, isMac, userFolder, mkdir
from processing.core.parameters import getParameterFromString
from os import path
import os

# for MS-Windows users who have MBCS chars in their name:
if == 'nt':
import win32api

def rliPath():
"""Return GRASS7 user dir"""
if isWindows():
return path.join(path.expanduser("~").decode('mcbs'), 'GRASS7', '')
homeDir = win32api.GetShortPathName(os.path.expanduser('~'))
return os.path.join(homeDir, 'AppData', 'Roaming', 'GRASS7', '')
return path.join(path.expanduser("~"), '.grass7', '')
return os.path.join(os.path.expanduser("~"), '.grass7', '')

def removeConfigFile(alg):
""" Remove the user dir config file """
configPath = alg.getParameterValue('config')
if isWindows():
command = "DEL {}".format(path.join(rliPath(), configPath))
command = "DEL {}".format(os.path.join(rliPath(), configPath))
command = "rm {}".format(path.join(rliPath(), configPath))
command = "rm {}".format(os.path.join(rliPath(), configPath))

@@ -82,39 +87,39 @@ def configFile(alg, outputTxt=False):
""" Handle inline configuration """
# Where is the GRASS7 user directory ?
userGrass7Path = rliPath()
if not path.isdir(userGrass7Path):
if not os.path.isdir(userGrass7Path):
if not path.isdir(path.join(userGrass7Path, 'output')):
mkdir(path.join(userGrass7Path, 'output'))
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 directory
tempConfig = alg.getTempFilename()
configFilePath = path.join(userGrass7Path, tempConfig)
configFilePath = os.path.join(userGrass7Path, tempConfig)
# Inject rules into temporary txt file
with open(configFilePath, "w") as f:

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

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

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

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

@@ -137,12 +142,12 @@ def moveOutputTxtFile(alg):
origOutput = alg.getOutputValue('output')
userGrass7Path = rliPath()

outputDir = path.join(userGrass7Path, 'output')
output = path.join(outputDir, path.basename(origOutput))
outputDir = os.path.join(userGrass7Path, 'output')
output = os.path.join(outputDir, os.path.basename(origOutput))

# move the file
if isWindows():
command = "cp {} {}".format(output, origOutput)
command = "MOVE /Y {} {}".format(output, origOutput)
command = "mv {} {}".format(output, origOutput)
command = "mv -f {} {}".format(output, origOutput)

0 comments on commit 2275ce4

Please sign in to comment.