• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.getProcessOutputAndValue函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了getProcessOutputAndValue函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:moldit,项目名称:mold,代码行数:28,代码来源:test_ssh.py


示例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
开发者ID:vikas-parashar,项目名称:magic-wormhole,代码行数:58,代码来源:test_scripts.py


示例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
开发者ID:kevcruise,项目名称:buildbot,代码行数:13,代码来源:gitpoller.py


示例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
开发者ID:jrollins,项目名称:magic-wormhole,代码行数:31,代码来源:test_scripts.py


示例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]
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:31,代码来源:test_cftp.py


示例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
开发者ID:kevcruise,项目名称:buildbot,代码行数:7,代码来源:gitpoller.py


示例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
开发者ID:usualoma,项目名称:buildbot,代码行数:7,代码来源:gitpoller.py


示例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
开发者ID:AmirKhooj,项目名称:VTK,代码行数:28,代码来源:test_cftp.py


示例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
开发者ID:auntieNeo,项目名称:asterisk-testsuite,代码行数:35,代码来源:asterisk.py


示例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()
开发者ID:buildbot,项目名称:buildbot,代码行数:31,代码来源:gitpoller.py


示例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
开发者ID:Ham22,项目名称:buildbot,代码行数:29,代码来源:gitpoller.py


示例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
开发者ID:behlendorf,项目名称:buildbot,代码行数:30,代码来源:test_contrib_buildbot_cvs_mail.py


示例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
开发者ID:behlendorf,项目名称:buildbot,代码行数:28,代码来源:test_contrib_buildbot_cvs_mail.py


示例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)
开发者ID:meejah,项目名称:magic-wormhole,代码行数:25,代码来源:test_cli.py


示例15: _finished

 def _finished(ignored):
     fd.close()
     d = getProcessOutputAndValue(
         'aunpack', (tp.path, '-X', downloadTempPath.path))
     d.addErrback(log.err)
     d.addCallback(_extracted)
     return d
开发者ID:jsza,项目名称:tempus-map-updater,代码行数:7,代码来源:updater.py


示例16: _run

 def _run(self, program, arguments, error_message):
     out, err, code = yield getProcessOutputAndValue(program, args=arguments, env=os.environ)
     if code not in (0, 1): # Why do we allow 1? Without it uploads seem to sometimes say they fail. IDK
         self.log("{:d}", code)
         self.log(out)
         self.log(err)
         raise self.master.modules["commands"].exception("{} [CODE: {:d}] [OUT: {}] [ERR: {}]".format(error_message, code, out.replace("\n"," ")[-60:], err.replace("\n"," ")[-60:]))
开发者ID:Fugiman,项目名称:Servrhe,代码行数:7,代码来源:ftp.py


示例17: method

 def method(testcase):
     testcase.expectCommands(Expect("command"))
     testcase.expectCommands(Expect("command2"))
     d = utils.getProcessOutputAndValue("command", ())
     d.addCallback(self.assertEqual, ('', '', 0))
     d.addCallback(lambda _: testcase.assertAllCommandsRan())
     return d
开发者ID:MPanH,项目名称:buildbot,代码行数:7,代码来源:test_test_util_gpo.py


示例18: initiateMotionCaptureCycle

 def initiateMotionCaptureCycle(self):
     if self.state != TreatCam.IDLE:
         return
     LOGGER.debug("Initiating motion capture cycle")
     self.state = TreatCam.PENDING_MOTION_CAPTURE
     deferred = utils.getProcessOutputAndValue(executable=self.config.motionCaptureProgram, args=self.config.motionCaptureProgramArgs.split(' '), reactor=self.reactor)
     deferred.addCallbacks(self.motionCapture, self.motionCaptureError)
开发者ID:DGeorgevich,项目名称:treater,代码行数:7,代码来源:raspicam.py


示例19: test_baddir

    def test_baddir(self):
        self.skip_if_cannot_daemonize()
        basedir = self.workdir("test_baddir")
        fileutil.make_dirs(basedir)

        d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
        def _cb(res):
            out, err, rc_or_sig = res
            self.failUnlessEqual(rc_or_sig, 1)
            self.failUnless("does not look like a node directory" in err, err)
        d.addCallback(_cb)

        def _then_stop_it(res):
            return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
        d.addCallback(_then_stop_it)

        def _cb2(res):
            out, err, rc_or_sig = res
            self.failUnlessEqual(rc_or_sig, 2)
            self.failUnless("does not look like a running node directory" in err)
        d.addCallback(_cb2)

        def _then_start_in_bogus_basedir(res):
            not_a_dir = os.path.join(basedir, "bogus")
            return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
        d.addCallback(_then_start_in_bogus_basedir)

        def _cb3(res):
            out, err, rc_or_sig = res
            self.failUnlessEqual(rc_or_sig, 1)
            self.failUnless("does not look like a directory at all" in err, err)
        d.addCallback(_cb3)
        return d
开发者ID:ducki2p,项目名称:tahoe-lafs,代码行数:33,代码来源:test_runner.py


示例20: spawnChild

 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)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:7,代码来源:test_process.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.getProcessValue函数代码示例发布时间:2022-05-27
下一篇:
Python utils.getProcessOutput函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap