本文整理汇总了Python中gevent.subprocess.PIPE属性的典型用法代码示例。如果您正苦于以下问题:Python subprocess.PIPE属性的具体用法?Python subprocess.PIPE怎么用?Python subprocess.PIPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类gevent.subprocess
的用法示例。
在下文中一共展示了subprocess.PIPE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _reap_workers
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _reap_workers(workers, to_close, debug_log):
"""Collects the IO workers created with _mk_workers.
After killing the workers, also closes the subprocess's open PIPE handles.
See _safe_close for caveats around closing handles on windows.
Args:
* workers (List[Greenlet]) - The IO workers to kill.
* to_close (List[...]) - (see _mk_workers for definition). The handles to
close. These originate from the `Popen.std{out,err}` handles when the
recipe engine had to use PIPEs.
* debug_log (..stream.StreamEngine.Stream)
Should not raise an exception.
"""
debug_log.write_line('reaping IO workers...')
for worker in workers:
worker.kill()
gevent.wait(workers)
debug_log.write_line(' done')
for handle_name, handle in to_close:
_safe_close(debug_log, handle_name, handle)
示例2: _copy_lines
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _copy_lines(handle, outstream):
while True:
try:
# Because we use readline here we could, technically, lose some data in
# the event of a timeout.
data = handle.readline()
except RuntimeError:
# See NOTE(gevent) above.
return
if not data:
break
outstream.write_line(data.rstrip('\n'))
# It's either a file-like object, a string or it's a Stream (so we need to
# return PIPE)
示例3: _htmlize
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _htmlize(ansi_output, title, parsed_query):
"""Return HTML representation of `ansi_output`.
Use `title` as the title of the page.
Format page according to query parameters from `parsed_query`."""
cmd = ["bash", ANSI2HTML, "--palette=solarized"]
if not parsed_query.get('inverted_colors'):
cmd += ["--bg=dark"]
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate(ansi_output.encode("utf-8"))
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")
if proc.returncode != 0:
error(stdout + stderr)
if parsed_query.get('inverted_colors'):
stdout = stdout.replace(
'<body class="">', '<body class="" style="background:white;color:#777777">')
title = "<title>%s</title>" % title
opengraph = _get_opengraph(parsed_query)
stdout = re.sub("<head>", "<head>" + title + opengraph, stdout)
return stdout
示例4: qrencode_wrapper
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def qrencode_wrapper(query_string="", request_options=None, html=False):
if query_string == "":
query_string = ":firstpage"
if query_string in INTERNAL_TOPICS:
answer = get_internal(query_string)
else:
answer = query_string + "\n"
cmd = ["qrencode", "-t", "UTF8", "-o", "-"]
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
answer = p.communicate(answer.encode('utf-8'))[0]
if html:
return html_wrapper(answer), True
else:
return answer, True
示例5: html_wrapper
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def html_wrapper(data):
p = Popen([ "bash", ANSI2HTML, "--palette=xterm", "--bg=dark" ], stdin=PIPE, stdout=PIPE, stderr=PIPE)
data = data.encode('utf-8')
stdout, stderr = p.communicate(data)
if p.returncode != 0:
error(stdout + stderr)
return stdout.decode('utf-8')
示例6: _git
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _git(self, cmd, stdin=None):
"""Executes a git command and returns the standard output."""
p = subprocess.Popen(['git'] + cmd, cwd=self._repo, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, _ = p.communicate(stdin)
if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, ['git'] + cmd, None)
return stdout.strip().splitlines()
示例7: run_simulation_test
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def run_simulation_test(repo, *additional_args):
"""Runs the recipe simulation test for given repo.
Returns a tuple of exit code and output.
"""
proc = subprocess.Popen([
VPYTHON, os.path.join(repo.recipes_root_path, 'recipes.py'), 'test',
] + list(additional_args), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = proc.communicate()
retcode = proc.returncode
return retcode, output
示例8: __init__
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def __init__(self, recipe_deps, description_queue, outcome_queue, is_train,
cov_file, cover_module_imports):
super(RunnerThread, self).__init__()
self.cov_file = cov_file
cmd = [
sys.executable, '-u', sys.argv[0],
'--package', os.path.join(
recipe_deps.main_repo.path, RECIPES_CFG_LOCATION_REL),
'--proto-override', os.path.dirname(PB.__path__[0]),
]
# Carry through all repos explicitly via overrides
for repo_name, repo in recipe_deps.repos.iteritems():
if repo_name == recipe_deps.main_repo.name:
continue
cmd.extend(['-O', '%s=%s' % (repo_name, repo.path)])
cmd.extend(['test', '_runner'])
if is_train:
cmd.append('--train')
if cov_file:
cmd.extend(['--cov-file', cov_file])
if cover_module_imports:
cmd.append('--cover-module-imports')
self._runner_proc = subprocess.Popen(
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
self._description_queue = description_queue
self._outcome_queue = outcome_queue
示例9: _compile_protos
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _compile_protos(proto_files, proto_tree, protoc, argfile, dest):
"""Runs protoc over the collected protos, renames them and rewrites their
imports to make them import from `PB`.
Args:
* proto_files (List[Tuple[src_abspath: str, dest_relpath: str]])
* proto_tree (str): Path to the directory with all the collected .proto
files.
* protoc (str): Path to the protoc binary to use.
* argfile (str): Path to a protoc argfile containing a relative path to
every .proto file in proto_tree on its own line.
* dest (str): Path to the destination where the compiled protos should go.
"""
protoc_proc = subprocess.Popen(
[protoc, '--python_out', dest, '@'+argfile],
cwd=proto_tree, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = protoc_proc.communicate()
os.remove(argfile)
if protoc_proc.returncode != 0:
replacer = _rel_to_abs_replacer(proto_files)
print >> sys.stderr, "Error while compiling protobufs. Output:\n"
sys.stderr.write(replacer(output))
sys.exit(1)
rewrite_errors = []
for base, _, fnames in OS_WALK(dest):
for name in fnames:
err = _rewrite_and_rename(dest, os.path.join(base, name))
if err:
rewrite_errors.append(err)
with open(os.path.join(base, '__init__.py'), 'wb'):
pass
if rewrite_errors:
print >> sys.stderr, "Error while rewriting generated protos. Output:\n"
replacer = _rel_to_abs_replacer(proto_files)
for error in rewrite_errors:
print >> sys.stderr, replacer(error)
sys.exit(1)
示例10: _mk_workers
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _mk_workers(step, proc, pipes):
"""Makes greenlets to shuttle lines from the process's PIPE'd std{out,err}
handles to the recipe Step's std{out,err} handles.
NOTE: This applies to @@@annotator@@@ runs when allow_subannotations=False;
Step.std{out,err} will be Stream objects which don't implement `fileno()`,
but add an '!' in front of all lines starting with '@@@'. In build.proto
mode this code path should NOT be active at all; Placeholders will be
redirected directly to files on disk and non-placeholders will go straight
to butler (i.e. regular file handles).
Args:
* step (..step_runner.Step) - The Step object describing what we're
supposed to run.
* proc (subprocess.Popen) - The running subprocess.
* pipes (Set[str]) - A subset of {'stdout', 'stderr'} to make worker
greenlets for.
Returns Tuple[
workers: List[Greenlet],
to_close: List[Tuple[
handle_name: str,
proc_handle: fileobj,
]]
]. Both returned values are expected to be passed directly to
`_reap_workers` without inspection or alteration.
"""
workers = []
to_close = []
for handle_name in pipes:
proc_handle = getattr(proc, handle_name)
to_close.append((handle_name, proc_handle))
workers.append(gevent.spawn(
_copy_lines, proc_handle, getattr(step, handle_name),
))
return workers, to_close
示例11: get_moon
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def get_moon(parsed_query):
location = parsed_query['orig_location']
html = parsed_query['html_output']
lang = parsed_query['lang']
date = None
if '@' in location:
date = location[location.index('@')+1:]
location = location[:location.index('@')]
cmd = [globals.PYPHOON]
if lang:
cmd += ["-l", lang]
if date:
try:
dateutil.parser.parse(date)
except Exception as e:
print("ERROR: %s" % e)
else:
cmd += [date]
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout = p.communicate()[0]
stdout = stdout.decode("utf-8")
if parsed_query.get('no-terminal', False):
stdout = globals.remove_ansi(stdout)
if html:
p = Popen(
["bash", globals.ANSI2HTML, "--palette=solarized", "--bg=dark"],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate(stdout.encode("utf-8"))
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")
if p.returncode != 0:
globals.error(stdout + stderr)
return stdout
示例12: _wego_wrapper
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _wego_wrapper(location, parsed_query):
lang = parsed_query['lang']
location_name = parsed_query['override_location_name']
cmd = [WEGO, '--city=%s' % location]
if parsed_query.get('inverted_colors'):
cmd += ['-inverse']
if parsed_query.get('use_ms_for_wind'):
cmd += ['-wind_in_ms']
if parsed_query.get('narrow'):
cmd += ['-narrow']
if lang and lang in SUPPORTED_LANGS:
cmd += ['-lang=%s'%lang]
if parsed_query.get('use_imperial', False):
cmd += ['-imperial']
if location_name:
cmd += ['-location_name', location_name]
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")
return stdout, stderr, proc.returncode
示例13: _get_page
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _get_page(self, topic, request_options=None):
cmd = self._get_command(topic, request_options=request_options)
if cmd:
try:
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
answer = proc.communicate()[0].decode('utf-8', 'ignore')
except OSError:
return "ERROR of the \"%s\" adapter: please create an issue" % self._adapter_name
return answer
return ""
示例14: get_cmd_output
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def get_cmd_output(hostname, topic, request_options):
digest = get_digest({'h':hostname, 't': topic, 'r': request_options})
cache_file = '%s/cache/%s' % (MYDIR, digest)
if os.path.exists(cache_file):
return open(cache_file).read().decode('utf-8')
#elif hostname == 'rate.sx' and topic == ':firstpage' and os.path.exists(cache_file):
# return open(cache_file).read().decode('utf-8')
else:
currency = hostname.lower()
if currency.endswith('.rate.sx'):
currency = currency[:-8].upper()
if currency == 'COIN':
return "Use YOUR COIN instead of COIN in the query: for example btg.rate.sx, xvg.rate.sx, eth.rate.sx and so on\nTry:\n curl btg.rate.sx\n curl xvg.rate.sx\n curl xrb.rate.sx\n"
use_currency = currency
if currency not in currencies_names.SUPPORTED_CURRENCIES \
and currency not in coins_names.COIN_NAMES_DICT and currency != 'coin':
currency = 'USD'
if topic != ':firstpage':
try:
answer = calculator.calculate(topic.upper(), currency)
if answer:
answer = 'text %s' % answer
except ValueError as e:
return "ERROR: %s\n" % e
if answer is None:
try:
answer = draw.view(topic, use_currency=use_currency)
except RuntimeError as e:
return "ERROR: %s\n" % e
if answer is not None:
if request_options.get('no-terminal'):
answer = remove_ansi(answer)
open(cache_file, 'w').write(str(answer)+"\n")
return "%s\n" % answer
else:
return "ERROR: Can't parse your query: %s\n" % topic
cmd = ["%s/ve/bin/python" % MYDIR, "%s/bin/show_data.py" % MYDIR, currency, topic]
config = request_options
config['currency'] = currency
answer = view.show(config)
if config.get('no-terminal'):
answer = remove_ansi(answer)
open(cache_file, 'w').write(answer)
#p = Popen(cmd, stdout=PIPE, stderr=PIPE)
#answer = p.communicate()[0]
return answer.decode('utf-8')
示例15: _install_protos
# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import PIPE [as 别名]
def _install_protos(proto_package_path, dgst, proto_files):
"""Installs protos to `{proto_package_path}/PB`.
Args:
* proto_package_base (str) - The absolute path to the folder where:
* We should install protoc as '.../protoc/...'
* We should install the compiled proto files as '.../PB/...'
* We should use '.../tmp/...' as a tempdir.
* dgst (str) - The hexadecimal (lowercase) checksum for the protos we're
about to install.
* proto_files (List[Tuple[src_abspath: str, dest_relpath: str]])
Side-effects:
* Ensures that `{proto_package_path}/PB` exists and is the correct
version (checksum).
* Ensures that `{proto_package_path}/protoc` contains the correct
`protoc` compiler from CIPD.
"""
cipd_proc = subprocess.Popen([
'cipd'+_BAT, 'ensure', '-root', os.path.join(proto_package_path, 'protoc'),
'-ensure-file', '-'], stdin=subprocess.PIPE)
cipd_proc.communicate('''
infra/tools/protoc/${{platform}} protobuf_version:v{PROTOC_VERSION}
'''.format(PROTOC_VERSION=PROTOC_VERSION))
if cipd_proc.returncode != 0:
raise ValueError(
'failed to install protoc: retcode %d' % cipd_proc.returncode)
# This tmp folder is where all the temporary garbage goes. Future recipe
# engine invocations will attempt to clean this up as long as PB is
# up-to-date.
tmp_base = os.path.join(proto_package_path, 'tmp')
# proto_tree holds a tree of all the collected .proto files, to be passed to
# `protoc`
# pb_temp is the destination of all the generated files; it will be renamed to
# `{proto_package_path}/dest` as the final step of the installation.
_DirMaker()(tmp_base)
proto_tree = tempfile.mkdtemp(dir=tmp_base)
pb_temp = tempfile.mkdtemp(dir=tmp_base)
argfile_fd, argfile = tempfile.mkstemp(dir=tmp_base)
_collect_protos(argfile_fd, proto_files, proto_tree)
protoc = os.path.join(proto_package_path, 'protoc', 'protoc')
_compile_protos(proto_files, proto_tree, protoc, argfile, pb_temp)
with open(os.path.join(pb_temp, 'csum'), 'wb') as csum_f:
csum_f.write(dgst)
dest = os.path.join(proto_package_path, 'PB')
# Check the digest again, in case another engine beat us to the punch.
# This is still racy, but it makes the window substantially smaller.
if not _check_digest(proto_package_path, dgst):
old = tempfile.mkdtemp(dir=tmp_base)
_try_rename(dest, os.path.join(old, 'PB'))
_try_rename(pb_temp, dest)