26 changes: 8 additions & 18 deletions python/plugins/GdalTools/tools/GdalTools_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,15 @@ def getVectorFields(vectorFile):
def getRasterSRS( parent, fileName ):
processSRS = QProcess( parent )
processSRS.start( "gdalinfo", [fileName], QIODevice.ReadOnly )
arr = QByteArray()
arr = ''
if processSRS.waitForFinished():
arr = processSRS.readAllStandardOutput()
arr = str(processSRS.readAllStandardOutput())
processSRS.close()

arr = str(arr)
if arr == '':
return ''

info = string.split( arr, sep="\n" )
info = arr.splitlines()
if len(info) == 0:
return ''

Expand All @@ -312,18 +311,17 @@ def getRasterSRS( parent, fileName ):
def getRasterExtent(parent, fileName):
processSRS = QProcess( parent )
processSRS.start( "gdalinfo", [fileName], QIODevice.ReadOnly )
arr = QByteArray()
arr = ''
if processSRS.waitForFinished():
arr = processSRS.readAllStandardOutput()
arr = str(processSRS.readAllStandardOutput())
processSRS.close()
arr = str(arr)

if arr == '':
return

ulCoord = lrCoord = ''
xUL = yLR = xLR = yUL = 0
info = string.split( arr, sep="\n" )
info = arr.splitlines()
for elem in info:
m = re.match("^Upper\sLeft.*", elem)
if m:
Expand Down Expand Up @@ -824,23 +822,15 @@ def setProcessEnvironment(process):
envval = os.getenv(name)
if envval == None or envval == "":
envval = str(val)
elif not QString( envval ).split( sep ).contains( val, Qt.CaseInsensitive ):
elif (platform.system() == "Windows" and val.lower() not in envval.lower().split( sep )) or
(platform.system() != "Windows" and val not in envval.split( sep )):
envval += "%s%s" % (sep, str(val))
else:
envval = None

if envval != None:
os.putenv( name, envval )

if False: # not needed because os.putenv() has already updated the environment for new child processes
env = QProcess.systemEnvironment()
if env.contains( QRegExp( "^%s=(.*)" % name, Qt.CaseInsensitive ) ):
env.replaceInStrings( QRegExp( "^%s=(.*)" % name, Qt.CaseInsensitive ), "%s=\\1%s%s" % (name, sep, gdalPath) )
else:
env.append( "%s=%s" % (name, val))
process.setEnvironment( env )


def setMacOSXDefaultEnvironment():
# fix bug #3170: many GDAL Tools don't work in OS X standalone

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/GdalTools/tools/dialogBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def onFinished(self, exitCode, status):
# show the error message if there's one, otherwise show the process output message
msg = str(self.process.readAllStandardError())
if msg == '':
outMessages = string.split( str(self.process.readAllStandardOutput()), sep="\n" )
outMessages = str(self.process.readAllStandardOutput()).splitlines()

# make sure to not show the help
for m in outMessages:
Expand All @@ -222,7 +222,7 @@ def onFinished(self, exitCode, status):
#if m.contains( QRegExp( "0(?:\\.+[1-9]0{1,2})+" ) ):
# continue

if not msg == '':
if msg:
msg += "\n"
msg += m

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/GdalTools/tools/doContour.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def getInputFileName(self):

def getOutputFileName(self):
if self.useDirAsOutput:
fn = self.outSelector.filename()
return fn if not fn else fn + QDir.separator() + "contour.shp"
if self.outSelector.filename():
return self.outSelector.filename() + QDir.separator() + "contour.shp"
return self.outSelector.filename()

def addLayerIntoCanvas(self, fileInfo):
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/GdalTools/tools/doFillNodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def updateProgress(self, index, total):
self.progressBar.setValue( 0 )

def batchRun(self):
exts = self.formatCombo.currentText().remove( QRegExp('^.*\(') ).remove( QRegExp('\).*$') ).split( " " )
exts = re.sub('\).*$', '', re.sub('^.*\(', '', self.formatCombo.currentText())).split(" ")
if exts and exts != "*" and exts != "*.*":
outExt = exts[ 0 ].remove( "*" )
else:
Expand All @@ -229,7 +229,7 @@ def batchRun(self):
for f in files:
self.inFiles.append( inDir + "/" + f )
if outDir != None:
outFile = re.sub( f, "\.[a-zA-Z0-9]{2,4}", outExt )
outFile = re.sub( "\.[a-zA-Z0-9]{2,4}", outExt, f )
self.outFiles.append( outDir + "/" + outFile )

self.errors = []
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/GdalTools/tools/doInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def finished( self ):
if platform.system() == "Windows":
#info = QString.fromLocal8Bit( arr ).strip().split( "\r\n" )
# TODO test
info = string.split(arr, sep="\r\n" )
info = arr.splitlines()
else:
info = string.split(arr, sep="\n" )
info = arr.splitlines()
self.rasterInfoList.addItems( info )

def fillInputFileEdit( self ):
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/GdalTools/tools/doTranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def getArguments(self):
if self.sdsCheck.isChecked():
arguments.append( "-sds")
if self.srcwinCheck.isChecked() and self.srcwinEdit.text():
coordList = self.srcwinEdit.text().split( ' ', QString.SkipEmptyParts )
coordList = self.srcwinEdit.text().split() # split the string on whitespace(s)
if len(coordList) == 4 and coordList[3]:
try:
for x in coordList:
Expand All @@ -219,7 +219,7 @@ def getArguments(self):
for x in coordList:
arguments.append( x)
if self.prjwinCheck.isChecked() and self.prjwinEdit.text():
coordList = self.prjwinEdit.text().split( ' ', QString.SkipEmptyParts )
coordList = self.prjwinEdit.text().split() # split the string on whitespace(s)
if len(coordList) == 4 and coordList[3]:
try:
for x in coordList:
Expand Down Expand Up @@ -276,7 +276,7 @@ def updateProgress(self, index, total):
self.progressBar.setValue( 0 )

def batchRun(self):
exts = self.formatCombo.currentText().remove( QRegExp('^.*\(') ).remove( QRegExp('\).*$') ).split( " " )
exts = re.sub('\).*$', '', re.sub('^.*\(', '', self.formatCombo.currentText())).split(" ")
if exts and exts != "*" and exts != "*.*":
outExt = exts[ 0 ].remove( "*" )
else:
Expand Down