當前位置: 首頁>>代碼示例>>Python>>正文


Python SilentProgress.setConsoleInfo方法代碼示例

本文整理匯總了Python中processing.core.SilentProgress.SilentProgress.setConsoleInfo方法的典型用法代碼示例。如果您正苦於以下問題:Python SilentProgress.setConsoleInfo方法的具體用法?Python SilentProgress.setConsoleInfo怎麽用?Python SilentProgress.setConsoleInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在processing.core.SilentProgress.SilentProgress的用法示例。


在下文中一共展示了SilentProgress.setConsoleInfo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: runGdal

# 需要導入模塊: from processing.core.SilentProgress import SilentProgress [as 別名]
# 或者: from processing.core.SilentProgress.SilentProgress import setConsoleInfo [as 別名]
    def runGdal(commands, progress=None):
        if progress is None:
            progress = SilentProgress()
        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 = QSettings()
            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)
        progress.setInfo("GDAL command:")
        progress.setCommand(fused_command)
        progress.setInfo("GDAL command output:")
        success = False
        retry_count = 0
        while success == False:
            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:
                        progress.setConsoleInfo(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
開發者ID:spono,項目名稱:QGIS,代碼行數:60,代碼來源:GdalUtils.py

示例2: runGdal

# 需要導入模塊: from processing.core.SilentProgress import SilentProgress [as 別名]
# 或者: from processing.core.SilentProgress.SilentProgress import setConsoleInfo [as 別名]
    def runGdal(commands, progress=None):
        if progress is None:
            progress = SilentProgress()
        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 = QSettings()
            path = settings.value('/GdalTools/gdalPath', '')
            if not path.lower() in envval.lower().split(os.pathsep):
                envval += '{}{}'.format(os.pathsep, path)
                os.putenv('PATH', envval)

        loglines = []
        loglines.append('GDAL execution console output')
        fused_command = ''.join(['%s ' % c for c in commands])
        progress.setInfo('GDAL command:')
        progress.setCommand(fused_command)
        proc = subprocess.Popen(
            fused_command,
            shell=True,
            stdout=subprocess.PIPE,
            stdin=open(os.devnull),
            stderr=subprocess.STDOUT,
            universal_newlines=True,
        ).stdout
        progress.setInfo('GDAL command output:')
        for line in iter(proc.readline, ''):
            progress.setConsoleInfo(line)
            loglines.append(line)
        ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
        GdalUtils.consoleOutput = loglines
開發者ID:barogi,項目名稱:QGIS,代碼行數:43,代碼來源:GdalUtils.py


注:本文中的processing.core.SilentProgress.SilentProgress.setConsoleInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。