28
28
import shutil
29
29
from processing .tools .system import isWindows , isMac , userFolder , mkdir
30
30
from processing .core .parameters import getParameterFromString
31
- from os import path
31
+ import os
32
+
33
+ # for MS-Windows users who have MBCS chars in their name:
34
+ if os .name == 'nt' :
35
+ import win32api
32
36
33
37
34
38
def rliPath ():
35
39
"""Return r.li GRASS7 user dir"""
36
40
if isWindows ():
37
- return path .join (path .expanduser ("~" ).decode ('mcbs' ), 'GRASS7' , 'r.li' )
41
+ homeDir = win32api .GetShortPathName (os .path .expanduser ('~' ))
42
+ return os .path .join (homeDir , 'AppData' , 'Roaming' , 'GRASS7' , 'r.li' )
38
43
else :
39
- return path .join (path .expanduser ("~" ), '.grass7' , 'r.li' )
44
+ return os . path .join (os . path .expanduser ("~" ), '.grass7' , 'r.li' )
40
45
41
46
42
47
def removeConfigFile (alg ):
43
48
""" Remove the r.li user dir config file """
44
49
configPath = alg .getParameterValue ('config' )
45
50
if isWindows ():
46
- command = "DEL {}" .format (path .join (rliPath (), configPath ))
51
+ command = "DEL {}" .format (os . path .join (rliPath (), configPath ))
47
52
else :
48
- command = "rm {}" .format (path .join (rliPath (), configPath ))
53
+ command = "rm {}" .format (os . path .join (rliPath (), configPath ))
49
54
alg .commands .append (command )
50
55
51
56
@@ -82,39 +87,39 @@ def configFile(alg, outputTxt=False):
82
87
""" Handle inline configuration """
83
88
# Where is the GRASS7 user directory ?
84
89
userGrass7Path = rliPath ()
85
- if not path .isdir (userGrass7Path ):
90
+ if not os . path .isdir (userGrass7Path ):
86
91
mkdir (userGrass7Path )
87
- if not path .isdir (path .join (userGrass7Path , 'output' )):
88
- mkdir (path .join (userGrass7Path , 'output' ))
92
+ if not os . path .isdir (os . path .join (userGrass7Path , 'output' )):
93
+ mkdir (os . path .join (userGrass7Path , 'output' ))
89
94
origConfigFile = alg .getParameterValue ('config' )
90
95
91
96
# Handle inline configuration
92
97
configTxt = alg .getParameterFromName ('config_txt' )
93
98
if configTxt .value :
94
99
# Creates a temporary txt file in user r.li directory
95
100
tempConfig = alg .getTempFilename ()
96
- configFilePath = path .join (userGrass7Path , tempConfig )
101
+ configFilePath = os . path .join (userGrass7Path , tempConfig )
97
102
# Inject rules into temporary txt file
98
103
with open (configFilePath , "w" ) as f :
99
104
f .write (configTxt .value )
100
105
101
106
# Use temporary file as rules file
102
- alg .setParameterValue ('config' , path .basename (configFilePath ))
107
+ alg .setParameterValue ('config' , os . path .basename (configFilePath ))
103
108
alg .parameters .remove (configTxt )
104
109
105
110
# If we have a configuration file, we need to copy it into user dir
106
111
if origConfigFile :
107
- configFilePath = path .join (userGrass7Path , path .basename (origConfigFile ))
112
+ configFilePath = os . path .join (userGrass7Path , os . path .basename (origConfigFile ))
108
113
# Copy the file
109
114
shutil .copy (origConfigFile , configFilePath )
110
115
111
116
# Change the parameter value
112
- alg .setParameterValue ('config' , path .basename (configFilePath ))
117
+ alg .setParameterValue ('config' , os . path .basename (configFilePath ))
113
118
114
119
origOutput = alg .getOutputFromName ('output' )
115
120
if outputTxt :
116
121
param = getParameterFromString ("ParameterString|output|txt output|None|False|True" )
117
- param .value = path .basename (origOutput .value )
122
+ param .value = os . path .basename (origOutput .value )
118
123
alg .addParameter (param )
119
124
alg .removeOutputFromName ('output' )
120
125
@@ -137,12 +142,12 @@ def moveOutputTxtFile(alg):
137
142
origOutput = alg .getOutputValue ('output' )
138
143
userGrass7Path = rliPath ()
139
144
140
- outputDir = path .join (userGrass7Path , 'output' )
141
- output = path .join (outputDir , path .basename (origOutput ))
145
+ outputDir = os . path .join (userGrass7Path , 'output' )
146
+ output = os . path .join (outputDir , os . path .basename (origOutput ))
142
147
143
148
# move the file
144
149
if isWindows ():
145
- command = "cp {} {}" .format (output , origOutput )
150
+ command = "MOVE /Y {} {}" .format (output , origOutput )
146
151
else :
147
- command = "mv {} {}" .format (output , origOutput )
152
+ command = "mv -f {} {}" .format (output , origOutput )
148
153
alg .commands .append (command )
0 commit comments