本文整理匯總了Python中whichcraft.which方法的典型用法代碼示例。如果您正苦於以下問題:Python whichcraft.which方法的具體用法?Python whichcraft.which怎麽用?Python whichcraft.which使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whichcraft
的用法示例。
在下文中一共展示了whichcraft.which方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_binary
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def get_binary(name):
binaries_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'bin'))
exe = None
installed_exe = which(name)
if installed_exe and os.path.isfile(installed_exe):
return installed_exe
else:
if platform.system() == "Windows": # Windows
exe = os.path.abspath(os.path.join(binaries_dir, "Windows", "i386", name, "%s.exe" % name))
elif platform.system() == "Darwin": # MacOSX
exe = os.path.abspath(os.path.join(binaries_dir, "MacOSX", "i386", name, name))
elif platform.system() == "Linux": # Linux
exe = os.path.abspath(os.path.join(binaries_dir, "Linux", platform.machine(), name, name))
if exe and os.path.isfile(exe):
return exe
示例2: run_flask
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def run_flask(self):
"""
Run flask or other framework specified
"""
if isinstance(self.server, str):
if self.server.lower() == "flask":
if self.socketio:
self.socketio.run(self.flask_app, host=self.host, port=self.port)
else:
self.flask_app.run(host=self.host, port=self.port)
elif self.server.lower() == "django":
if sys.platform in ['win32', 'win64']:
os.system("python manage.py runserver {}:{}".format(self.host, self.port))
else:
os.system("python3 manage.py runserver {}:{}".format(self.host, self.port))
else:
raise Exception("{} must be a function which starts the webframework server!".format(self.server))
else:
self.server()
示例3: find_chrome_linux
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def find_chrome_linux(self):
try:
import whichcraft as wch
except:
raise Exception("whichcraft module is not installed/found \
please fill browser_path parameter or install whichcraft!")
chrome_names = ['chromium-browser',
'chromium',
'google-chrome',
'google-chrome-stable']
for name in chrome_names:
chrome = wch.which(name)
if chrome is not None:
return chrome
return None
示例4: run
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def run(self):
if which("mongod"):
cwd = os.path.join(os.path.dirname(__file__), "..", "..")
dbpath = os.path.join("/", "data", "db")
if not os.path.exists(dbpath):
dbpath = os.path.join(cwd, "db")
logpath = os.path.join(dbpath, "mongodb-mpcontribs.log")
call(["mongod", "--dbpath", dbpath, "--logpath", logpath, "--logappend"])
print("mongod started.")
else:
print("install MongoDB to use local DB instance.")
示例5: find_path
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def find_path():
if sys.platform in ['win32', 'win64']:
# It doesn't work well passing the .bat file to Popen, so we get the actual .exe
bat_path = wch.which('electron')
return os.path.join(bat_path, r'..\node_modules\electron\dist\electron.exe')
elif sys.platform in ['darwin', 'linux']:
# This should work find...
return wch.which('electron')
else:
return None
示例6: _find_chrome_linux
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def _find_chrome_linux():
import whichcraft as wch
chrome_names = ['chromium-browser',
'chromium',
'google-chrome',
'google-chrome-stable']
for name in chrome_names:
chrome = wch.which(name)
if chrome is not None:
return chrome
return None
示例7: get_adb_exe
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def get_adb_exe():
# 1. find in $PATH
exe = whichcraft.which("adb")
if exe and _is_valid_exe(exe):
return exe
# 2. use buildin adb
bin_dir = resource_filename("adbutils", "binaries")
exe = os.path.join(bin_dir, "adb.exe" if os.name == 'nt' else 'adb')
if os.path.isfile(exe) and _is_valid_exe(exe):
return exe
raise RuntimeError("No adb exe could be found. Install adb on your system")
示例8: test_existing_linux
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def test_existing_linux():
cmd = which("date")
assert cmd
assert os.path.exists(cmd)
assert os.access(cmd, os.F_OK | os.X_OK)
assert not os.path.isdir(cmd)
示例9: test_non_existing_command
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def test_non_existing_command():
assert which("stringthatisntashellcommand") is None
示例10: test_existing_windows
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def test_existing_windows():
cmd = which("cmd")
assert cmd
assert os.path.exists(cmd)
assert os.access(cmd, os.F_OK | os.X_OK)
assert not os.path.isdir(cmd)
示例11: forward_ports
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def forward_ports(remote_host, local_host, local_listen_ports,
remote_listen_ports):
"""Forwards ports such that multiplayer works between machines.
Args:
remote_host: Where to ssh to.
local_host: "127.0.0.1" or "::1".
local_listen_ports: Which ports to listen on locally to forward remotely.
remote_listen_ports: Which ports to listen on remotely to forward locally.
Returns:
The ssh process.
Raises:
ValueError: if it can't find ssh.
"""
if ":" in local_host and not local_host.startswith("["):
local_host = "[%s]" % local_host
ssh = whichcraft.which("ssh") or whichcraft.which("plink")
if not ssh:
raise ValueError("Couldn't find an ssh client.")
args = [ssh, remote_host]
for local_port in local_listen_ports:
args += ["-L", "%s:%s:%s:%s" % (local_host, local_port,
local_host, local_port)]
for remote_port in remote_listen_ports:
args += ["-R", "%s:%s:%s:%s" % (local_host, remote_port,
local_host, remote_port)]
logging.info("SSH port forwarding: %s", " ".join(args))
return subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, close_fds=(os.name == "posix"))
示例12: check_failed_dockerfile
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def check_failed_dockerfile(scripts, lines_required=None):
npm_bin = which('npm')
npm_bin_path = subprocess.check_output([npm_bin, 'bin']).\
decode('UTF-8').strip('\n') if npm_bin else ""
npm_bin_path_g = subprocess.check_output([npm_bin, 'bin', '-g']).\
decode('UTF-8').strip('\n') if npm_bin else ""
lint_bin_name = 'dockerfile_lint'
lint_bin = which(lint_bin_name) or \
which(lint_bin_name, path=npm_bin_path + os.pathsep + npm_bin_path_g)
assert lint_bin, "'%s' not found." % lint_bin_name
for script in scripts:
fname_dkr = os.path.join(script, 'Dockerfile')
pipe = subprocess.Popen([lint_bin, "-f", fname_dkr],
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE)
output = pipe.stdout.read().decode('utf-8')
assert 'Check passed' in output, fname_dkr
print("Check dockerfile output", output)
if not lines_required:
continue
with open(fname_dkr) as fdkr:
fdkr_lines = fdkr.readlines()
fdkr_lines[-1] = fdkr_lines[-1].strip('\n') + '\n'
for line_required in lines_required:
assert line_required + '\n' in fdkr_lines
print(fdkr_lines)
示例13: __init__
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def __init__(self, meka_classifier=None, weka_classifier=None,
java_command=None, meka_classpath=None):
super(Meka, self).__init__()
self.java_command = java_command
if self.java_command is None:
# TODO: this will not be needed once we're python 3 ready - we will
# use it only in python 2.7 cases
from whichcraft import which
self.java_command = which("java")
if self.java_command is None:
raise ValueError("Java not found")
self.meka_classpath = meka_classpath
if self.meka_classpath is None:
self.meka_classpath = os.environ.get('MEKA_CLASSPATH')
if self.meka_classpath is None:
raise ValueError("No meka classpath defined")
self.meka_classifier = meka_classifier
self.weka_classifier = weka_classifier
self.copyable_attrs = [
'meka_classifier',
'weka_classifier',
'java_command',
'meka_classpath'
]
self.output_ = None
self._verbosity = 5
self._warnings = None
self.require_dense = [False, False]
self._clean()
示例14: find_chrome_linux
# 需要導入模塊: import whichcraft [as 別名]
# 或者: from whichcraft import which [as 別名]
def find_chrome_linux(self):
import whichcraft as wch
chrome_names = ['chromium-browser',
'chromium',
'google-chrome',
'google-chrome-stable']
for name in chrome_names:
chrome = wch.which(name)
if chrome is not None:
return chrome
return None