本文整理汇总了Python中twisted.python.procutils.which函数的典型用法代码示例。如果您正苦于以下问题:Python which函数的具体用法?Python which怎么用?Python which使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了which函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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]
示例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']
示例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"))
示例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]
示例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
示例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
示例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
示例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
示例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
示例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')
示例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 []
示例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
示例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
示例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 []