Skip to content
Permalink
Browse files

[processing] partially fixed handling of non-ascii chars when running…

… grass algorithms in windows
  • Loading branch information
volaya committed Oct 1, 2015
1 parent 5d4a8d9 commit d4cb3465b2af78500cb280a28ac6546184ba34d4
Showing with 26 additions and 25 deletions.
  1. +26 −25 python/plugins/processing/algs/grass/GrassUtils.py
@@ -30,6 +30,7 @@
import codecs
import subprocess
import os
import locale
from qgis.core import QgsApplication
from PyQt4.QtCore import QCoreApplication
from processing.core.ProcessingConfig import ProcessingConfig
@@ -122,8 +123,9 @@ def createGrassScript(commands):
script = GrassUtils.grassScriptFilename()
gisrc = userFolder() + os.sep + 'processing.gisrc'

encoding = locale.getpreferredencoding()
# Temporary gisrc file
output = codecs.open(gisrc, 'w', encoding='utf-8')
output = codecs.open(gisrc, 'w', encoding=encoding)
location = 'temp_location'
gisdbase = GrassUtils.grassDataFolder()

@@ -133,7 +135,7 @@ def createGrassScript(commands):
output.write('GRASS_GUI: text\n')
output.close()

output = codecs.open(script, 'w', encoding='utf-8')
output = codecs.open(script, 'w', encoding=encoding)
output.write('set HOME=' + os.path.expanduser('~') + '\n')
output.write('set GISRC=' + gisrc + '\n')
output.write('set GRASS_SH=' + shell + '\\bin\\sh.exe\n')
@@ -163,7 +165,7 @@ def createGrassScript(commands):
output.write('g.gisenv.exe set="GISDBASE=' + gisdbase + '"\n')
output.write('g.gisenv.exe set="GRASS_GUI=text"\n')
for command in commands:
output.write(command.encode('utf8') + '\n')
output.write(command + u'\n')
output.write('\n')
output.write('exit\n')
output.close()
@@ -172,7 +174,7 @@ def createGrassScript(commands):
def createGrassBatchJobFileFromGrassCommands(commands):
fout = codecs.open(GrassUtils.grassBatchJobFilename(), 'w', encoding='utf-8')
for command in commands:
fout.write(command.encode('utf8') + '\n')
fout.write(command + u'\n')
fout.write('exit')
fout.close()

@@ -216,27 +218,26 @@ def createTempMapset():

@staticmethod
def writeGrassWindow(filename):
out = codecs.open(filename, 'w', encoding='utf-8')
out.write('proj: 0\n')
out.write('zone: 0\n')
out.write('north: 1\n')
out.write('south: 0\n')
out.write('east: 1\n')
out.write('west: 0\n')
out.write('cols: 1\n')
out.write('rows: 1\n')
out.write('e-w resol: 1\n')
out.write('n-s resol: 1\n')
out.write('top: 1\n')
out.write('bottom: 0\n')
out.write('cols3: 1\n')
out.write('rows3: 1\n')
out.write('depths: 1\n')
out.write('e-w resol3: 1\n')
out.write('n-s resol3: 1\n')
out.write('t-b resol: 1\n')

out.close()
with open(filename, 'w') as out:
out.write('proj: 0\n')
out.write('zone: 0\n')
out.write('north: 1\n')
out.write('south: 0\n')
out.write('east: 1\n')
out.write('west: 0\n')
out.write('cols: 1\n')
out.write('rows: 1\n')
out.write('e-w resol: 1\n')
out.write('n-s resol: 1\n')
out.write('top: 1\n')
out.write('bottom: 0\n')
out.write('cols3: 1\n')
out.write('rows3: 1\n')
out.write('depths: 1\n')
out.write('e-w resol3: 1\n')
out.write('n-s resol3: 1\n')
out.write('t-b resol: 1\n')


@staticmethod
def prepareGrassExecution(commands):

0 comments on commit d4cb346

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