Skip to content

Commit

Permalink
[Processing] Uses os.path.join instead of + os.sep + (#3552)
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont authored and m-kuhn committed Oct 1, 2016
1 parent 52fc535 commit 37951ba
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 34 deletions.
21 changes: 9 additions & 12 deletions python/plugins/processing/algs/grass/GrassUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def grassBatchJobFilename():
GRASS_BATCH_JOB and then call GRASS and let it do the work
'''
filename = 'grass_batch_job.sh'
batchfile = userFolder() + os.sep + filename
batchfile = os.path.join(userFolder(), filename)
return batchfile

@staticmethod
Expand All @@ -74,7 +74,7 @@ def grassScriptFilename():
GRASS and then uses grass commands
'''
filename = 'grass_script.bat'
filename = userFolder() + os.sep + filename
filename = os.path.join(userFolder(), filename)
return filename

@staticmethod
Expand Down Expand Up @@ -132,7 +132,7 @@ def createGrassScript(commands):
shell = GrassUtils.grassWinShell()

script = GrassUtils.grassScriptFilename()
gisrc = userFolder() + os.sep + 'processing.gisrc'
gisrc = os.path.join(userFolder(), 'processing.gisrc')

encoding = locale.getpreferredencoding()
# Temporary gisrc file
Expand All @@ -150,12 +150,10 @@ def createGrassScript(commands):
output.write('set HOME=' + os.path.expanduser('~') + '\n')
output.write('set GISRC=' + gisrc + '\n')
output.write('set GRASS_SH=' + shell + '\\bin\\sh.exe\n')
output.write('set PATH=' + shell + os.sep + 'bin;' + shell + os.sep
+ 'lib;' + '%PATH%\n')
output.write('set PATH=' + os.path.join(shell, 'bin') + ';' + os.path.join(shell, 'lib') + ';' + '%PATH%\n')
output.write('set WINGISBASE=' + folder + '\n')
output.write('set GISBASE=' + folder + '\n')
output.write('set GRASS_PROJSHARE=' + folder + os.sep + 'share'
+ os.sep + 'proj' + '\n')
output.write('set GRASS_PROJSHARE=' + os.path.join(folder, 'share', 'proj') + '\n')
output.write('set GRASS_MESSAGE_FORMAT=gui\n')

# Replacement code for etc/Init.bat
Expand Down Expand Up @@ -257,7 +255,7 @@ def prepareGrassExecution(commands):
GrassUtils.createGrassScript(commands)
command = ['cmd.exe', '/C ', GrassUtils.grassScriptFilename()]
else:
gisrc = userFolder() + os.sep + 'processing.gisrc'
gisrc = os.path.join(userFolder(), 'processing.gisrc')
env['GISRC'] = gisrc
env['GRASS_MESSAGE_FORMAT'] = 'gui'
env['GRASS_BATCH_JOB'] = GrassUtils.grassBatchJobFilename()
Expand All @@ -267,11 +265,10 @@ def prepareGrassExecution(commands):
os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC
| stat.S_IREAD | stat.S_IWRITE)
if isMac():
command = GrassUtils.grassPath() + os.sep + 'grass.sh ' \
+ GrassUtils.grassMapsetFolder() + '/PERMANENT'
command = os.path.join(GrassUtils.grassPath(), 'grass.sh') + ' ' \
+ os.path.join(GrassUtils.grassMapsetFolder(), 'PERMANENT')
else:
command = 'grass64 ' + GrassUtils.grassMapsetFolder() \
+ '/PERMANENT'
command = 'grass64 ' + os.path.join(GrassUtils.grassMapsetFolder(), 'PERMANENT')

return command, env

Expand Down
18 changes: 8 additions & 10 deletions python/plugins/processing/algs/grass7/Grass7Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def grassBatchJobFilename():
GRASS_BATCH_JOB and then call GRASS and let it do the work
'''
filename = 'grass7_batch_job.sh'
batchfile = userFolder() + os.sep + filename
batchfile = os.path.join(userFolder(), filename)
return batchfile

@staticmethod
Expand All @@ -71,7 +71,7 @@ def grassScriptFilename():
GRASS and then uses grass commands
'''
filename = 'grass7_script.bat'
filename = userFolder() + os.sep + filename
filename = os.path.join(userFolder(), filename)
return filename

@staticmethod
Expand Down Expand Up @@ -133,8 +133,7 @@ def createGrass7Script(commands):
output.write('set GISRC=' + gisrc + '\n')
output.write('set WINGISBASE=' + folder + '\n')
output.write('set GISBASE=' + folder + '\n')
output.write('set GRASS_PROJSHARE=' + folder + os.sep + 'share'
+ os.sep + 'proj' + '\n')
output.write('set GRASS_PROJSHARE=' + os.path.join(folder, 'share', 'proj') + '\n')
output.write('set GRASS_MESSAGE_FORMAT=plain\n')

# Replacement code for etc/Init.bat
Expand Down Expand Up @@ -236,7 +235,7 @@ def prepareGrass7Execution(commands):
Grass7Utils.createGrass7Script(commands)
command = ['cmd.exe', '/C ', Grass7Utils.grassScriptFilename()]
else:
gisrc = userFolder() + os.sep + 'processing.gisrc7'
gisrc = os.path.join(userFolder(), 'processing.gisrc7')
env['GISRC'] = gisrc
env['GRASS_MESSAGE_FORMAT'] = 'plain'
env['GRASS_BATCH_JOB'] = Grass7Utils.grassBatchJobFilename()
Expand All @@ -245,12 +244,11 @@ def prepareGrass7Execution(commands):
Grass7Utils.createGrass7BatchJobFileFromGrass7Commands(commands)
os.chmod(Grass7Utils.grassBatchJobFilename(), stat.S_IEXEC
| stat.S_IREAD | stat.S_IWRITE)
if isMac() and os.path.exists(Grass7Utils.grassPath() + os.sep + '*grass.sh*'):
command = Grass7Utils.grassPath() + os.sep + '*grass.sh* ' \
+ Grass7Utils.grassMapsetFolder() + '/PERMANENT'
if isMac() and os.path.exists(os.path.join(Grass7Utils.grassPath(), '*grass.sh*')):
command = os.path.join(Grass7Utils.grassPath(), '*grass.sh*') + ' ' \
+ os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')
else:
command = 'grass70 ' + Grass7Utils.grassMapsetFolder() \
+ '/PERMANENT'
command = 'grass70 ' + os.path.join(Grass7Utils.grassMapsetFolder(), 'PERMANENT')

return command, env

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/lidar/fusion/FusionUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def FusionPath():
@staticmethod
def tempFileListFilepath():
filename = 'fusion_files_list.txt'
filepath = userFolder() + os.sep + filename
filepath = os.path.join(userFolder(), filename)
return filepath

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/otb/OTBAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def processAlgorithm(self, progress):
path = OTBUtils.otbPath()

commands = []
commands.append(path + os.sep + self.cliName)
commands.append(os.path.join(path, self.cliName))

self.roiVectors = {}
self.roiRasters = {}
Expand Down
8 changes: 3 additions & 5 deletions python/plugins/processing/algs/r/RUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RUtils(object):
R_USE64 = 'R_USE64'
R_LIBS_USER = 'R_LIBS_USER'

rscriptfilename = userFolder() + os.sep + 'processing_script.r'
rscriptfilename = os.path.join(userFolder(), 'processing_script.r')

@staticmethod
def RFolder():
Expand Down Expand Up @@ -129,8 +129,7 @@ def executeRAlgorithm(alg, progress):
else:
execDir = 'i386'
command = [
RUtils.RFolder() + os.sep + 'bin' + os.sep + execDir + os.sep
+ 'R.exe',
os.path.join(RUtils.RFolder(), 'bin', execDir, 'R.exe'),
'CMD',
'BATCH',
'--vanilla',
Expand Down Expand Up @@ -208,8 +207,7 @@ def checkRIsInstalled(ignoreRegistrySettings=False):
execDir = 'x64'
else:
execDir = 'i386'
command = [RUtils.RFolder() + os.sep + 'bin' + os.sep + execDir
+ os.sep + 'R.exe', '--version']
command = [os.path.join(RUtils.RFolder(), 'bin', execDir, 'R.exe'), '--version']
else:
command = ['R --version']
proc = subprocess.Popen(
Expand Down
8 changes: 3 additions & 5 deletions python/plugins/processing/algs/saga/SagaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sagaBatchJobFilename():
else:
filename = 'saga_batch_job.sh'

batchfile = userFolder() + os.sep + filename
batchfile = os.path.join(userFolder(), filename)

return batchfile

Expand Down Expand Up @@ -88,12 +88,10 @@ def createSagaBatchJobFileFromSagaCommands(commands):
fout = open(sagaBatchJobFilename(), 'w')
if isWindows():
fout.write('set SAGA=' + sagaPath() + '\n')
fout.write('set SAGA_MLB=' + sagaPath() + os.sep
+ 'modules' + '\n')
fout.write('set SAGA_MLB=' + os.path.join(sagaPath(), 'modules') + '\n')
fout.write('PATH=%PATH%;%SAGA%;%SAGA_MLB%\n')
elif isMac():
fout.write('export SAGA_MLB=' + sagaPath()
+ '/../lib/saga\n')
fout.write('export SAGA_MLB=' + os.path.join(sagaPath(), '../lib/saga') + '\n')
fout.write('export PATH=' + sagaPath() + ':$PATH\n')
else:
pass
Expand Down

0 comments on commit 37951ba

Please sign in to comment.