Skip to content

Commit

Permalink
[processing] handle non-ASCII characters when running GRASS algorithms
Browse files Browse the repository at this point in the history
(addresses #5420)
  • Loading branch information
alexbruy committed Mar 26, 2014
1 parent 3bedc70 commit 3d6f17b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions python/plugins/processing/grass/GrassUtils.py
Expand Up @@ -27,6 +27,7 @@

import stat
import shutil
import codecs
import traceback
import subprocess
from qgis.core import QgsApplication
Expand Down Expand Up @@ -123,7 +124,7 @@ def createGrassScript(commands):
gisrc = userFolder() + os.sep + 'processing.gisrc'

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

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

output = open(script, 'w')
output = codecs.open(script, 'w', encoding='utf-8')
output.write('set HOME=' + os.path.expanduser('~') + '\n')
output.write('set GISRC=' + gisrc + '\n')
output.write('set GRASS_SH=' + shell + '\\bin\\sh.exe\n')
Expand Down Expand Up @@ -171,7 +172,7 @@ def createGrassScript(commands):

@staticmethod
def createGrassBatchJobFileFromGrassCommands(commands):
fout = open(GrassUtils.grassBatchJobFilename(), 'w')
fout = codecs.open(GrassUtils.grassBatchJobFilename(), 'w', encoding='utf-8')
for command in commands:
fout.write(command + '\n')
fout.write('exit')
Expand Down Expand Up @@ -204,20 +205,20 @@ def createTempMapset():
mkdir(os.path.join(folder, 'PERMANENT', '.tmp'))
GrassUtils.writeGrassWindow(os.path.join(folder, 'PERMANENT',
'DEFAULT_WIND'))
outfile = open(os.path.join(folder, 'PERMANENT', 'MYNAME'), 'w')
outfile = codecs.open(os.path.join(folder, 'PERMANENT', 'MYNAME'), 'w', encoding='utf-8')
outfile.write(
'QGIS GRASS interface: temporary data processing location.\n')
outfile.close()
GrassUtils.writeGrassWindow(os.path.join(folder, 'PERMANENT', 'WIND'))
mkdir(os.path.join(folder, 'PERMANENT', 'dbf'))
outfile = open(os.path.join(folder, 'PERMANENT', 'VAR'), 'w')
outfile = codecs.open(os.path.join(folder, 'PERMANENT', 'VAR'), 'w', encoding='utf-8')
outfile.write('DB_DRIVER: dbf\n')
outfile.write('DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n')
outfile.close()

@staticmethod
def writeGrassWindow(filename):
out = open(filename, 'w')
out = codecs.open(filename, 'w', encoding='utf-8')
out.write('proj: 0\n')
out.write('zone: 0\n')
out.write('north: 1\n')
Expand Down

0 comments on commit 3d6f17b

Please sign in to comment.