本文整理汇总了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
示例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