本文整理汇总了Python中which.which函数的典型用法代码示例。如果您正苦于以下问题:Python which函数的具体用法?Python which怎么用?Python which使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了which函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_gotool
def _get_gotool(self, tool_name, env):
# First try the pref
# Then try which
# Then try the golang pref
# Finally try which golang
path = [d.strip()
for d in env.get_envvar("PATH", "").split(os.pathsep)
if d.strip()]
tool_path = env.get_pref(tool_name + "DefaultLocation", "")
if tool_path and os.path.exists(tool_path):
return tool_path
ext = sys.platform.startswith("win") and ".exe" or ""
golang_path = env.get_pref("golangDefaultLocation", "")
if golang_path:
tool_path = os.path.join(os.path.dirname(golang_dir), tool_name + ext)
if os.path.exists(tool_path):
return tool_path
try:
return which.which(tool_name, path=path)
except which.WhichError:
pass
try:
golang_path = which.which('golang', path=path)
except which.WhichError:
return None
tool_path = os.path.join(os.path.basename(golang_path, tool_name)) + ext
if os.path.exists(tool_path):
return tool_path
return None
开发者ID:Wilo,项目名称:komodo-go,代码行数:29,代码来源:lang_go.py
示例2: test_recognize_nodejs_file_with_interpreter
def test_recognize_nodejs_file_with_interpreter(self):
# If we have a node interpreter on our path, then these will be seen as
# Node.js files, otherwise they are seen as JavaScript files.
manifest = [
(tempfile.mktemp(".js"), """\
require('console');
"""),
(tempfile.mktemp(".js"), """\
module.exports = {};
"""),
(tempfile.mktemp(".js"), """\
foo.on('something', function(event) {
console.log(event.name);
});
"""),
]
import which
try:
which.which("node")
lang = "Node.js"
except which.WhichError:
# Could not find node interpreter.
import logging
log = logging.getLogger("test")
log.warn("No node interpreter was found on the path")
lang = "JavaScript"
for name, content in manifest:
path = join(self.data_dir, name)
_writefile(path, content)
koDoc = self._koDocFromPath(path)
self.assertEqual(koDoc.language, lang,
"%r found, expected %r, content %r" % (koDoc.language, lang, content))
开发者ID:Defman21,项目名称:KomodoEdit,代码行数:32,代码来源:test_koDocument.py
示例3: command
def command(cmd):
which(cmd)
def wrapper(argstr, **kwargs):
fullcmd = cmd + ' %s' % argstr
log.debug('Executing shell command: %s' % fullcmd)
return subprocess.Popen(fullcmd, shell=True, **kwargs)
return wrapper
开发者ID:jc0n,项目名称:video-montage,代码行数:7,代码来源:VideoMontager.py
示例4: debug
def debug(self, params, remote, background, debugger, debugparams, slowscript):
import which
use_lldb = False
use_gdb = False
if debugger:
try:
debugger = which.which(debugger)
except Exception as e:
print("You don't have %s in your PATH" % (debugger))
print(e)
return 1
else:
try:
debugger = which.which('gdb')
use_gdb = True
except Exception:
try:
debugger = which.which('lldb')
use_lldb = True
except Exception as e:
print("You don't have gdb or lldb in your PATH")
print(e)
return 1
args = [debugger]
extra_env = { 'MOZ_CRASHREPORTER_DISABLE' : '1' }
if debugparams:
import pymake.process
argv, badchar = pymake.process.clinetoargv(debugparams, os.getcwd())
if badchar:
print("The +debugparams you passed require a real shell to parse them.")
print("(We can't handle the %r character.)" % (badchar,))
return 1
args.extend(argv)
binpath = None
try:
binpath = self.get_binary_path('app')
except Exception as e:
print("It looks like your program isn't built.",
"You can run |mach build| to build it.")
print(e)
return 1
if use_gdb:
args.append('--args')
elif use_lldb:
args.append('--')
args.append(binpath)
if not remote:
args.append('-no-remote')
if not background and sys.platform == 'darwin':
args.append('-foreground')
if params:
args.extend(params)
if not slowscript:
extra_env['JS_DISABLE_SLOW_SCRIPT_SIGNALS'] = '1'
return self.run_process(args=args, append_env=extra_env,
ensure_exit_code=False, pass_thru=True)
开发者ID:JasonGross,项目名称:mozjs,代码行数:60,代码来源:mach_commands.py
示例5: getNodeOrNpmPath
def getNodeOrNpmPath(self, filename):
"""
Return the nodejs or npm path.
"""
if platform.system() == "Windows":
for ext in [".cmd", ".exe", ""]:
try:
nodeOrNpmPath = which.which(filename + ext,
path=self.getPossibleNodePathsWin())
if self.is_valid(nodeOrNpmPath):
return nodeOrNpmPath
except which.WhichError:
pass
else:
try:
return which.which(filename)
except which.WhichError:
pass
if filename == "node":
print(NODE_NOT_FOUND_MESSAGE)
elif filename == "npm":
print(NPM_NOT_FOUND_MESSAGE)
if platform.system() == "Windows":
appPaths = self.getPossibleNodePathsWin()
for p in appPaths:
print(" - %s" % p)
elif platform.system() == "Darwin":
print(" - /usr/local/bin/node")
elif platform.system() == "Linux":
print(" - /usr/bin/nodejs")
return None
开发者ID:brendandahl,项目名称:gecko-dev,代码行数:35,代码来源:mach_commands.py
示例6: eclipse
def eclipse(self, ide, args):
if ide == 'eclipse':
backend = 'CppEclipse'
elif ide == 'visualstudio':
backend = 'VisualStudio'
if ide == 'eclipse':
try:
which.which('eclipse')
except which.WhichError:
print('Eclipse CDT 8.4 or later must be installed in your PATH.')
print('Download: http://www.eclipse.org/cdt/downloads.php')
return 1
# Here we refresh the whole build. 'build export' is sufficient here and is probably more
# correct but it's also nice having a single target to get a fully built and indexed
# project (gives a easy target to use before go out to lunch).
res = self._mach_context.commands.dispatch('build', self._mach_context)
if res != 0:
return 1
# Generate or refresh the IDE backend.
python = self.virtualenv_manager.python_path
config_status = os.path.join(self.topobjdir, 'config.status')
args = [python, config_status, '--backend=%s' % backend]
res = self._run_command_in_objdir(args=args, pass_thru=True, ensure_exit_code=False)
if res != 0:
return 1
if ide == 'eclipse':
eclipse_workspace_dir = self.get_eclipse_workspace_path()
process = subprocess.check_call(['eclipse', '-data', eclipse_workspace_dir])
elif ide == 'visualstudio':
visual_studio_workspace_dir = self.get_visualstudio_workspace_path()
process = subprocess.check_call(['explorer.exe', visual_studio_workspace_dir])
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:35,代码来源:mach_commands.py
示例7: push_to_try
def push_to_try(self, msg, verbose):
if not self._use_git:
try:
hg_args = ['hg', 'push-to-try', '-m', msg]
subprocess.check_call(hg_args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print('ERROR hg command %s returned %s' % (hg_args, e.returncode))
print('\nmach failed to push to try. There may be a problem '
'with your ssh key, or another issue with your mercurial '
'installation.')
# Check for the presence of the "push-to-try" extension, and
# provide instructions if it can't be found.
try:
subprocess.check_output(['hg', 'showconfig',
'extensions.push-to-try'])
except subprocess.CalledProcessError:
print('\nThe "push-to-try" hg extension is required. It '
'can be installed to Mercurial 3.3 or above by '
'running ./mach mercurial-setup')
sys.exit(1)
else:
try:
which.which('git-cinnabar')
self._git_push_to_try(msg)
except which.WhichError:
print('ERROR git-cinnabar is required to push from git to try with'
'the autotry command.\n\nMore information can by found at '
'https://github.com/glandium/git-cinnabar')
sys.exit(1)
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:29,代码来源:autotry.py
示例8: has_command
def has_command(cmd):
from which import which, WhichError
try:
which(cmd)
return True
except WhichError as e:
return False
开发者ID:jeremygray,项目名称:pyperclip,代码行数:7,代码来源:pyperclip.py
示例9: mercurial_setup
def mercurial_setup(self, update_only=False):
"""Ensure Mercurial is optimally configured.
This command will inspect your Mercurial configuration and
guide you through an interactive wizard helping you configure
Mercurial for optimal use on Mozilla projects.
User choice is respected: no changes are made without explicit
confirmation from you.
If "--update-only" is used, the interactive wizard is disabled
and this command only ensures that remote repositories providing
Mercurial extensions are up to date.
"""
import which
import mozboot.bootstrap as bootstrap
# "hg" is an executable script with a shebang, which will be found
# be which.which. We need to pass a win32 executable to the function
# because we spawn a process
# from it.
if sys.platform in ("win32", "msys"):
hg = which.which("hg.exe")
else:
hg = which.which("hg")
if update_only:
bootstrap.update_vct(hg, self._context.state_dir)
else:
bootstrap.configure_mercurial(hg, self._context.state_dir)
开发者ID:carriercomm,项目名称:gecko-dev,代码行数:30,代码来源:mach_commands.py
示例10: run_test
def run_test(
self,
test_paths,
b2g_home=None,
busybox=None,
device_name=None,
test_objects=None,
log=None,
# ignore parameters from other platforms' options
**kwargs
):
try:
import which
which.which("adb")
except which.WhichError:
# TODO Find adb automatically if it isn't on the path
print(ADB_NOT_FOUND % ("mochitest-remote", b2g_home))
sys.exit(1)
test_path = None
if test_objects:
if len(test_objects) > 1:
print("Warning: Only the first test will be used.")
test_path = self._wrap_path_argument(test_objects[0]["path"])
elif test_paths:
if len(test_paths) > 1:
print("Warning: Only the first test path will be used.")
test_path = self._wrap_path_argument(test_paths[0]).relpath()
import runtestsb2g
parser = runtestsb2g.B2GOptions()
options, args = parser.parse_args([])
options.b2g_path = b2g_home
options.busybox = busybox or os.environ.get("BUSYBOX")
options.localLib = self.bin_dir
options.localBin = self.bin_dir
options.logdir = self.xpcshell_dir
options.manifest = os.path.join(self.xpcshell_dir, "xpcshell.ini")
options.mozInfo = os.path.join(self.topobjdir, "mozinfo.json")
options.objdir = self.topobjdir
options.symbolsPath = (os.path.join(self.distdir, "crashreporter-symbols"),)
options.testingModulesDir = os.path.join(self.tests_dir, "modules")
options.testsRootDir = self.xpcshell_dir
options.testPath = test_path
options.use_device_libs = True
options.emulator = "arm"
if device_name.startswith("emulator"):
if "x86" in device_name:
options.emulator = "x86"
if not options.busybox:
options.busybox = self._download_busybox(b2g_home, options.emulator)
return runtestsb2g.run_remote_xpcshell(parser, options, args, log)
开发者ID:yangkkokk,项目名称:gecko-dev,代码行数:60,代码来源:mach_commands.py
示例11: office_path
def office_path(self):
path = os.environ['PATH']
office = which('ooffice', path=path)
if not office:
office = which('soffice', path=path)
if not office:
raise KeyError("Cannot find OpenOffice on path")
return office[0]
开发者ID:winjer,项目名称:isotoma.openoffice,代码行数:8,代码来源:office.py
示例12: notify
def notify(self, msg):
"""Show a desktop notification with the supplied message
On Linux and Mac, this will show a desktop notification with the message,
but on Windows we can only flash the screen.
"""
moz_nospam = os.environ.get('MOZ_NOSPAM')
if moz_nospam:
return
try:
if sys.platform.startswith('darwin'):
try:
notifier = which.which('terminal-notifier')
except which.WhichError:
raise Exception('Install terminal-notifier to get '
'a notification when the build finishes.')
self.run_process([notifier, '-title',
'Mozilla Build System', '-group', 'mozbuild',
'-message', msg], ensure_exit_code=False)
elif sys.platform.startswith('linux'):
try:
notifier = which.which('notify-send')
except which.WhichError:
raise Exception('Install notify-send (usually part of '
'the libnotify package) to get a notification when '
'the build finishes.')
self.run_process([notifier, '--app-name=Mozilla Build System',
'Mozilla Build System', msg], ensure_exit_code=False)
elif sys.platform.startswith('win'):
from ctypes import Structure, windll, POINTER, sizeof
from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
class FLASHWINDOW(Structure):
_fields_ = [("cbSize", UINT),
("hwnd", HANDLE),
("dwFlags", DWORD),
("uCount", UINT),
("dwTimeout", DWORD)]
FlashWindowExProto = WINFUNCTYPE(BOOL, POINTER(FLASHWINDOW))
FlashWindowEx = FlashWindowExProto(("FlashWindowEx", windll.user32))
FLASHW_CAPTION = 0x01
FLASHW_TRAY = 0x02
FLASHW_TIMERNOFG = 0x0C
# GetConsoleWindows returns NULL if no console is attached. We
# can't flash nothing.
console = windll.kernel32.GetConsoleWindow()
if not console:
return
params = FLASHWINDOW(sizeof(FLASHWINDOW),
console,
FLASHW_CAPTION | FLASHW_TRAY | FLASHW_TIMERNOFG, 3, 0)
FlashWindowEx(params)
except Exception as e:
self.log(logging.WARNING, 'notifier-failed', {'error':
e.message}, 'Notification center failed: {error}')
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:57,代码来源:base.py
示例13: test_info
def test_info(self, **params):
import which
from mozbuild.base import MozbuildObject
self.branches = params['branches']
self.start = params['start']
self.end = params['end']
self.show_info = params['show_info']
self.show_results = params['show_results']
self.show_durations = params['show_durations']
self.show_bugs = params['show_bugs']
self.verbose = params['verbose']
if (not self.show_info and
not self.show_results and
not self.show_durations and
not self.show_bugs):
# by default, show everything
self.show_info = True
self.show_results = True
self.show_durations = True
self.show_bugs = True
here = os.path.abspath(os.path.dirname(__file__))
build_obj = MozbuildObject.from_environment(cwd=here)
self._hg = None
if conditions.is_hg(build_obj):
if self._is_windows():
self._hg = which.which('hg.exe')
else:
self._hg = which.which('hg')
self._git = None
if conditions.is_git(build_obj):
if self._is_windows():
self._git = which.which('git.exe')
else:
self._git = which.which('git')
for test_name in params['test_names']:
print("===== %s =====" % test_name)
self.test_name = test_name
if len(self.test_name) < 6:
print("'%s' is too short for a test name!" % self.test_name)
continue
if self.show_info:
self.set_test_name()
if self.show_results:
self.report_test_results()
if self.show_durations:
self.report_test_durations()
if self.show_bugs:
self.report_bugs()
开发者ID:luke-chang,项目名称:gecko-1,代码行数:55,代码来源:mach_commands.py
示例14: run_b2g_test
def run_b2g_test(self, context, tests=None, suite='mochitest', **kwargs):
"""Runs a b2g mochitest."""
if kwargs.get('desktop'):
kwargs['profile'] = kwargs.get('profile') or os.environ.get('GAIA_PROFILE')
if not kwargs['profile'] or not os.path.isdir(kwargs['profile']):
print(GAIA_PROFILE_NOT_FOUND)
sys.exit(1)
if os.path.isfile(os.path.join(kwargs['profile'], 'extensions',
'[email protected]')):
print(GAIA_PROFILE_IS_DEBUG.format(kwargs['profile']))
sys.exit(1)
elif context.target_out:
host_webapps_dir = os.path.join(context.target_out, 'data', 'local', 'webapps')
if not os.path.isdir(os.path.join(
host_webapps_dir, 'test-container.gaiamobile.org')):
print(ENG_BUILD_REQUIRED.format(host_webapps_dir))
sys.exit(1)
# TODO without os.chdir, chained imports fail below
os.chdir(self.mochitest_dir)
# The imp module can spew warnings if the modules below have
# already been imported, ignore them.
with warnings.catch_warnings():
warnings.simplefilter('ignore')
import imp
path = os.path.join(self.mochitest_dir, 'runtestsb2g.py')
with open(path, 'r') as fh:
imp.load_module('mochitest', fh, path,
('.py', 'r', imp.PY_SOURCE))
import mochitest
options = Namespace(**kwargs)
from manifestparser import TestManifest
if tests:
manifest = TestManifest()
manifest.tests.extend(tests)
options.manifestFile = manifest
if options.desktop:
return mochitest.run_desktop_mochitests(options)
try:
which.which('adb')
except which.WhichError:
# TODO Find adb automatically if it isn't on the path
print(ADB_NOT_FOUND.format(options.b2gPath))
return 1
return mochitest.run_remote_mochitests(options)
开发者ID:Jinwoo-Song,项目名称:gecko-dev,代码行数:54,代码来源:mach_commands.py
示例15: run_test
def run_test(self, **kwargs):
try:
import which
which.which('adb')
except which.WhichError:
# TODO Find adb automatically if it isn't on the path
print(ADB_NOT_FOUND % ('mochitest-remote', kwargs["b2g_home"]))
sys.exit(1)
import runtestsb2g
log = kwargs.pop("log")
self.log_manager.enable_unstructured()
if kwargs["xpcshell"] is None:
kwargs["xpcshell"] = "xpcshell"
if kwargs["b2g_path"] is None:
kwargs["b2g_path"] = kwargs["b2g_home"]
if kwargs["busybox"] is None:
kwargs["busybox"] = os.environ.get('BUSYBOX')
if kwargs["busybox"] is None:
kwargs["busybox"] = self._download_busybox(kwargs["b2g_home"], kwargs["emulator"])
if kwargs["localLib"] is None:
kwargs["localLib"] = self.bin_dir
if kwargs["localBin"] is None:
kwargs["localBin"] = self.bin_dir
if kwargs["logdir"] is None:
kwargs["logdir"] = self.xpcshell_dir
if kwargs["manifest"] is None:
kwargs["manifest"] = os.path.join(self.xpcshell_dir, 'xpcshell.ini')
if kwargs["mozInfo"] is None:
kwargs["mozInfo"] = os.path.join(self.topobjdir, 'mozinfo.json')
if kwargs["objdir"] is None:
kwargs["objdir"] = self.topobjdir
if kwargs["symbolsPath"] is None:
kwargs["symbolsPath"] = os.path.join(self.distdir, 'crashreporter-symbols')
if kwargs["testingModulesDir"] is None:
kwargs["testingModulesDir"] = os.path.join(self.tests_dir, 'modules')
if kwargs["use_device_libs"] is None:
kwargs["use_device_libs"] = True
if kwargs["device_name"].startswith('emulator') and 'x86' in kwargs["device_name"]:
kwargs["emulator"] = 'x86'
parser = parser_b2g()
options = argparse.Namespace(**kwargs)
rv = runtestsb2g.run_remote_xpcshell(parser, options, log)
self.log_manager.disable_unstructured()
return rv
开发者ID:npark-mozilla,项目名称:gecko-dev,代码行数:51,代码来源:mach_commands.py
示例16: _getP4D
def _getP4D():
try:
return which.which("p4d", path=[os.curdir])
except which.WhichError:
try:
return which.which("p4d")
except which.WhichError:
raise TestError(
"cannot not find a 'p4d' Perforce server binary "
"to use for testing. You must download one from "
"http://www.perforce.com/perforce/loadprog.html "
"to the current directory or to somewhere on "
"your PATH"
)
开发者ID:Tech-pandit,项目名称:python-p4lib,代码行数:14,代码来源:test.py
示例17: get_tool
def get_tool(config, key):
f = None
if key in config:
f = config[key]
if os.path.isabs(f):
if not os.path.exists(f):
raise ValueError("%s must point to an existing path" % key)
return f
# Assume that we have the name of some program that should be on PATH.
try:
return which.which(f) if f else which.which(key)
except which.WhichError:
raise ValueError("%s not found on PATH" % f)
开发者ID:bgrins,项目名称:gecko-dev,代码行数:14,代码来源:build-clang.py
示例18: _get_nodejs_version_from_env
def _get_nodejs_version_from_env(self, env=None):
import process
executable = env.get_pref("nodejsDefaultInterpreter", None)
if not executable:
import which
path = [d.strip()
for d in env.get_envvar("PATH", "").split(os.pathsep)
if d.strip()]
try:
executable = which.which("node", path=path)
except which.WhichError:
pass
if not executable:
return None
if not os.path.exists(executable):
log.info("Node.js executable %s does not exist", executable)
return None
p = process.ProcessOpen([executable, "--version"],
env=env.get_all_envvars(), stdin=None)
stdout, stderr = p.communicate()
if p.returncode != 0:
log.info("Failed to find Node.js version: %r: %s",
p.returncode, stderr)
return None # Failed to run
version = stdout.lstrip("v")
short_ver = ".".join(version.split(".", 2)[:2])
return short_ver
开发者ID:feimm,项目名称:KomodoEdit,代码行数:27,代码来源:lang_nodejs.py
示例19: check_program
def check_program():
"""Check dependencies."""
program_list = ['lastal, kraken, poretools']
for program in program_list:
if not which.which(program):
print(program + 'is not available')
sys.exit(1)
开发者ID:emilhaegglund,项目名称:master-thesis,代码行数:7,代码来源:mash_main.py
示例20: get_cargo_path
def get_cargo_path(self):
try:
return self.substs['CARGO']
except (BuildEnvironmentNotFoundException, KeyError):
# Default if this tree isn't configured.
import which
return which.which('cargo')
开发者ID:mykmelez,项目名称:spidernode,代码行数:7,代码来源:vendor_rust.py
注:本文中的which.which函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论