Ejemplo n.º 1
0
def execute(commands, feedback=None):
    if feedback is None:
        feedback = QgsProcessingFeedback()

    fused_command = ' '.join([str(c) for c in commands])
    QgsMessageLog.logMessage(fused_command, 'Processing', QgsMessageLog.INFO)
    feedback.pushInfo('WhiteBox Tools command:')
    feedback.pushCommandInfo(fused_command)
    feedback.pushInfo('WhiteBox Tools command output:')

    loglines = []
    with subprocess.Popen(fused_command,
                          shell=True,
                          stdout=subprocess.PIPE,
                          stdin=subprocess.DEVNULL,
                          stderr=subprocess.STDOUT,
                          universal_newlines=True) as proc:
        try:
            for line in iter(proc.stdout.readline, ''):
                if '%' in line:
                    try:
                        feedback.setProgress(
                            int(progressRegex.search(line).group(0)))
                    except:
                        pass
                else:
                    feedback.pushConsoleInfo(line)
                    loglines.append(line)
        except:
            pass

    if ProcessingConfig.getSetting(WHITEBOX_VERBOSE):
        QgsMessageLog.logMessage('\n'.join(loglines), 'Processing',
                                 QgsMessageLog.INFO)
Ejemplo n.º 2
0
    def runGdal(commands, feedback=None):
        if feedback is None:
            feedback = QgsProcessingFeedback()
        envval = os.getenv('PATH')
        # We need to give some extra hints to get things picked up on OS X
        isDarwin = False
        try:
            isDarwin = platform.system() == 'Darwin'
        except IOError:  # https://travis-ci.org/m-kuhn/QGIS#L1493-L1526
            pass
        if isDarwin and os.path.isfile(
                os.path.join(QgsApplication.prefixPath(), "bin", "gdalinfo")):
            # Looks like there's a bundled gdal. Let's use it.
            os.environ['PATH'] = "{}{}{}".format(
                os.path.join(QgsApplication.prefixPath(), "bin"), os.pathsep,
                envval)
            os.environ['DYLD_LIBRARY_PATH'] = os.path.join(
                QgsApplication.prefixPath(), "lib")
        else:
            # Other platforms should use default gdal finder codepath
            settings = QgsSettings()
            path = settings.value('/GdalTools/gdalPath', '')
            if not path.lower() in envval.lower().split(os.pathsep):
                envval += '{}{}'.format(os.pathsep, path)
                os.putenv('PATH', envval)

        fused_command = ' '.join([str(c) for c in commands])
        ProcessingLog.addToLog(ProcessingLog.LOG_INFO, fused_command)
        feedback.pushInfo('GDAL command:')
        feedback.pushCommandInfo(fused_command)
        feedback.pushInfo('GDAL command output:')
        success = False
        retry_count = 0
        while not success:
            loglines = []
            loglines.append('GDAL execution console output')
            try:
                with subprocess.Popen(
                        fused_command,
                        shell=True,
                        stdout=subprocess.PIPE,
                        stdin=subprocess.DEVNULL,
                        stderr=subprocess.STDOUT,
                        universal_newlines=True,
                ) as proc:
                    for line in proc.stdout:
                        feedback.pushConsoleInfo(line)
                        loglines.append(line)
                    success = True
            except IOError as e:
                if retry_count < 5:
                    retry_count += 1
                else:
                    raise IOError(
                        e.message +
                        u'\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}'
                        .format(len(loglines), u'\n'.join(loglines[-10:])))

        ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
        GdalUtils.consoleOutput = loglines
Ejemplo n.º 3
0
def execute(commands, feedback=None):
    print(commands)
    if feedback is None:
        feedback = QgsProcessingFeedback()

    fused_command = ' '.join([str(c) for c in commands])
    QgsMessageLog.logMessage(fused_command, 'Processing', Qgis.Info)
    feedback.pushInfo('FUSION command:')
    feedback.pushCommandInfo(fused_command)
    feedback.pushInfo('FUSION command output:')

    loglines = []
    with subprocess.Popen(fused_command,
                          shell=True,
                          stdout=subprocess.PIPE,
                          stdin=subprocess.DEVNULL,
                          stderr=subprocess.STDOUT,
                          universal_newlines=True) as proc:
        try:
            for line in iter(proc.stdout.readline, ''):
                feedback.pushConsoleInfo(line)
                loglines.append(line)
        except:
            pass

    if ProcessingConfig.getSetting(FUSION_VERBOSE):
        QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', Qgis.Info)
Ejemplo n.º 4
0
    def runGdal(commands, feedback=None):
        if feedback is None:
            feedback = QgsProcessingFeedback()
        envval = os.getenv('PATH')
        # We need to give some extra hints to get things picked up on OS X
        isDarwin = False
        try:
            isDarwin = platform.system() == 'Darwin'
        except IOError:  # https://travis-ci.org/m-kuhn/QGIS#L1493-L1526
            pass
        if isDarwin and os.path.isfile(os.path.join(QgsApplication.prefixPath(), "bin", "gdalinfo")):
            # Looks like there's a bundled gdal. Let's use it.
            os.environ['PATH'] = "{}{}{}".format(os.path.join(QgsApplication.prefixPath(), "bin"), os.pathsep, envval)
            os.environ['DYLD_LIBRARY_PATH'] = os.path.join(QgsApplication.prefixPath(), "lib")
        else:
            # Other platforms should use default gdal finder codepath
            settings = QgsSettings()
            path = settings.value('/GdalTools/gdalPath', '')
            if not path.lower() in envval.lower().split(os.pathsep):
                envval += '{}{}'.format(os.pathsep, path)
                os.putenv('PATH', envval)

        fused_command = ' '.join([str(c) for c in commands])
        QgsMessageLog.logMessage(fused_command, 'Processing', Qgis.Info)
        feedback.pushInfo('GDAL command:')
        feedback.pushCommandInfo(fused_command)
        feedback.pushInfo('GDAL command output:')
        success = False
        retry_count = 0
        while not success:
            loglines = []
            loglines.append('GDAL execution console output')
            try:
                with subprocess.Popen(
                    fused_command,
                    shell=True,
                    stdout=subprocess.PIPE,
                    stdin=subprocess.DEVNULL,
                    stderr=subprocess.STDOUT,
                    universal_newlines=True,
                ) as proc:
                    for line in proc.stdout:
                        feedback.pushConsoleInfo(line)
                        loglines.append(line)
                    success = True
            except IOError as e:
                if retry_count < 5:
                    retry_count += 1
                else:
                    raise IOError(
                        str(e) + u'\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}'.format(
                            len(loglines), u'\n'.join(loglines[-10:])))

            QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', Qgis.Info)
            GdalUtils.consoleOutput = loglines
Ejemplo n.º 5
0
def execute(commands, feedback=None):
    cmds = []
    cmds.append(os.path.join(mpichDirectory(), "mpiexec"))

    processes = ProcessingConfig.getSetting(TAUDEM_PROCESSES)
    if int(processes) <= 0:
        processes = 1

    cmds.append("-n")
    cmds.append(processes)
    cmds.extend(commands)

    if feedback is None:
        feedback = QgsProcessingFeedback()

    fused_command = " ".join([str(c) for c in cmds])
    # QgsMessageLog.logMessage(fused_command, "Processing", QgsMessageLog.INFO)
    QgsMessageLog.logMessage(fused_command, "Processing", Qgis.Info)
    feedback.pushInfo("TauDEM command:")
    feedback.pushCommandInfo(fused_command)
    feedback.pushInfo("TauDEM command output:")

    loglines = []
    with subprocess.Popen(fused_command,
                          shell=True,
                          stdout=subprocess.PIPE,
                          stdin=subprocess.DEVNULL,
                          stderr=subprocess.STDOUT,
                          universal_newlines=True) as proc:
        try:
            for line in iter(proc.stdout.readline, ""):
                feedback.pushConsoleInfo(line)
                loglines.append(line)
        except:
            pass

    if ProcessingConfig.getSetting(TAUDEM_VERBOSE):
        # QgsMessageLog.logMessage("\n".join(loglines), "Processing", QgsMessageLog.INFO)
        QgsMessageLog.logMessage("\n".join(loglines), "Processing", Qgis.Info)
Ejemplo n.º 6
0
def execute(commands, feedback=None):
    command = prepareArguments(commands)

    if feedback is None:
        feedback = QgsProcessingFeedback()

    feedback.pushInfo('pktools command:')
    feedback.pushCommandInfo(command)
    feedback.pushInfo('pktools command output:')

    loglines = []
    with subprocess.Popen(command,
                          shell=True,
                          stdout=subprocess.PIPE,
                          stdin=subprocess.DEVNULL,
                          stderr=subprocess.STDOUT,
                          universal_newlines=True) as proc:
        try:
            for line in iter(proc.stdout.readline, ''):
                feedback.pushConsoleInfo(line)
                loglines.append(line)
        except:
            pass
Ejemplo n.º 7
0
def execute(commands, feedback=None):
    cmds = []
    cmds.append(os.path.join(mpichDirectory(), "mpiexec"))

    processes = ProcessingConfig.getSetting(TAUDEM_PROCESSES)
    if int(processes) <= 0:
      processes = 1

    cmds.append("-n")
    cmds.append(processes)
    cmds.extend(commands)

    if feedback is None:
        feedback = QgsProcessingFeedback()

    fused_command = " ".join([str(c) for c in cmds])
    QgsMessageLog.logMessage(fused_command, "Processing", QgsMessageLog.INFO)
    feedback.pushInfo("TauDEM command:")
    feedback.pushCommandInfo(fused_command)
    feedback.pushInfo("TauDEM command output:")

    loglines = []
    with subprocess.Popen(fused_command,
                          shell=True,
                          stdout=subprocess.PIPE,
                          stdin=subprocess.DEVNULL,
                          stderr=subprocess.STDOUT,
                          universal_newlines=True) as proc:
        try:
            for line in iter(proc.stdout.readline, ""):
                feedback.pushConsoleInfo(line)
                loglines.append(line)
        except:
            pass

    if ProcessingConfig.getSetting(TAUDEM_VERBOSE):
        QgsMessageLog.logMessage("\n".join(loglines), "Processing", QgsMessageLog.INFO)
Ejemplo n.º 8
0
    def runChloe(commands, feedback=None):

        cwd = os.path.dirname(__file__) + os.sep + 'Chloe2012'
        print('cwd : ' + cwd)
        if feedback is None:
            feedback = QgsProcessingFeedback()
        envval = os.getenv('PATH')
        # We need to give some extra hints to get things picked up on OS X
        isDarwin = False
        try:
            isDarwin = platform.system() == 'Darwin'
        except IOError:  # https://travis-ci.org/m-kuhn/QGIS#L1493-L1526
            pass
        if isDarwin and os.path.isfile(
                os.path.join(QgsApplication.prefixPath(), "bin", "chloeinfo")):
            # Looks like there's a bundled chloe. Let's use it.
            os.environ['PATH'] = "{}{}{}".format(
                os.path.join(QgsApplication.prefixPath(), "bin"), os.pathsep,
                envval)
            os.environ['DYLD_LIBRARY_PATH'] = os.path.join(
                QgsApplication.prefixPath(), "lib")
        else:
            # Other platforms should use default chloe finder codepath
            settings = QgsSettings()
            path = settings.value('/ChloeTools/chloePath', '')
            if not path.lower() in envval.lower().split(os.pathsep):
                envval += '{}{}'.format(os.pathsep, path)
                os.putenv('PATH', envval)

        fused_command = ' '.join([str(c) for c in commands])
        QgsMessageLog.logMessage(fused_command, 'Processing', Qgis.Info)
        feedback.pushInfo('CHLOE command:')
        feedback.pushCommandInfo(fused_command)
        feedback.pushInfo('CHLOE command output:')

        success = False
        retry_count = 0
        while not success:
            loglines = []
            loglines.append('CHLOE execution console output')
            print('step while')
            try:
                #print('runChloe')
                #feedback.pushConsoleInfo('runChloe')
                with subprocess.Popen(
                        fused_command,
                        shell=True,
                        stdout=subprocess.PIPE,
                        stdin=subprocess.DEVNULL,
                        stderr=subprocess.STDOUT,
                        #universal_newlines=True,
                        cwd=cwd) as proc:
                    for byte_line in proc.stdout:
                        line = byte_line.decode(
                            'utf8',
                            errors='backslashreplace').replace('\r', '')
                        feedback.pushConsoleInfo(line)
                        loglines.append(line)
                    success = True
            except IOError as e:
                if retry_count < 5:
                    print('retry ' + str(retry_count))
                    retry_count += 1
                else:
                    raise IOError(
                        str(e) +
                        u'\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}'
                        .format(len(loglines), u'\n'.join(loglines[-10:])))

            QgsMessageLog.logMessage('\n'.join(loglines), 'Processing',
                                     Qgis.Info)
            ChloeUtils.consoleOutput = loglines