本文整理汇总了Python中twisted.internet.utils.getProcessOutput方法的典型用法代码示例。如果您正苦于以下问题:Python utils.getProcessOutput方法的具体用法?Python utils.getProcessOutput怎么用?Python utils.getProcessOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.utils
的用法示例。
在下文中一共展示了utils.getProcessOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_changes
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def _get_changes(self):
log.msg('LLVMGitPoller: polling git repo at %s' % self.repourl)
self.lastPoll = time.time()
# get a deferred object that performs the fetch
args = ['fetch', 'origin']
self._extend_with_fetch_refspec(args)
# This command always produces data on stderr, but we actually do not care
# about the stderr or stdout from this command. We set errortoo=True to
# avoid an errback from the deferred. The callback which will be added to this
# deferred will not use the response.
d = utils.getProcessOutput(self.gitbin, args,
path=self.workdir,
env=dict(PATH=os.environ['PATH']), errortoo=True )
return d
示例2: test_output
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def test_output(self):
"""
L{getProcessOutput} returns a L{Deferred} which fires with the complete
output of the process it runs after that process exits.
"""
scriptFile = self.makeSourceFile([
"import sys",
"for s in b'hello world\\n':",
" if hasattr(sys.stdout, 'buffer'):",
" # Python 3",
" s = bytes([s])",
" sys.stdout.buffer.write(s)",
" else:",
" # Python 2",
" sys.stdout.write(s)",
" sys.stdout.flush()"])
d = utils.getProcessOutput(self.exe, ['-u', scriptFile])
return d.addCallback(self.assertEqual, b"hello world\n")
示例3: test_outputWithErrorIgnored
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def test_outputWithErrorIgnored(self):
"""
The L{Deferred} returned by L{getProcessOutput} is fired with an
L{IOError} L{Failure} if the child process writes to stderr.
"""
# make sure stderr raises an error normally
scriptFile = self.makeSourceFile([
'import sys',
'sys.stderr.write("hello world\\n")'
])
d = utils.getProcessOutput(self.exe, ['-u', scriptFile])
d = self.assertFailure(d, IOError)
def cbFailed(err):
return self.assertFailure(err.processEnded, error.ProcessDone)
d.addCallback(cbFailed)
return d
示例4: test_outputWithErrorCollected
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def test_outputWithErrorCollected(self):
"""
If a C{True} value is supplied for the C{errortoo} parameter to
L{getProcessOutput}, the returned L{Deferred} fires with the child's
stderr output as well as its stdout output.
"""
scriptFile = self.makeSourceFile([
'import sys',
# Write the same value to both because ordering isn't guaranteed so
# this simplifies the test.
'sys.stdout.write("foo")',
'sys.stdout.flush()',
'sys.stderr.write("foo")',
'sys.stderr.flush()'])
d = utils.getProcessOutput(self.exe, ['-u', scriptFile], errortoo=True)
return d.addCallback(self.assertEqual, b"foofoo")
示例5: run_script
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def run_script(self, script, options=None):
"""
Run a script that logs messages and uses ``FlockerScriptRunner``.
:param ICommandLineScript: Script to run. Must be class in this module.
:param list options: Extra command line options to pass to the
script.
:return: ``Deferred`` that fires with list of decoded JSON messages.
"""
if options is None:
options = []
code = _SCRIPT_CODE.format(script.__name__, script.__name__)
d = getProcessOutput(
sys.executable, [b"-c", code] + options,
env=os.environ,
errortoo=True
)
d.addCallback(lambda data: (msg(b"script output: " + data), data)[1])
d.addCallback(lambda data: map(loads, data.splitlines()))
return d
示例6: spawn_reporter
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def spawn_reporter(self):
args = ["--quiet"]
if self.config.config:
args.extend(["-c", self.config.config])
env = os.environ.copy()
if self.config.clones > 0:
if self.config.is_clone:
return self._run_fake_reporter(args)
else:
env["FAKE_GLOBAL_PACKAGE_STORE"] = "1"
if self._reporter_command is None:
self._reporter_command = find_reporter_command(self.config)
# path is set to None so that getProcessOutput does not
# chdir to "." see bug #211373
env = encode_values(env)
result = getProcessOutput(self._reporter_command,
args=args, env=env,
errortoo=1,
path=None)
result.addCallback(self._got_reporter_output)
return result
示例7: test_outputWithErrorCollected
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def test_outputWithErrorCollected(self):
"""
If a C{True} value is supplied for the C{errortoo} parameter to
L{getProcessOutput}, the returned L{Deferred} fires with the child's
stderr output as well as its stdout output.
"""
scriptFile = self.makeSourceFile([
'import sys',
# Write the same value to both because ordering isn't guaranteed so
# this simplifies the test.
'sys.stdout.write("foo")',
'sys.stdout.flush()',
'sys.stderr.write("foo")',
'sys.stderr.flush()'])
d = utils.getProcessOutput(self.exe, ['-u', scriptFile], errortoo=True)
return d.addCallback(self.assertEqual, "foofoo")
示例8: _get_commit_comments
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def _get_commit_comments(self, rev):
args = ['log', rev, '--no-walk', r'--format=%s%n%b']
d = utils.getProcessOutput(self.gitbin, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
def process(git_output):
stripped_output = git_output.strip().decode(self.encoding)
if len(stripped_output) == 0:
raise EnvironmentError('could not get commit comment for rev')
#log.msg("LLVMGitPoller: _get_commit_comments: '%s'" % stripped_output)
return stripped_output
d.addCallback(process)
return d
示例9: _get_commit_timestamp
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def _get_commit_timestamp(self, rev):
# unix timestamp
args = ['log', rev, '--no-walk', r'--format=%ct']
d = utils.getProcessOutput(self.gitbin, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
def process(git_output):
stripped_output = git_output.strip()
if self.usetimestamps:
try:
stamp = float(stripped_output)
#log.msg("LLVMGitPoller: _get_commit_timestamp: \'%s\'" % stamp)
except Exception, e:
log.msg('LLVMGitPoller: caught exception converting output \'%s\' to timestamp' % stripped_output)
raise e
return stamp
else:
示例10: _get_commit_files
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def _get_commit_files(self, rev):
args = ['log', rev, '--name-only', '--no-walk', r'--format=%n']
d = utils.getProcessOutput(self.gitbin, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
def process(git_output):
fileList = git_output.split()
#log.msg("LLVMGitPoller: _get_commit_files: \'%s\'" % fileList)
return fileList
d.addCallback(process)
return d
示例11: _get_commit_name
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def _get_commit_name(self, rev):
args = ['log', rev, '--no-walk', r'--format=%aN <%aE>']
d = utils.getProcessOutput(self.gitbin, args, path=self.workdir, env=dict(PATH=os.environ['PATH']), errortoo=False )
def process(git_output):
stripped_output = git_output.strip().decode(self.encoding)
if len(stripped_output) == 0:
raise EnvironmentError('could not get commit name for rev')
#log.msg("LLVMGitPoller: _get_commit_name: \'%s\'" % stripped_output)
return stripped_output
d.addCallback(process)
return d
示例12: get_logs
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def get_logs(self, _):
args = []
args.extend(["log", "--xml", "--verbose", "--non-interactive"])
if self.svnuser:
args.extend(["--username=%s" % self.svnuser])
if self.svnpasswd:
args.extend(["--password=%s" % self.svnpasswd])
args.extend(["--limit=%d" % (self.histmax), self.svnurl])
d = self.getProcessOutput(args)
return d
示例13: cmd_EXEC
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def cmd_EXEC(self, rest):
"""
Run C{rest} using the user's shell (or /bin/sh if they do not have
one).
"""
shell = self._pwd.getpwnam(getpass.getuser())[6]
if not shell:
shell = '/bin/sh'
if rest:
cmds = ['-c', rest]
return utils.getProcessOutput(shell, cmds, errortoo=1)
else:
os.system(shell)
# accessory functions
示例14: test_getProcessOutputPath
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def test_getProcessOutputPath(self):
"""
L{getProcessOutput} runs the given command with the working directory
given by the C{path} parameter.
"""
return self._pathTest(utils.getProcessOutput, self.assertEqual)
示例15: this_node_uuid
# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutput [as 别名]
def this_node_uuid(self):
getting_era = getProcessOutput(
"flocker-node-era", reactor=self._reactor, env=environ)
def got_era(era):
return retry_failure(
self._reactor, lambda: self._request(
b"GET", b"/state/nodes/by_era/" + era, None, {OK},
{NOT_FOUND: NotFound},
), [NotFound])
request = getting_era.addCallback(got_era)
request.addCallback(lambda result: UUID(result["uuid"]))
return request