Files
react-native-devtools-frontend/scripts/utils.py
T
Blink Reformat 4c46d0969f The Great Blink mv for source files, part 2.
Move and rename files.

NOAUTOREVERT=true
NOPRESUBMIT=true
NOTREECHECKS=true
Bug: 768828
TBR=darin@chromium.org
NOTRY=true

Change-Id: I66d3b155808bc5bdbf237b80208e1e552bcf7f28
Reviewed-on: https://chromium-review.googlesource.com/1001153
Reviewed-by: Blink Reformat <blink-reformat@chromium.org>
Commit-Queue: Blink Reformat <blink-reformat@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#549061}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0aee4434a4dba42a42abaea9bfbc0cd196a63bc1
2018-04-07 15:32:37 +00:00

44 lines
1.3 KiB
Python

# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
from os import path
import sys
# Based on http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python.
def which(program):
def is_executable(fpath):
return path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = path.split(program)
if fpath:
if is_executable(program):
return program
return None
env_paths = os.environ["PATH"].split(os.pathsep)
if sys.platform == "win32":
env_paths = get_windows_path(env_paths)
for part in env_paths:
part = part.strip('\"')
file = path.join(part, program)
if is_executable(file):
return file
if sys.platform == "win32" and not file.endswith(".exe"):
file_exe = file + ".exe"
if is_executable(file_exe):
return file_exe
return None
# Use to find 64-bit programs (e.g. Java) when using 32-bit python in Windows
def get_windows_path(env_paths):
new_env_paths = env_paths[:]
for env_path in env_paths:
env_path = env_path.lower()
if "system32" in env_path:
new_env_paths.append(env_path.replace("system32", "sysnative"))
return new_env_paths