当前位置: 首页>>代码示例>>Python>>正文


Python SilentProgress.setInfo方法代码示例

本文整理汇总了Python中processing.core.SilentProgress.SilentProgress.setInfo方法的典型用法代码示例。如果您正苦于以下问题:Python SilentProgress.setInfo方法的具体用法?Python SilentProgress.setInfo怎么用?Python SilentProgress.setInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在processing.core.SilentProgress.SilentProgress的用法示例。


在下文中一共展示了SilentProgress.setInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: runGdal

# 需要导入模块: from processing.core.SilentProgress import SilentProgress [as 别名]
# 或者: from processing.core.SilentProgress.SilentProgress import setInfo [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 setInfo [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.setInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。