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

Python procutils.which函数代码示例

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

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



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

示例1: _startProcess

    def _startProcess(self):
        executable = sys.executable
        env = os.environ

        twistdBinaries = procutils.which("twistd2.4") + procutils.which("twistd")
        if not twistdBinaries:
            return defer.fail(RuntimeError("Couldn't find twistd to start subprocess"))
        twistd = twistdBinaries[0]

        setsid = procutils.which("setsid")

        self.connector = JuiceConnector(self.juice, self)

        args = [
            sys.executable,
            twistd,
            '--logfile=%s' % (self.logPath,)]

        if not runtime.platform.isWindows():
            args.append('--pidfile=%s' % (self.pidPath,))

        args.extend(['-noy',
                     self.tacPath])

        if setsid:
            args = ['setsid'] + args
            executable = setsid[0]

        self.process = process.spawnProcess(
            self.connector, executable, tuple(args), env=env)
开发者ID:perkinslr,项目名称:axiom-py3,代码行数:30,代码来源:batch.py


示例2: check_for_ghostscript

def check_for_ghostscript():
    """
    Check and return path to ghostscript, returns None
    if is not installed.
    """
    from twisted.python.procutils import which
    if which("gs") == []:
        print "Ghostscript is not installed."
        return None
    return which("gs")[0]
开发者ID:bschollnick,项目名称:QuickBBS,代码行数:10,代码来源:PDF_Parser.py


示例3: get_disconnection_args

 def get_disconnection_args(self, dialer):
     assert dialer.binary == 'wvdial'
     
     killall_path = which('killall')[0]
     if not self.privileges_needed:
         return [killall_path, 'pppd', 'wvdial']
     else:
         gksudo_name = self.abstraction['gksudo_name']
         gksudo_path = which(gksudo_name)[0]
         return [gksudo_path, killall_path, 'pppd', 'wvdial']
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:10,代码来源:linuxbundled.py


示例4: test_path_setup

    def test_path_setup(self):
        """Validate that the path allows finding the executable."""
        from twisted.python.procutils import which
        open_port_exe = which("open-port")
        self.assertTrue(open_port_exe)
        self.assertTrue(open_port_exe[0].endswith("open-port"))

        close_port_exe = which("close-port")
        self.assertTrue(close_port_exe)
        self.assertTrue(close_port_exe[0].endswith("close-port"))
开发者ID:mcclurmc,项目名称:juju,代码行数:10,代码来源:test_invoker.py


示例5: get_disconnection_args

    def get_disconnection_args(self, dialer):
        assert dialer.binary == "wvdial"

        killall_path = which("killall")[0]
        if not self.privileges_needed:
            return [killall_path, "wvdial"]

        gksudo_name = self.abstraction["gksudo_name"]
        gksudo_path = which(gksudo_name)[0]
        args = " ".join([killall_path, "wvdial"])
        return [gksudo_path, "-c", args]
开发者ID:mrader11,项目名称:vodafone-mobile-connect,代码行数:11,代码来源:suse.py


示例6: jack_disconnect

def jack_disconnect(source, sink):
    """
    Calls jack_disconnect with the given arguments.
    Returns a Deferred
    """
    deferred = defer.Deferred()
    def _cb(result):
        if type(result) != int:
            lor.error("The result of calling jack_disconnect should be an int.")
        log.info("jack_disconnect result: " + str(result))
        if result == 0:
            deferred.callback(True)
        else:
            deferred.callback(False)
    
    exec_name = "jack_disconnect"
    try:
        executable = procutils.which(exec_name)[0]
    except IndexError:
        log.error("Could not find executable %s" % (exec_name))
        return defer.succeed(False)
    else:
        args = [source, sink]
        log.info("$ %s %s" % (executable, " ".join(list(args))))
        d = utils.getProcessValue(executable, args, os.environ, '.', reactor)
        d.addCallback(_cb)
        return deferred
开发者ID:aalex,项目名称:ubuntu-spinic,代码行数:27,代码来源:plumberjack.py


示例7: find_exe

def find_exe(exename):
    """
    Look for something named exename or exename + ".py".

    This is a kludge.

    @return: a list containing one element which is the path to the exename
        (if it is thought to be executable), or else the first element being
        sys.executable and the second element being the path to the
        exename + ".py", or else return False if one can't be found
    """
    warnings.warn("deprecated", DeprecationWarning)
    exes = which(exename)
    exe = exes and exes[0]
    if not exe:
        exe = os.path.join(sys.prefix, 'scripts', exename + '.py')
    if os.path.exists(exe):
        path, ext = os.path.splitext(exe)
        if ext.lower() in [".exe", ".bat",]:
            cmd = [exe,]
        else:
            cmd = [sys.executable, exe,]
        return cmd
    else:
        return False
开发者ID:ANTH040,项目名称:CouchPotatoServer,代码行数:25,代码来源:find_exe.py


示例8: list_cameras

def list_cameras():
    """
    Calls the Deferred with the dict of devices as argument.

    @rtype: Deferred
    """
    def _cb(text, deferred):
        #print text
        ret = _parse_milhouse_list_cameras(text)
        deferred.callback(ret)

    def _eb(reason, deferred):
        deferred.errback(reason)
        print("Error listing cameras: %s" % (reason))

    command_name = "milhouse"
    args = ['--list-v4l2']
    try:
        executable = procutils.which(command_name)[0] # gets the executable
    except IndexError:
        return defer.fail(RuntimeError("Could not find command %s" % (command_name)))
    deferred = defer.Deferred()
    d = utils.getProcessOutput(executable, args=args, env=os.environ, errortoo=True) # errortoo puts stderr in output
    d.addCallback(_cb, deferred)
    d.addErrback(_eb, deferred)
    return deferred
开发者ID:alg-a,项目名称:scenic,代码行数:26,代码来源:cameras.py


示例9: jackd_get_infos

def jackd_get_infos():
    """
    Calls jack-info to retrieve info about jackd servers.

    Returns a Deferred whose result is list of dict:
    [{
    'period': 1024,
    'rate': 44100,
    'latency': 32
    }]
    @rtype: Deferred
    """
    def _cb(text, deferred):
        #print text
        ret = _parse_jack_info(text)
        deferred.callback(ret)

    def _eb(reason, deferred):
        deferred.errback(reason)
        print("Error listing jackd servers: %s" % (reason))

    command_name = "jack-info"
    args = []
    try:
        executable = procutils.which(command_name)[0] # gets the executable
    except IndexError:
        return defer.fail(RuntimeError("Could not find command %s" % (command_name)))
    deferred = defer.Deferred()
    d = utils.getProcessOutput(executable, args=args, env=os.environ, errortoo=True) # errortoo puts stderr in output
    d.addCallback(_cb, deferred)
    d.addErrback(_eb, deferred)
    return deferred
开发者ID:alg-a,项目名称:scenic,代码行数:32,代码来源:jackd.py


示例10: xvideo_extension_is_present

def xvideo_extension_is_present():
    """
    Checks for XV extension.
    Result is boolean.

    @rtype: Deferred
    """
    def _cb(result, deferred):
        ret = True
        for line in result.splitlines():
            if line.find("no adaptors present") != -1: # Hardy
                ret = False
            if line.find("no adaptor present") != -1: # Karmic
                ret = False
        deferred.callback(ret)

    def _eb(reason, deferred):
        deferred.errback(reason)

    command_name = "xvinfo"
    try:
        executable = procutils.which(command_name)[0] # gets the executable
    except IndexError:
        return defer.fail(RuntimeError("Could not find command %s" % (command_name)))
    deferred = defer.Deferred()
    d = utils.getProcessOutput(executable, env=os.environ)
    d.addCallback(_cb, deferred)
    d.addErrback(_eb, deferred)
    return deferred
开发者ID:alg-a,项目名称:scenic,代码行数:29,代码来源:x11.py


示例11: assertExecuteWithKexAlgorithm

    def assertExecuteWithKexAlgorithm(self, keyExchangeAlgo):
        """
        Call execute() method of L{OpenSSHClientMixin} with an ssh option that
        forces the exclusive use of the key exchange algorithm specified by
        keyExchangeAlgo

        @type keyExchangeAlgo: L{str}
        @param keyExchangeAlgo: The key exchange algorithm to use

        @return: L{defer.Deferred}
        """
        kexAlgorithms = []
        try:
            output = subprocess.check_output([which('ssh')[0], '-Q', 'kex'],
                                             stderr=subprocess.STDOUT)
            if not isinstance(output, str):
                output = output.decode("utf-8")
            kexAlgorithms = output.split()
        except:
            pass

        if keyExchangeAlgo not in kexAlgorithms:
            raise unittest.SkipTest(
                "{} not supported by ssh client".format(
                    keyExchangeAlgo))

        d = self.execute('echo hello', ConchTestOpenSSHProcess(),
                         '-oKexAlgorithms=' + keyExchangeAlgo)
        return d.addCallback(self.assertEqual, b'hello\n')
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:29,代码来源:test_conch.py


示例12: _synchronously_find_addresses_via_config

def _synchronously_find_addresses_via_config():
    # originally by Greg Smith, hacked by Zooko to conform to Brian's API

    platform = _platform_map.get(sys.platform)
    if not platform:
        raise UnsupportedPlatformError(sys.platform)

    (pathtotool, args, regex,) = _tool_map[platform]

    # If pathtotool is a fully qualified path then we just try that.
    # If it is merely an executable name then we use Twisted's
    # "which()" utility and try each executable in turn until one
    # gives us something that resembles a dotted-quad IPv4 address.

    if os.path.isabs(pathtotool):
        return _query(pathtotool, args, regex)
    else:
        exes_to_try = which(pathtotool)
        for exe in exes_to_try:
            try:
                addresses = _query(exe, args, regex)
            except Exception:
                addresses = []
            if addresses:
                return addresses
        return []
开发者ID:jsgf,项目名称:tahoe-lafs,代码行数:26,代码来源:iputil.py


示例13: list_midi_devices

def list_midi_devices():
    """
    Twisted wrapper for _list_x11_displays.
    Result is a dict with keys "input" and "output". The value are dict with ID and name for each device.
    @rtype: Deferred
    """
    deferred = defer.Deferred()
    def _cb(text, deferred):
        #print text
        ret = _parse_miditream_list_devices(text)
        deferred.callback(ret)

    def _eb(reason, deferred):
        deferred.errback(reason)
        log.error("Error listing MIDI devices: %s" % (reason))

    command_name = "midistream"
    args = ['--list-devices']
    try:
        executable = procutils.which(command_name)[0] # gets the executable
    except IndexError:
        return defer.fail(RuntimeError("Could not find command %s" % (command_name)))
    log.debug("$ %s %s" % (executable, args))
    d = utils.getProcessOutput(executable, args=args, env=os.environ, errortoo=True) # errortoo puts stderr in output
    d.addCallback(_cb, deferred)
    d.addErrback(_eb, deferred)
    return deferred
开发者ID:alg-a,项目名称:scenic,代码行数:27,代码来源:midi.py


示例14: list_network_interfaces_addresses

def list_network_interfaces_addresses():
    """
    Lists network interfaces IP.
    @rtype: Deferred
    """
    def _cb(result, deferred):
        #print 'cb', result
        ret = _parse_ifconfig(result)
        deferred.callback(ret)
        return None
    def _eb(reason, deferred):
        print("Error calling ifconfig.")
        print(reason)
        deferred.errback(reason)
        return None
    command_name = "ifconfig"
    args = []
    try:
        executable = procutils.which(command_name)[0] # gets the executable
    except IndexError:
        return defer.fail(RuntimeError("Could not find command %s" % (command_name)))
    deferred = defer.Deferred()
    d = utils.getProcessOutput(executable, args=args, env=os.environ)
    d.addCallback(_cb, deferred)
    d.addErrback(_eb, deferred)
    return deferred
开发者ID:alg-a,项目名称:scenic,代码行数:26,代码来源:networkinterfaces.py


示例15: _synchronously_find_addresses_via_config

def _synchronously_find_addresses_via_config():
    # originally by Greg Smith, hacked by Zooko and then Daira

    # We don't reach here for cygwin.
    if platform == 'win32':
        commands = _win32_commands
    else:
        commands = _unix_commands

    for (pathtotool, args, regex) in commands:
        # If pathtotool is a fully qualified path then we just try that.
        # If it is merely an executable name then we use Twisted's
        # "which()" utility and try each executable in turn until one
        # gives us something that resembles a dotted-quad IPv4 address.

        if os.path.isabs(pathtotool):
            exes_to_try = [pathtotool]
        else:
            exes_to_try = which(pathtotool)

        for exe in exes_to_try:
            try:
                addresses = _query(exe, args, regex)
            except Exception:
                addresses = []
            if addresses:
                return addresses

    return []
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:29,代码来源:iputil.py


示例16: run_once

def run_once(executable, *args):
    """
    Runs a command, without looking at its output or return value.
    Returns a Deferred or None.
    """
    from twisted.internet import reactor
    global _original_environment_variables
    def _cb(result):
        #print(result)
        pass
    try:
        executable = procutils.which(executable)[0]
    except IndexError:
        log.error("Could not find executable %s" % (executable))
        return None
    else:
        env = _original_environment_variables
        for k in ["GTK2_RC_FILES", "GTK_RC_FILES"]:
            if env.has_key(k):
                log.info("%s=%s" % (k, env[k]))
        log.info("$ %s %s" % (executable, " ".join(list(args))))
        log.debug("ENV=%s" % (env))
        d = utils.getProcessValue(executable, args, env, '.', reactor)
        d.addCallback(_cb)
        return d
开发者ID:alg-a,项目名称:scenic,代码行数:25,代码来源:process.py


示例17: test_whichWithoutPATH

 def test_whichWithoutPATH(self):
     """
     Test that if C{os.environ} does not have a C{'PATH'} key,
     L{procutils.which} returns an empty list.
     """
     del os.environ['PATH']
     self.assertEqual(procutils.which("executable"), [])
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:7,代码来源:test_process.py


示例18: test_reExecService

    def test_reExecService(self):
        """
        Verify that sending a HUP to the test reexec.tac causes startService
        and stopService to be called again by counting the number of times
        START and STOP appear in the process output.
        """
        # Inherit the reactor used to run trial
        reactorArg = "--reactor=select"
        for arg in sys.argv:
            if arg.startswith("--reactor"):
                reactorArg = arg
                break

        tacFilePath = os.path.join(os.path.dirname(__file__), "reexec.tac")
        twistd = which("twistd")[0]
        deferred = Deferred()
        proc = reactor.spawnProcess(
            CapturingProcessProtocol(deferred, None),
            sys.executable,
            [sys.executable, "-W", "ignore", twistd, reactorArg, "-n", "-y", tacFilePath],
            env=os.environ,
        )
        reactor.callLater(3, proc.signalProcess, "HUP")
        reactor.callLater(6, proc.signalProcess, "TERM")
        output = yield deferred
        self.assertEquals(output.count("START"), 2)
        self.assertEquals(output.count("STOP"), 2)
开发者ID:eventable,项目名称:CalendarServer,代码行数:27,代码来源:test_caldav.py


示例19: _find_executable

def _find_executable(name):
    executables = which(name)
    if executables:
        return executables[0]
    else:
        raise RuntimeError("Couldn't find the executable (%s) in PATH: %s"
                % (name, os.environ.get('PATH', None)))
开发者ID:genome,项目名称:flow-core,代码行数:7,代码来源:request_builder.py


示例20: get_max_channels_in_raw

    def get_max_channels_in_raw(self):
        """
        Calls deferred with an int as argument
        @rtype: Deferred
        """
        def _cb(text, deferred):
            ret = None
            for i in text.splitlines():
                if "raw supports up to " in i:
                    ret = int(i.split()[-2])
            if ret is None:
                log.error("Could not figure out how many channels in raw are supported.")
                ret = 8
            deferred.callback(ret)

        def _eb(reason, deferred):
            deferred.errback(reason)
            print("Error getting max channels: %s" % (reason))

        command_name = "milhouse"
        args = ['--max-channels']
        try:
            executable = procutils.which(command_name)[0] # gets the executable
        except IndexError:
            return defer.fail(RuntimeError("Could not find command %s" % (command_name)))
        deferred = defer.Deferred()
        d = utils.getProcessOutput(executable, args=args, env=os.environ, errortoo=True) # errortoo puts stderr in output
        d.addCallback(_cb, deferred)
        d.addErrback(_eb, deferred)
        return deferred
开发者ID:alg-a,项目名称:scenic,代码行数:30,代码来源:streamer.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python randbytes.secureRandom函数代码示例发布时间:2022-05-27
下一篇:
Python monkey.MonkeyPatcher类代码示例发布时间: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