Skip to content

Commit

Permalink
[processing] remove obsolete TauDEM multifile stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Aug 23, 2016
1 parent 3bfd998 commit 7866bda
Show file tree
Hide file tree
Showing 55 changed files with 54 additions and 1,395 deletions.
56 changes: 29 additions & 27 deletions python/plugins/processing/algs/taudem/TauDEMAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__revision__ = '$Format:%H$'

import os
from qgis.PyQt.QtCore import QCoreApplication

from qgis.PyQt.QtGui import QIcon

from processing.core.GeoAlgorithm import GeoAlgorithm
Expand All @@ -45,6 +45,9 @@

from .TauDEMUtils import TauDEMUtils

pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))


class TauDEMAlgorithm(GeoAlgorithm):

Expand All @@ -59,34 +62,33 @@ def getCopy(self):
return newone

def getIcon(self):
return QIcon(os.path.dirname(__file__) + '/../../images/taudem.svg')
return QIcon(os.path.join(pluginPath, 'images', 'taudem.svg'))

def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip('\n').strip()
self.name = line
self.i18n_name = QCoreApplication.translate("TAUDEMAlgorithm", line)
line = lines.readline().strip('\n').strip()
self.cmdName = line
line = lines.readline().strip('\n').strip()
self.group = line
self.i18n_group = QCoreApplication.translate("TAUDEMAlgorithm", line)

line = lines.readline().strip('\n').strip()
while line != '':
try:
line = line.strip('\n').strip()
if line.startswith('Parameter'):
param = getParameterFromString(line)
self.addParameter(param)
else:
self.addOutput(getOutputFromString(line))
line = lines.readline().strip('\n').strip()
except Exception as e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('Could not load TauDEM algorithm: %s\n%s' % (self.descriptionFile, line)))
raise e
lines.close()
with codecs.open(self.descriptionFile, 'utf-8') as f:
line = f.readline().strip('\n').strip()
self.name = line
self.i18n_name = self.tr(line)
line = f.readline().strip('\n').strip()
self.cmdName = line
line = f.readline().strip('\n').strip()
self.group = line
self.i18n_group = self.tr(line)

line = f.readline().strip('\n').strip()
while line != '':
try:
line = line.strip('\n').strip()
if line.startswith('Parameter'):
param = getParameterFromString(line)
self.addParameter(param)
else:
self.addOutput(getOutputFromString(line))
line = f.readline().strip('\n').strip()
except Exception as e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('Could not load TauDEM algorithm: {}\n{}'.format(self.descriptionFile, line)))
raise e

def processAlgorithm(self, progress):
commands = []
Expand Down
80 changes: 23 additions & 57 deletions python/plugins/processing/algs/taudem/TauDEMAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
from .dinftranslimaccum_multi import DinfTransLimAccumMulti
from .dinftranslimaccum2_multi import DinfTransLimAccum2Multi

pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))


class TauDEMAlgorithmProvider(AlgorithmProvider):

Expand All @@ -71,7 +74,7 @@ def getName(self):
return 'taudem'

def getIcon(self):
return QIcon(os.path.dirname(__file__) + '/../../images/taudem.svg')
return QIcon(os.path.join(pluginPath, 'images', 'taudem.svg'))

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
Expand All @@ -80,16 +83,6 @@ def initializeSettings(self):
TauDEMUtils.TAUDEM_FOLDER,
self.tr('TauDEM command line tools folder'),
TauDEMUtils.taudemPath(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.TAUDEM_MULTIFILE_FOLDER,
self.tr('TauDEM multifile command line tools folder'),
TauDEMUtils.taudemMultifilePath(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.TAUDEM_USE_SINGLEFILE,
self.tr('Enable singlefile TauDEM tools'), True))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.TAUDEM_USE_MULTIFILE,
self.tr('Enable multifile TauDEM tools'), False))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.MPIEXEC_FOLDER,
self.tr('MPICH2/OpenMPI bin directory'),
Expand All @@ -102,63 +95,36 @@ def unload(self):
AlgorithmProvider.unload(self)

ProcessingConfig.removeSetting(TauDEMUtils.TAUDEM_FOLDER)
ProcessingConfig.removeSetting(TauDEMUtils.TAUDEM_MULTIFILE_FOLDER)
ProcessingConfig.removeSetting(TauDEMUtils.TAUDEM_USE_SINGLEFILE)
ProcessingConfig.removeSetting(TauDEMUtils.TAUDEM_USE_MULTIFILE)
ProcessingConfig.removeSetting(TauDEMUtils.MPIEXEC_FOLDER)
ProcessingConfig.removeSetting(TauDEMUtils.MPI_PROCESSES)

def _loadAlgorithms(self):
self.algs = []
basePath = TauDEMUtils.taudemDescriptionPath()

if ProcessingConfig.getSetting(TauDEMUtils.TAUDEM_USE_SINGLEFILE):
folder = os.path.join(basePath, 'single')

for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
descriptionFile = os.path.join(folder, descriptionFile)
self._algFromDescription(descriptionFile)

self.algs.append(PeukerDouglas())
self.algs.append(SlopeArea())
self.algs.append(LengthArea())
self.algs.append(DropAnalysis())
self.algs.append(DinfDistDown())
self.algs.append(DinfDistUp())
self.algs.append(GridNet())
self.algs.append(DinfTransLimAccum())
self.algs.append(DinfTransLimAccum2())

if ProcessingConfig.getSetting(TauDEMUtils.TAUDEM_USE_MULTIFILE):
folder = os.path.join(basePath, 'multi')

for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
descriptionFile = os.path.join(folder, descriptionFile)
self._algFromDescription(descriptionFile, True)

self.algs.append(PeukerDouglasMulti())
self.algs.append(SlopeAreaMulti())
self.algs.append(LengthAreaMulti())
self.algs.append(DropAnalysisMulti())
self.algs.append(DinfDistDownMulti())
self.algs.append(DinfDistUpMulti())
self.algs.append(GridNetMulti())
self.algs.append(DinfTransLimAccumMulti())
self.algs.append(DinfTransLimAccum2Multi())
folder = TauDEMUtils.taudemDescriptionPath()

for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
descriptionFile = os.path.join(folder, descriptionFile)
self._algFromDescription(descriptionFile)

self.algs.append(PeukerDouglas())
self.algs.append(SlopeArea())
self.algs.append(LengthArea())
self.algs.append(DropAnalysis())
self.algs.append(DinfDistDown())
self.algs.append(DinfDistUp())
self.algs.append(GridNet())
self.algs.append(DinfTransLimAccum())
self.algs.append(DinfTransLimAccum2())

def _algFromDescription(self, descriptionFile, multifile=False):
try:
if multifile:
alg = TauDEMMultifileAlgorithm(descriptionFile)
else:
alg = TauDEMAlgorithm(descriptionFile)
alg = TauDEMAlgorithm(descriptionFile)
if alg.name.strip() != '':
self.algs.append(alg)
else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('Could not open TauDEM algorithm: %s' % descriptionFile))
self.tr('Could not open TauDEM algorithm: {}'.format(descriptionFile)))
except Exception as e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('Could not open TauDEM algorithm %s:\n%s' % (descriptionFile, unicode(e))))
self.tr('Could not open TauDEM algorithm {}:\n{}'.format(descriptionFile, unicode(e))))
122 changes: 0 additions & 122 deletions python/plugins/processing/algs/taudem/TauDEMMultifileAlgorithm.py

This file was deleted.

20 changes: 2 additions & 18 deletions python/plugins/processing/algs/taudem/TauDEMUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,11 @@ def taudemPath():

if isMac():
testfolder = os.path.join(QgsApplication.prefixPath(), 'bin')
if os.path.exists(os.path.join(testfolder, 'slopearea')):
if os.path.exists(os.path.join(testfolder, 'pitremove')):
folder = testfolder
else:
testfolder = '/usr/local/bin'
if os.path.exists(os.path.join(testfolder, 'slopearea')):
folder = testfolder
return folder

@staticmethod
def taudemMultifilePath():
folder = ProcessingConfig.getSetting(TauDEMUtils.TAUDEM_MULTIFILE_FOLDER)
if folder is None:
folder = ''

if isMac():
testfolder = os.path.join(QgsApplication.prefixPath(), 'bin')
if os.path.exists(os.path.join(testfolder, 'slopearea')):
folder = testfolder
else:
testfolder = '/usr/local/bin'
if os.path.exists(os.path.join(testfolder, 'slopearea')):
if os.path.exists(os.path.join(testfolder, 'pitremove')):
folder = testfolder
return folder

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7866bda

Please sign in to comment.