本文整理汇总了Python中gevent.subprocess.Popen.communicate方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.communicate方法的具体用法?Python Popen.communicate怎么用?Python Popen.communicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.subprocess.Popen
的用法示例。
在下文中一共展示了Popen.communicate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: logs_downloader
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def logs_downloader(logs_queued, recipient):
# Build tar command with tar command and logs sent by client
archive_path = '%ssrc/rockstor/logs/' % settings.ROOT_DIR
archive_file = 'requested_logs.tgz'
# If log download requested by Log Reader serve a personalized tgz
# file with log file name
if (recipient == 'reader_response'):
archive_file = '%s.tgz' % logs_queued[0]
archive_path += archive_file
download_command = []
download_command.extend(self.tar_utility)
download_command.append(archive_path)
# Get every log location via logs dictionary
for log in logs_queued:
download_command.append(self.build_log_path(log))
# Build download archive
download_process = Popen(download_command, bufsize=1, stdout=PIPE)
download_process.communicate()
# Return ready state for logs archive download specifying recipient
# (logManager or LogDownloader)
self.emit('logsdownload',
{
'key': 'logManager:logsdownload', 'data': {
'archive_name': '/logs/%s' % archive_file,
'recipient': recipient
}
})
示例2: test_ia_mine
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def test_ia_mine():
with open('testlist.txt', 'w') as fp:
fp.write('\n'.join(['nasa', 'iacli-test-item']))
cmd = 'ia mine testlist.txt --cache'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
cmd = 'ia mine testlist.txt --output=d.json'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
cmd = 'ia mine testlist.txt'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
# Test ids from stdin.
cmd = 'echo "nasa" | ia mine -'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
try:
os.remove('testlist.txt')
os.remove('d.json')
os.remove('nasa_meta.json')
os.remove('iacli-test-item_meta.json')
except OSError:
pass
示例3: save_weather_data
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def save_weather_data( location, filename ):
if location == NOT_FOUND_LOCATION:
location_not_found = True
location = DEFAULT_LOCATION
else:
location_not_found = False
p = Popen( [ WEGO, '--city=%s' % location ], stdout=PIPE, stderr=PIPE )
stdout, stderr = p.communicate()
if p.returncode != 0:
error( stdout + stderr )
dirname = os.path.dirname( filename )
if not os.path.exists( dirname ):
os.makedirs( dirname )
if location_not_found:
stdout += NOT_FOUND_MESSAGE
open( filename, 'w' ).write( stdout )
p = Popen( [ "bash", ANSI2HTML, "--palette=solarized", "--bg=dark" ], stdin=PIPE, stdout=PIPE, stderr=PIPE )
stdout, stderr = p.communicate( stdout )
if p.returncode != 0:
error( stdout + stderr )
open( filename+'.html', 'w' ).write( stdout )
示例4: test_ia_metadata_exists
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def test_ia_metadata_exists():
nasa_files = ['NASAarchiveLogo.jpg', 'globe_west_540.jpg', 'nasa_reviews.xml',
'nasa_meta.xml', 'nasa_archive.torrent', 'nasa_files.xml']
cmd = 'ia ls nasa'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
output = [x.strip() for x in stdout.split('\n')]
assert all(f in output for f in nasa_files)
assert proc.returncode == 0
cmd = 'ia ls nasa --glob="*torrent"'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert stdout == 'nasa_archive.torrent\r\n'
assert proc.returncode == 0
cmd = 'ia ls nasa --all --verbose'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
cmd = 'ia ls nasa --location'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
示例5: run_autobahn
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def run_autobahn():
"""
Spawn the autobahn test suite in a subprocess
"""
import os.path
cmd = ['wstest -m fuzzingclient -s %s/autobahn.json' % (
os.path.dirname(__file__),)]
wstest = Popen(cmd, stderr=PIPE, stdout=PIPE, shell=True)
if wstest.wait():
# something went wrong, it's boom time.
stdout, stderr = wstest.communicate(None)
sys.stderr.write(stderr)
sys.stderr.flush()
sys.stdout.write(stdout)
sys.stderr.flush()
raise RuntimeError
# parse the generated report to see if we have failures
chk = Popen(
'fgrep gevent_websocket reports/clients/index.html | grep Fail',
stdout=PIPE, shell=True)
stdout, stderr = chk.communicate(None)
if stdout:
sys.stderr.write('Autobahn test failures:\n' + stdout)
raise SystemExit(1)
示例6: test_ia_upload
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def test_ia_upload():
# upload from stdin.
cmd = ('echo "Hello World!" |'
'ia upload iacli-test-item - --remote-name="stdin.txt" --size-hint=8')
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
cmd = ('echo "Hello World!" |'
'ia upload iacli-test-item -')
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 1
assert stderr == '--remote-name is required when uploading from stdin.\n'
# upload file.
cmd = 'ia upload iacli-test-item setup.py'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
# upload debug.
cmd = 'ia upload iacli-test-item setup.py --debug'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
# upload non-200 status_code.
cmd = ('echo "Hello World!" |'
'ia upload iacli-test-item - --remote-name="iacli-test-item_meta.xml"')
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert stderr == 'error "AccessDenied" (403): Access Denied\n'
assert proc.returncode == 1
示例7: test_invoke
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def test_invoke():
# Run a subprocess through Popen to make sure
# libev is handling SIGCHLD. This could *probably* be simplified to use
# just hub.loop.install_sigchld
p = Popen("true", stdout=PIPE, stderr=PIPE)
gevent.sleep(0)
p.communicate()
gevent.sleep(0)
示例8: test_ia_metadata_exists
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def test_ia_metadata_exists():
cmd = 'ia metadata --exists iacli_test-doesnotexist'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 1
cmd = 'ia metadata --exists nasa'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
示例9: test_ia_metadata_modify
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def test_ia_metadata_modify():
# Modify test item.
valid_key = "foo-{k}".format(k=int(time()))
cmd = 'ia metadata --modify="{k}:test_value" iacli_test_item'.format(k=valid_key)
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 0
# Submit illegal modification.
cmd = 'ia metadata --modify="-foo:test_value" iacli_test_item'
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
assert proc.returncode == 1
assert "Illegal tag name" in stderr
示例10: execute_cmd_with_output
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def execute_cmd_with_output(cmd, stdin=None):
log.debug("Running command: %r" % cmd)
p = Popen(cmd, bufsize=-1, stdout=PIPE, stderr=PIPE, stdin=stdin)
(msgs, errs) = p.communicate()
if p.returncode != 0:
raise Exception('Failed to run command')
return (msgs, errs)
示例11: link_alive_tcp
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def link_alive_tcp( link, remote_ip ):
"""
Returns status of the link.
If the link is alive, returns its rtt to the remote_ip.
Use this method to check if the link is alive:
$ nc -v -s 192.168.0.101 -w 1 1.1.1.1 35501
nc: connect to 1.1.1.1 port 35501 (tcp) timed out: Operation now in progress
$ nc -v -s 192.168.0.101 -w 1 5.9.243.189 35501
nc: connect to 5.9.243.189 port 35501 (tcp) failed: Connection refused
"""
if link[0] in 'el':
source_ip = ip_of_interface( link )
if source_ip is None:
log("Can't detect IP address of %s" % link)
return
cmd = ['nc', '-v', '-s', source_ip, '-w', '1', remote_ip, '35501' ]
p = Popen(cmd, stdout=PIPE, stderr=STDOUT)
stdout = p.communicate()[0]
if 'Connection refused' in stdout:
return '1'
return None
示例12: ipv6_supported
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def ipv6_supported():
"""Checks whether we can support IPv6 on this host.
:returns tuple[bool,str]: supported, reason for lack of support or None.
"""
if not os.path.exists("/proc/sys/net/ipv6"):
return False, "/proc/sys/net/ipv6 is missing (IPv6 compiled out?)"
try:
check_call(["which", "ip6tables"])
except FailedSystemCall:
return False, ("ip6tables not installed; Calico IPv6 support requires "
"Linux kernel v3.3 or above and ip6tables v1.4.14 or "
"above.")
try:
# Use -C, which checks for a particular rule. We don't expect the rule
# to exist but iptables will give us a distinctive error if the
# rpfilter module is missing.
proc = Popen(["ip6tables", "-C", "FORWARD", "-m", "rpfilter"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if "Couldn't load match" in err:
return False, (
"ip6tables is missing required rpfilter match module; "
"Calico IPv6 support requires Linux kernel v3.3 or "
"above and ip6tables v1.4.14 or above."
)
except OSError:
return False, "Failed to execute ip6tables"
return True, None
示例13: worker
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def worker():
print 'start'
sub = Popen(['sleep 10'], stdout=PIPE, shell=True)
# sub = Popen(['top'], stdout=PIPE, shell=True)
out, err = sub.communicate()
print 'end'
return out.rstrip()
示例14: get_doc_index
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def get_doc_index(document, filepath):
words = {}
command = 'tesseract ' + filepath + ' -l hrv stdout'
#text = subprocess.check_output(command, shell=True)
print '>>> ', command
sub = Popen([command], stdout=PIPE, shell=True)
text, err = sub.communicate()
print '>>> ', command, 'DONE'
# extract page num from file path
match = re.search('.*xl-(\d+).png', filepath)
if match:
page = int(match.groups()[0])
for word in text.strip().split():
# skip small words
if len(word) <= 2:
continue
if word in words:
document_dict = words[word]
if document['name'] in document_dict:
pages_set = words[word][document['name']]
pages_set.add(page)
words[word][document['name']] = pages_set
else:
words[word][document['name']] = set([page])
else:
# init word
words[word] = {document['name']: set([page])}
return len(words)
示例15: try_get_video_name
# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import communicate [as 别名]
def try_get_video_name(self, video_url):
print "Getting name for %s"%video_url
cmd=['youtube-dl', '--get-title',video_url]
temp = Popen(cmd, stdout=PIPE)
out, err = temp.communicate()
print out
return out