当前位置: 首页>>代码示例>>Python>>正文


Python utils.getProcessOutputAndValue方法代码示例

本文整理汇总了Python中twisted.internet.utils.getProcessOutputAndValue方法的典型用法代码示例。如果您正苦于以下问题:Python utils.getProcessOutputAndValue方法的具体用法?Python utils.getProcessOutputAndValue怎么用?Python utils.getProcessOutputAndValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.utils的用法示例。


在下文中一共展示了utils.getProcessOutputAndValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_processOutputAndValueStdin

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_get_processOutputAndValueStdin(self):
        """
        Standard input can be made available to the child process by passing
        bytes for the `stdinBytes` parameter.
        """
        scriptFile = self.makeSourceFile([
            "import sys",
            "sys.stdout.write(sys.stdin.read())",
        ])
        stdinBytes = b"These are the bytes to see."
        d = utils.getProcessOutputAndValue(
            self.exe,
            ['-u', scriptFile],
            stdinBytes=stdinBytes,
        )

        def gotOutputAndValue(out_err_code):
            out, err, code = out_err_code
            # Avoid making an exact equality comparison in case there is extra
            # random output on stdout (warnings, stray print statements,
            # logging, who knows).
            self.assertIn(stdinBytes, out)
            self.assertEqual(0, code)
        d.addCallback(gotOutputAndValue)
        return d 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:27,代码来源:test_iutils.py

示例2: _find_utf8_locale

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
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) 
开发者ID:warner,项目名称:magic-wormhole,代码行数:27,代码来源:test_cli.py

示例3: test_version

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_version(self):
        # "wormhole" must be on the path, so e.g. "pip install -e ." in a
        # virtualenv. This guards against an environment where the tests
        # below might run the wrong executable.
        self.maxDiff = None
        wormhole = self.find_executable()
        # we must pass on the environment so that "something" doesn't
        # get sad about UTF8 vs. ascii encodings
        out, err, rc = yield getProcessOutputAndValue(
            wormhole, ["--version"], env=os.environ)
        err = err.decode("utf-8")
        if "DistributionNotFound" in err:
            log.msg("stderr was %s" % err)
            last = err.strip().split("\n")[-1]
            self.fail("wormhole not runnable: %s" % last)
        ver = out.decode("utf-8") or err
        self.failUnlessEqual(ver.strip(),
                             "magic-wormhole {}".format(__version__))
        self.failUnlessEqual(rc, 0) 
开发者ID:warner,项目名称:magic-wormhole,代码行数:21,代码来源:test_cli.py

示例4: call_and_check_rc

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def call_and_check_rc(cmd, *args):
    def _check_rc(_args):
        (stdout, stderr, rc) = _args
        if rc != 0:
            err = ExecError('RC %d: %s %s' % (rc, cmd, ' '.join(args)))
            err.stdout = stdout.strip()
            err.stderr = stderr.strip()
            raise err

        log.msg('# %s' % (' '.join((cmd,) + args),))
        if stdout:
            log.msg(stdout)

    def _got_signal(f):
        f.trap(tuple)
        stdout, stderr, signum = f.value
        err = ExecError('Got signal %d: %s %s' % (signum, cmd, ' '.join(args)))
        err.stdout = stdout.strip()
        err.stderr = stderr.strip()
        raise err

    return utils.getProcessOutputAndValue(cmd, args, env=os.environ).addCallbacks(_check_rc, _got_signal) 
开发者ID:svpcom,项目名称:wifibroadcast,代码行数:24,代码来源:server.py

示例5: test_outputAndValue

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_outputAndValue(self):
        """
        The L{Deferred} returned by L{getProcessOutputAndValue} fires with a
        three-tuple, the elements of which give the data written to the child's
        stdout, the data written to the child's stderr, and the exit status of
        the child.
        """
        exe = sys.executable
        scriptFile = self.makeSourceFile([
            "import sys",
            "sys.stdout.write('hello world!\\n')",
            "sys.stderr.write('goodbye world!\\n')",
            "sys.exit(1)"
            ])

        def gotOutputAndValue((out, err, code)):
            self.assertEquals(out, "hello world!\n")
            self.assertEquals(err, "goodbye world!" + os.linesep)
            self.assertEquals(code, 1)
        d = utils.getProcessOutputAndValue(self.exe, ["-u", scriptFile])
        return d.addCallback(gotOutputAndValue) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_iutils.py

示例6: _getBatchOutput

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def _getBatchOutput(self, f):
        fn = tempfile.mktemp()
        open(fn, 'w').write(f)
        port = self.server.getHost().port
        cmds = ('-p %i -l testuser '
                    '-K unix '
                    '-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)
        if hasattr(self.server.factory, 'proto'):
            self.server.factory.proto.expectedLoseConnection = 1
        d = getProcessOutputAndValue(sys.executable, cmds, env=env)
        def cleanup(res):
            os.remove(fn)
            return res[0]
        d.addBoth(cleanup)
        return d 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:22,代码来源:test_cftp.py

示例7: testOutputSignal

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def testOutputSignal(self):
        # Use SIGKILL here because it's guaranteed to be delivered. Using
        # SIGHUP might not work in, e.g., a buildbot slave run under the
        # 'nohup' command.
        exe = sys.executable
        scriptFile = self.makeSourceFile([
            "import sys, os, signal",
            "sys.stdout.write('stdout bytes\\n')",
            "sys.stderr.write('stderr bytes\\n')",
            "sys.stdout.flush()",
            "sys.stderr.flush()",
            "os.kill(os.getpid(), signal.SIGKILL)"
            ])

        def gotOutputAndValue(err):
            (out, err, sig) = err.value # XXX Sigh wtf
            self.assertEquals(out, "stdout bytes" + os.linesep)
            self.assertEquals(err, "stderr bytes" + os.linesep)
            self.assertEquals(sig, signal.SIGKILL)

        d = utils.getProcessOutputAndValue(exe, ['-u', scriptFile])
        return d.addErrback(gotOutputAndValue) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:24,代码来源:test_iutils.py

示例8: _catch_up

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def _catch_up(self, res):
        if self.changeCount == 0:
            log.msg('LLVMGitPoller: no changes, no catch_up')
            return
        log.msg('LLVMGitPoller: catching up tracking branch')
        args = ['reset', '--hard', 'origin/%s' % (self.branch,)]
        d = utils.getProcessOutputAndValue(self.gitbin, args, path=self.workdir, env=dict(PATH=os.environ['PATH']))
        d.addCallback(self._convert_nonzero_to_failure)
        return d 
开发者ID:llvm,项目名称:llvm-zorg,代码行数:11,代码来源:llvmgitpoller.py

示例9: _convert_nonzero_to_failure

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def _convert_nonzero_to_failure(self, res):
        "utility method to handle the result of getProcessOutputAndValue"
        (stdout, stderr, code) = res
        if code != 0:
            raise EnvironmentError('command failed with exit code %d: %s' % (code, stderr))
        return (stdout, stderr, code) 
开发者ID:llvm,项目名称:llvm-zorg,代码行数:8,代码来源:llvmgitpoller.py

示例10: test_shebang

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_shebang(self):
        """
        Spawning a process with an executable which is a script starting
        with an interpreter definition line (#!) uses that interpreter to
        evaluate the script.
        """
        shebangOutput = b'this is the shebang output'

        scriptFile = self.makeSourceFile([
                "#!%s" % (pyExe.decode('ascii'),),
                "import sys",
                "sys.stdout.write('%s')" % (shebangOutput.decode('ascii'),),
                "sys.stdout.flush()"])
        os.chmod(scriptFile, 0o700)

        reactor = self.buildReactor()

        def cbProcessExited(args):
            out, err, code = args
            msg("cbProcessExited((%r, %r, %d))" % (out, err, code))
            self.assertEqual(out, shebangOutput)
            self.assertEqual(err, b"")
            self.assertEqual(code, 0)

        def shutdown(passthrough):
            reactor.stop()
            return passthrough

        def start():
            d = utils.getProcessOutputAndValue(scriptFile, reactor=reactor)
            d.addBoth(shutdown)
            d.addCallback(cbProcessExited)
            d.addErrback(err)

        reactor.callWhenRunning(start)
        self.runReactor(reactor) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:38,代码来源:test_process.py

示例11: test_processCommandLineArguments

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_processCommandLineArguments(self):
        """
        Arguments given to spawnProcess are passed to the child process as
        originally intended.
        """
        us = b"twisted.internet.test.process_cli"

        args = [b'hello', b'"', b' \t|<>^&', br'"\\"hello\\"', br'"foo\ bar baz\""']
        # Ensure that all non-NUL characters can be passed too.
        if _PY3:
            args.append("".join(map(chr, xrange(1,255))).encode("utf8"))
        else:
            args.append("".join(map(chr, xrange(1,255))))

        reactor = self.buildReactor()

        def processFinished(finishedArgs):
            output, err, code = finishedArgs
            output = output.split(b'\0')
            # Drop the trailing \0.
            output.pop()
            self.assertEqual(args, output)

        def shutdown(result):
            reactor.stop()
            return result

        def spawnChild():
            d = succeed(None)
            d.addCallback(lambda dummy: utils.getProcessOutputAndValue(
                pyExe, [b"-m", us] + args, env=properEnv,
                reactor=reactor))
            d.addCallback(processFinished)
            d.addBoth(shutdown)

        reactor.callWhenRunning(spawnChild)
        self.runReactor(reactor) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:39,代码来源:test_process.py

示例12: _getBatchOutput

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def _getBatchOutput(self, f):
        fn = self.mktemp()
        with open(fn, 'w') as fp:
            fp.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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:31,代码来源:test_cftp.py

示例13: test_outputAndValue

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_outputAndValue(self):
        """
        The L{Deferred} returned by L{getProcessOutputAndValue} fires with a
        three-tuple, the elements of which give the data written to the child's
        stdout, the data written to the child's stderr, and the exit status of
        the child.
        """
        scriptFile = self.makeSourceFile([
            "import sys",
            "if hasattr(sys.stdout, 'buffer'):",
            "    # Python 3",
            "    sys.stdout.buffer.write(b'hello world!\\n')",
            "    sys.stderr.buffer.write(b'goodbye world!\\n')",
            "else:",
            "    # Python 2",
            "    sys.stdout.write(b'hello world!\\n')",
            "    sys.stderr.write(b'goodbye world!\\n')",
            "sys.exit(1)"
            ])

        def gotOutputAndValue(out_err_code):
            out, err, code = out_err_code
            self.assertEqual(out, b"hello world!\n")
            if _PY3:
                self.assertEqual(err, b"goodbye world!\n")
            else:
                self.assertEqual(err, b"goodbye world!" +
                                      os.linesep)
            self.assertEqual(code, 1)
        d = utils.getProcessOutputAndValue(self.exe, ["-u", scriptFile])
        return d.addCallback(gotOutputAndValue) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:33,代码来源:test_iutils.py

示例14: test_getProcessOutputAndValuePath

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_getProcessOutputAndValuePath(self):
        """
        L{getProcessOutputAndValue} runs the given command with the working
        directory given by the C{path} parameter.
        """
        def check(out_err_status, dir):
            out, err, status = out_err_status
            self.assertEqual(out, dir)
            self.assertEqual(status, 0)
        return self._pathTest(utils.getProcessOutputAndValue, check) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_iutils.py

示例15: test_getProcessOutputAndValueDefaultPath

# 需要导入模块: from twisted.internet import utils [as 别名]
# 或者: from twisted.internet.utils import getProcessOutputAndValue [as 别名]
def test_getProcessOutputAndValueDefaultPath(self):
        """
        If no value is supplied for the C{path} parameter,
        L{getProcessOutputAndValue} runs the given command in the same working
        directory as the parent process and succeeds even if the current
        working directory is not accessible.
        """
        def check(out_err_status, dir):
            out, err, status = out_err_status
            self.assertEqual(out, dir)
            self.assertEqual(status, 0)
        return self._defaultPathTest(
            utils.getProcessOutputAndValue, check) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_iutils.py


注:本文中的twisted.internet.utils.getProcessOutputAndValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。