本文整理匯總了Python中distutils.spawn.find_executable方法的典型用法代碼示例。如果您正苦於以下問題:Python spawn.find_executable方法的具體用法?Python spawn.find_executable怎麽用?Python spawn.find_executable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類distutils.spawn
的用法示例。
在下文中一共展示了spawn.find_executable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: find_gae_path
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def find_gae_path():
global GAE_PATH
if GAE_PATH:
return GAE_PATH
if IS_WINDOWS:
gae_path = None
for path in os.environ['PATH'].split(os.pathsep):
if os.path.isfile(os.path.join(path, 'dev_appserver.py')):
gae_path = path
else:
gae_path = spawn.find_executable('dev_appserver.py')
if gae_path:
gae_path = os.path.dirname(os.path.realpath(gae_path))
if not gae_path:
return ''
gcloud_exec = 'gcloud.cmd' if IS_WINDOWS else 'gcloud'
if not os.path.isfile(os.path.join(gae_path, gcloud_exec)):
GAE_PATH = gae_path
else:
gae_path = os.path.join(gae_path, '..', 'platform', 'google_appengine')
if os.path.exists(gae_path):
GAE_PATH = os.path.realpath(gae_path)
return GAE_PATH
示例2: try_to_find_osquery
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def try_to_find_osquery(self):
extention = ""
if platform.system() == "Windows":
extention = ".exe"
try:
return resources.get_resource("osqueryi" + extention)
except IOError as e:
# Maybe it is installed on the system.
if platform.system() == "Windows":
result = r"c:\ProgramData\osquery\osqueryi.exe"
if os.access(result, os.R_OK):
return result
else:
# Try to find it somewhere on the system.
return spawn.find_executable("osqueryi")
raise e
示例3: tearDown
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def tearDown(self):
dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage')
if os.path.exists(dist_coverage_path):
# change ownership of coverage files
if find_executable('sudo'):
proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()),
dist_coverage_path], shell=False)
proc.wait()
# rewrite paths in coverage result files
for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')):
if 'COVERAGE_FILE' in os.environ:
new_cov_file = os.environ['COVERAGE_FILE'] \
+ os.path.basename(fn).replace('.coverage', '')
else:
new_cov_file = fn.replace('.dist-coverage' + os.sep, '')
shutil.copyfile(fn, new_cov_file)
shutil.rmtree(dist_coverage_path)
示例4: tearDown
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def tearDown(self):
time.sleep(5)
dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage')
if os.path.exists(dist_coverage_path):
# change ownership of coverage files
if find_executable('sudo'):
proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()),
dist_coverage_path], shell=False)
proc.wait()
# rewrite paths in coverage result files
for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')):
cov_db = sqlite3.connect(fn)
c = cov_db.cursor()
c.execute('UPDATE file SET path=REPLACE(path, \'%s\', \'\')' % (MARS_ROOT + os.path.sep))
cov_db.commit()
cov_db.close()
if 'COVERAGE_FILE' in os.environ:
new_cov_file = os.environ['COVERAGE_FILE'] \
+ os.path.basename(fn).replace('.coverage', '')
else:
new_cov_file = fn.replace('.dist-coverage' + os.sep, '')
shutil.copyfile(fn, new_cov_file)
shutil.rmtree(dist_coverage_path)
示例5: setbgcolor
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def setbgcolor(line, color):
# hack hack hack
# add a bgcolor attribute to all escape sequences found
import re
setbg = '\x1b[%sm' % color
regexbg = '\\1;%sm' % color
result = setbg + re.sub('(\x1b\\[.*?)m', regexbg, line) + '\x1b[00m'
if os.environ.get('TERM') == 'eterm-color':
# it seems that emacs' terminal has problems with some ANSI escape
# sequences. Eg, 'ESC[44m' sets the background color in all terminals
# I tried, but not in emacs. To set the background color, it needs to
# have also an explicit foreground color, e.g. 'ESC[37;44m'. These
# three lines are a hack, they try to add a foreground color to all
# escape sequences which are not recognized by emacs. However, we need
# to pick one specific fg color: I choose white (==37), but you might
# want to change it. These lines seems to work fine with the ANSI
# codes produced by pygments, but they are surely not a general
# solution.
result = result.replace(setbg, '\x1b[37;%dm' % color)
result = result.replace('\x1b[00;%dm' % color, '\x1b[37;%dm' % color)
result = result.replace('\x1b[39;49;00;', '\x1b[37;')
return result
示例6: _disable_pytest_capture_maybe
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def _disable_pytest_capture_maybe(self):
try:
import py.test
# Force raising of ImportError if pytest is not installed.
py.test.config
except (ImportError, AttributeError):
return
try:
capman = py.test.config.pluginmanager.getplugin('capturemanager')
capman.suspendcapture()
except KeyError:
pass
except AttributeError:
# Newer pytest with support ready, or very old py.test for which
# this hack does not work.
pass
示例7: _install_linecache_wrapper
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def _install_linecache_wrapper(self):
"""Disable linecache.checkcache to not invalidate caches.
This gets installed permanently to also bypass e.g. pytest using
`inspect.getsource`, which would invalidate it outside of the
interaction them.
"""
if not hasattr(self, "_orig_linecache_checkcache"):
import linecache
# Save it, although not used really (can be useful for debugging).
self._orig_linecache_checkcache = linecache.checkcache
def _linecache_checkcache(*args, **kwargs):
return
linecache.checkcache = _linecache_checkcache
示例8: do_track
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def do_track(self, arg):
"""
track expression
Display a graph showing which objects are referred by the
value of the expression. This command requires pypy to be in
the current PYTHONPATH.
"""
try:
from rpython.translator.tool.reftracker import track
except ImportError:
print('** cannot import pypy.translator.tool.reftracker **',
file=self.stdout)
return
try:
val = self._getval(arg)
except:
pass
else:
track(val)
示例9: _get_editor_cmd
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def _get_editor_cmd(self, filename, lineno):
editor = self.config.editor
if editor is None:
try:
editor = os.environ["EDITOR"]
except KeyError:
try:
from shutil import which
except ImportError:
from distutils.spawn import find_executable as which
editor = which("vim")
if editor is None:
editor = which("vi")
if not editor:
raise RuntimeError("Could not detect editor. Configure it or set $EDITOR.") # noqa: E501
return self._format_editcmd(editor, filename, lineno)
示例10: set_trace
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def set_trace(self, frame=None):
"""Remember starting frame.
This is used with pytest, which does not use pdb.set_trace().
"""
if getattr(local, "_pdbpp_completing", False):
# Handle set_trace being called during completion, e.g. with
# fancycompleter's attr_matches.
return
if self.disabled:
return
if frame is None:
frame = sys._getframe().f_back
self._via_set_trace_frame = frame
self._stopped_for_set_trace = False
self.start_filename = frame.f_code.co_filename
self.start_lineno = frame.f_lineno
return super(Pdb, self).set_trace(frame)
示例11: find_sdk_path
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def find_sdk_path():
"""Find the App Engine SDK path."""
if common.get_platform() == 'windows':
_, gcloud_path = common.execute('where gcloud.cmd', print_output=False)
else:
gcloud_path = spawn.find_executable('gcloud')
if not gcloud_path:
print('Please install the Google Cloud SDK and set up PATH to point to it.')
sys.exit(1)
cloud_sdk_path = os.path.dirname(
os.path.dirname(os.path.realpath(gcloud_path)))
appengine_sdk_path = os.path.join(cloud_sdk_path, 'platform',
'google_appengine')
if not os.path.exists(appengine_sdk_path):
print('App Engine SDK not found. Please run local/install_deps.bash')
sys.exit(1)
return appengine_sdk_path
示例12: get_command
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def get_command(self, additional_args=None):
"""Overridden get_command."""
if environment.platform() != 'LINUX':
raise RuntimeError('UnshareProcessRunner only supported on Linux')
unshare_path = spawn.find_executable('unshare')
if not unshare_path:
raise RuntimeError('unshare not found')
command = [unshare_path]
command.extend([
'-n', # Enter network namespace.
])
command.append(self._executable_path)
command.extend(self._default_args)
if additional_args:
command.extend(additional_args)
return command
示例13: check_executable
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def check_executable(executable):
"""
Checks if an executable exists in $PATH.
Arguments:
executable -- the name of the executable (e.g. "echo")
Returns:
True or False
"""
logger = logging.getLogger(__name__)
logger.debug("Checking executable '%s'...", executable)
executable_path = find_executable(executable)
found = executable_path is not None
if found:
logger.debug("Executable '%s' found: '%s'", executable,
executable_path)
else:
logger.debug("Executable '%s' not found", executable)
return found
示例14: _get_c_program
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def _get_c_program(self, makefile_target_name, binary_name):
"""build c program and return path to binary"""
find_executable(MAKE_CMD)
if not find_executable(MAKE_CMD):
print(
'Could not find executable "%s". Ensure it is installed and on your $PATH.'
% MAKE_CMD
)
exit(1)
SAMPLE_C_CODE_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "sample_c_app"
)
binary_path = os.path.join(SAMPLE_C_CODE_DIR, binary_name)
subprocess.call(["rm", "pygdbmi.a*"], cwd=SAMPLE_C_CODE_DIR)
# Build C program
subprocess.check_output(
[MAKE_CMD, makefile_target_name, "-C", SAMPLE_C_CODE_DIR, "--quiet"]
)
return binary_path
示例15: is_memcached_present
# 需要導入模塊: from distutils import spawn [as 別名]
# 或者: from distutils.spawn import find_executable [as 別名]
def is_memcached_present():
executable = find_executable('memcached')
return bool(executable)