本文整理汇总了Python中twisted.internet.utils.getProcessOutputAndValue函数的典型用法代码示例。如果您正苦于以下问题:Python getProcessOutputAndValue函数的具体用法?Python getProcessOutputAndValue怎么用?Python getProcessOutputAndValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getProcessOutputAndValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getConnection
def getConnection(self):
maker = SSHConnectionMaker()
if not DOCKER:
raise SkipTest('docker is not installed')
# Start a docker container.
log.msg('Spawning container...', system='docker')
stdout, sdterr, rc = yield utils.getProcessOutputAndValue(
DOCKER,
['run', '-p', '22', '-d', 'moldit/ubuntu-ssh'],
)
if rc != 0:
self.fail("Could not spawn docker instance:\n%s\n%s" % (
stdout, stderr))
container_id = stdout.strip()
log.msg('Spawned container %s' % (container_id,), system='docker')
self.addCleanup(self.killDockerContainer, container_id)
# Generate an SSH uri for connecting to the container.
stdout, stderr, rc = yield utils.getProcessOutputAndValue(
DOCKER,
['port', container_id, '22'],
)
port = int(stdout.strip().split(':')[-1])
uri = 'ssh://mold:[email protected]:%d' % (port,)
log.msg('Generated SSH URI: %r' % (uri,))
conn = yield maker.getConnection(uri)
defer.returnValue(conn)
示例2: test_send_file_pre_generated_code
def test_send_file_pre_generated_code(self):
code = "1-abc"
filename = "testfile"
message = "test message"
send_dir = self.mktemp()
os.mkdir(send_dir)
with open(os.path.join(send_dir, filename), "w") as f:
f.write(message)
wormhole = self.find_executable()
server_args = ["--relay-url", self.relayurl]
send_args = server_args + [
"send",
"--code", code,
filename,
]
d1 = getProcessOutputAndValue(wormhole, send_args, path=send_dir)
receive_dir = self.mktemp()
os.mkdir(receive_dir)
receive_args = server_args + [
"receive", "--accept-file",
code,
]
d2 = getProcessOutputAndValue(wormhole, receive_args, path=receive_dir)
def _check_sender(res):
out, err, rc = res
out = out.decode("utf-8")
err = err.decode("utf-8")
self.failUnlessIn("Sending %d byte file named '%s'\n" %
(len(message), filename), out)
self.failUnlessIn("On the other computer, please run: "
"wormhole receive\n"
"Wormhole code is: %s\n\n" % code,
out)
self.failUnlessIn("File sent.. waiting for confirmation\n"
"Confirmation received. Transfer complete.\n",
out)
self.failUnlessEqual(err, "")
self.failUnlessEqual(rc, 0)
return d2
d1.addCallback(_check_sender)
def _check_receiver(res):
out, err, rc = res
out = out.decode("utf-8")
err = err.decode("utf-8")
self.failUnlessIn("Receiving %d bytes for '%s'" %
(len(message), filename), out)
self.failUnlessIn("Received file written to ", out)
self.failUnlessEqual(err, "")
self.failUnlessEqual(rc, 0)
fn = os.path.join(receive_dir, filename)
self.failUnless(os.path.exists(fn))
with open(fn, "r") as f:
self.failUnlessEqual(f.read(), message)
d1.addCallback(_check_receiver)
return d1
示例3: set_master
def set_master(_):
log.msg('gitpoller: checking out %s' % self.branch)
if self.branch == 'master': # repo is already on branch 'master', so reset
d = utils.getProcessOutputAndValue(self.gitbin,
['reset', '--hard', 'origin/%s' % self.branch],
path=self.workdir, env=os.environ)
else:
d = utils.getProcessOutputAndValue(self.gitbin,
['checkout', '-b', self.branch, 'origin/%s' % self.branch],
path=self.workdir, env=os.environ)
d.addCallback(self._convert_nonzero_to_failure)
d.addErrback(self._stop_on_failure)
return d
示例4: is_runnable
def is_runnable(self):
# One property of Versioneer is that many changes to the source tree
# (making a commit, dirtying a previously-clean tree) will change the
# version string. Entrypoint scripts frequently insist upon importing
# a library version that matches the script version (whatever was
# reported when 'pip install' was run), and throw a
# DistributionNotFound error when they don't match. This is really
# annoying in a workspace created with "pip install -e .", as you
# must re-run pip after each commit.
# So let's report just one error in this case (from test_version),
# and skip the other tests that we know will fail.
# Setting LANG/LC_ALL to a unicode-capable locale is necessary to
# convince Click to not complain about a forced-ascii locale. My
# apologies to folks who want to run tests on a machine that doesn't
# have the en_US.UTF-8 locale installed.
wormhole = self.find_executable()
d = getProcessOutputAndValue(wormhole, ["--version"],
env=dict(LC_ALL="en_US.UTF-8",
LANG="en_US.UTF-8"))
def _check(res):
out, err, rc = res
if rc != 0:
log.msg("wormhole not runnable in this tree:")
log.msg("out", out)
log.msg("err", err)
log.msg("rc", rc)
raise unittest.SkipTest("wormhole is not runnable in this tree")
d.addCallback(_check)
return d
示例5: _getBatchOutput
def _getBatchOutput(self, f):
fn = tempfile.mktemp()
open(fn, 'w').write(f)
l = []
port = self.server.getHost().port
cmds = ('-p %i -l testuser '
'--known-hosts kh_test '
'--user-authentications publickey '
'--host-key-algorithms ssh-rsa '
'-K direct '
'-i dsa_test '
'-a --nocache '
'-v -b %s 127.0.0.1') % (port, fn)
cmds = test_conch._makeArgs(cmds.split(), mod='cftp')[1:]
log.msg('running %s %s' % (sys.executable, cmds))
env = os.environ.copy()
env['PYTHONPATH'] = os.pathsep.join(sys.path)
d = getProcessOutputAndValue(sys.executable, cmds, env=env)
d.setTimeout(10)
d.addBoth(l.append)
while not l:
if hasattr(self.server.factory, 'proto'):
self.server.factory.proto.expectedLoseConnection = 1
reactor.iterate(0.1)
os.remove(fn)
result = l[0]
if isinstance(result, failure.Failure):
raise result.value
else:
log.msg(result[1])
return result[0]
示例6: git_remote_add
def git_remote_add(_):
d = utils.getProcessOutputAndValue(self.gitbin,
['remote', 'add', 'origin', self.repourl],
path=self.workdir, env=os.environ)
d.addCallback(self._convert_nonzero_to_failure)
d.addErrback(self._stop_on_failure)
return d
示例7: git_fetch_origin
def git_fetch_origin(_):
d = utils.getProcessOutputAndValue(
self.gitbin, ["fetch", "origin"], path=self.workdir, env=dict(PATH=os.environ["PATH"])
)
d.addCallback(self._convert_nonzero_to_failure)
d.addErrback(self._stop_on_failure)
return d
示例8: _getBatchOutput
def _getBatchOutput(self, f):
fn = self.mktemp()
open(fn, 'w').write(f)
port = self.server.getHost().port
cmds = ('-p %i -l testuser '
'--known-hosts kh_test '
'--user-authentications publickey '
'--host-key-algorithms ssh-rsa '
'-i dsa_test '
'-a '
'-v -b %s 127.0.0.1') % (port, fn)
cmds = test_conch._makeArgs(cmds.split(), mod='cftp')[1:]
log.msg('running %s %s' % (sys.executable, cmds))
env = os.environ.copy()
env['PYTHONPATH'] = os.pathsep.join(sys.path)
self.server.factory.expectedLoseConnection = 1
d = getProcessOutputAndValue(sys.executable, cmds, env=env)
def _cleanup(res):
os.remove(fn)
return res
d.addCallback(lambda res: res[0])
d.addBoth(_cleanup)
return d
示例9: execute
def execute(self):
"""Execute the CLI command.
Returns a deferred that will be called when the operation completes. The
parameter to the deferred is this object.
"""
def __cli_output_callback(result):
"""Callback from getProcessOutputAndValue"""
self._set_properties(result)
LOGGER.debug("Asterisk CLI %s exited %d" %
(self.host, self.exitcode))
if self.err:
LOGGER.debug(self.err)
if self.exitcode:
self._deferred.errback(self)
else:
self._deferred.callback(self)
def __cli_error_callback(result):
"""Errback from getProcessOutputAndValue"""
self._set_properties(result)
LOGGER.warning("Asterisk CLI %s exited %d with error: %s" %
(self.host, self.exitcode, self.err))
if self.err:
LOGGER.debug(self.err)
self._deferred.errback(self)
self._deferred = defer.Deferred()
deferred = utils.getProcessOutputAndValue(self._cmd[0],
self._cmd,
env=os.environ)
deferred.addCallbacks(callback=__cli_output_callback,
errback=__cli_error_callback,)
return self._deferred
示例10: _dovccmdImpl
def _dovccmdImpl(self, command, args, path, ssh_workdir):
full_args = []
full_env = os.environ.copy()
if self._isSshPrivateKeyNeededForCommand(command):
key_path = self._getSshPrivateKeyPath(ssh_workdir)
self._downloadSshPrivateKey(key_path)
known_hosts_path = None
if self.sshHostKey is not None or self.sshKnownHosts is not None:
known_hosts_path = self._getSshKnownHostsPath(ssh_workdir)
self._downloadSshKnownHosts(known_hosts_path)
self.adjustCommandParamsForSshPrivateKey(full_args, full_env,
key_path, None,
known_hosts_path)
full_args += [command] + args
res = yield utils.getProcessOutputAndValue(self.gitbin,
full_args, path=path, env=full_env)
(stdout, stderr, code) = res
stdout = bytes2unicode(stdout, self.encoding)
stderr = bytes2unicode(stderr, self.encoding)
if code != 0:
if code == 128:
raise GitError('command {} in {} on repourl {} failed with exit code {}: {}'.format(
full_args, path, self.repourl, code, stderr))
raise EnvironmentError('command {} in {} on repourl {} failed with exit code {}: {}'.format(
full_args, path, self.repourl, code, stderr))
return stdout.strip()
示例11: _dovccmd
def _dovccmd(self, command, args, path=None):
def encodeArg(arg):
if isinstance(arg, list):
return [encodeArg(a) for a in arg]
elif isinstance(arg, unicode):
return arg.encode("ascii")
return arg
d = utils.getProcessOutputAndValue(encodeArg(self.gitbin),
encodeArg([command] + args),
path=encodeArg(path), env=os.environ)
def _convert_nonzero_to_failure(res,
command,
args,
path):
"utility to handle the result of getProcessOutputAndValue"
(stdout, stderr, code) = res
if code != 0:
if code == 128:
raise GitError('command %s %s in %s on repourl %s failed with exit code %d: %s'
% (command, args, path, self.repourl, code, stderr))
raise EnvironmentError('command %s %s in %s on repourl %s failed with exit code %d: %s'
% (command, args, path, self.repourl, code, stderr))
return stdout.strip()
d.addCallback(_convert_nonzero_to_failure,
command,
args,
path)
return d
示例12: test_buildbot_cvs_mail_without_cvsroot_opt_exits_with_error
def test_buildbot_cvs_mail_without_cvsroot_opt_exits_with_error(self):
d = utils.getProcessOutputAndValue(
sys.executable,
[
self.buildbot_cvs_mail_path,
"--complete-garbage-opt=gomi",
'--cvsroot="ext:example.com:/cvsroot"',
"[email protected]",
"-P",
"test",
"--path",
"test",
"-R",
"[email protected]",
"-t",
"README",
"1.1",
"1.2",
"hello.c",
"2.2",
"2.3",
],
)
def check(xxx_todo_changeme2):
(stdout, stderr, code) = xxx_todo_changeme2
self.assertEqual(code, 2)
d.addCallback(check)
return d
示例13: test_buildbot_cvs_mail_with_unknown_opt_exits_with_error
def test_buildbot_cvs_mail_with_unknown_opt_exits_with_error(self):
d = utils.getProcessOutputAndValue(
sys.executable,
[
self.buildbot_cvs_mail_path,
"[email protected]",
"-P",
"test",
"--path",
"test",
"-R",
"[email protected]",
"-t",
"README",
"1.1",
"1.2",
"hello.c",
"2.2",
"2.3",
],
)
def check(xxx_todo_changeme3):
(stdout, stderr, code) = xxx_todo_changeme3
self.assertEqual(code, 2)
d.addCallback(check)
return d
示例14: _find_utf8_locale
def _find_utf8_locale(self):
# Click really wants to be running under a unicode-capable locale,
# especially on python3. macOS has en-US.UTF-8 but not C.UTF-8, and
# most linux boxes have C.UTF-8 but not en-US.UTF-8 . For tests,
# figure out which one is present and use that. For runtime, it's a
# mess, as really the user must take responsibility for setting their
# locale properly. I'm thinking of abandoning Click and going back to
# twisted.python.usage to avoid this problem in the future.
(out, err, rc) = yield getProcessOutputAndValue("locale", ["-a"])
if rc != 0:
log.msg("error running 'locale -a', rc=%s" % (rc,))
log.msg("stderr: %s" % (err,))
returnValue(None)
out = out.decode("utf-8") # make sure we get a string
utf8_locales = {}
for locale in out.splitlines():
locale = locale.strip()
if locale.lower().endswith((".utf-8", ".utf8")):
utf8_locales[locale.lower()] = locale
for wanted in ["C.utf8", "C.UTF-8", "en_US.utf8", "en_US.UTF-8"]:
if wanted.lower() in utf8_locales:
returnValue(utf8_locales[wanted.lower()])
if utf8_locales:
returnValue(list(utf8_locales.values())[0])
returnValue(None)
示例15: _finished
def _finished(ignored):
fd.close()
d = getProcessOutputAndValue(
'aunpack', (tp.path, '-X', downloadTempPath.path))
d.addErrback(log.err)
d.addCallback(_extracted)
return d