本文整理汇总了Python中subprocutils.check_output函数的典型用法代码示例。如果您正苦于以下问题:Python check_output函数的具体用法?Python check_output怎么用?Python check_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_output函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _is_buckd_running
def _is_buckd_running(self):
with Tracing('BuckRepo._is_buckd_running'):
buckd_socket_path = self._buck_project.get_buckd_socket_path()
if not os.path.exists(buckd_socket_path):
return False
buck_client_file = self._get_resource(CLIENT)
command = [buck_client_file]
command.append('ng-stats')
command.append('--nailgun-server')
command.append('local:.buckd/sock')
try:
check_output(
command,
cwd=self._buck_project.root,
stderr=subprocess.STDOUT)
except CalledProcessError as e:
if e.returncode == NAILGUN_CONNECTION_REFUSED_CODE:
return False
else:
print(e.output, end='', file=sys.stderr)
raise
return True
示例2: get_dirty_buck_version
def get_dirty_buck_version(dirpath):
git_tree_in = check_output(
['git', 'log', '-n1', '--pretty=format:%T', 'HEAD', '--'],
cwd=dirpath).strip()
with EmptyTempFile(prefix='buck-git-index') as index_file:
new_environ = os.environ.copy()
new_environ['GIT_INDEX_FILE'] = index_file.name
subprocess.check_call(
['git', 'read-tree', git_tree_in],
cwd=dirpath,
env=new_environ)
subprocess.check_call(
['git', 'add', '-A'],
cwd=dirpath,
env=new_environ)
git_tree_out = check_output(
['git', 'write-tree'],
cwd=dirpath,
env=new_environ).strip()
with EmptyTempFile(prefix='buck-version-uid-input',
closed=False) as uid_input:
subprocess.check_call(
['git', 'ls-tree', '--full-tree', git_tree_out],
cwd=dirpath,
stdout=uid_input)
return check_output(
['git', 'hash-object', uid_input.name],
cwd=dirpath).strip()
示例3: _setup_watchman_watch
def _setup_watchman_watch(self):
with Tracing('BuckRepo._setup_watchman_watch'):
if not which('watchman'):
message = textwrap.dedent("""\
Watchman not found, please install when using buckd.
See https://github.com/facebook/watchman for details.""")
if sys.platform == "darwin":
message += "\n(brew install watchman on OS X)"
# Bail if watchman isn't installed as we know java's
# FileSystemWatcher will take too long to process events.
raise BuckToolException(message)
print("Using watchman.", file=sys.stderr)
try:
# Check watchman version
# We only want to use watch-project in watchman >= 3.4,
# since early versions don't return the project path relative to
# the repo root.
if self._watchman_atleast(3, 4):
response = check_output(
['watchman', 'watch-project', self._buck_project.root],
stderr=subprocess.STDOUT)
else:
response = check_output(
['watchman', 'watch', self._buck_project.root],
stderr=subprocess.STDOUT)
jsonresp = json.loads(response)
root = jsonresp.get("watch", self._buck_project.root)
relative_path = jsonresp.get('relative_path')
return root, relative_path
except CalledProcessError as e:
print(e.output, end='', file=sys.stderr)
raise
示例4: kill_buckd
def kill_buckd(self):
with Tracing('BuckRepo.kill_buckd'):
buckd_port = self._buck_project.get_buckd_port()
if buckd_port:
if not buckd_port.isdigit():
print("WARNING: Corrupt buckd port: '{0}'.".format(buckd_port))
else:
print("Shutting down nailgun server...", file=sys.stderr)
buck_client_file = self._get_resource(CLIENT)
command = [buck_client_file]
command.append('ng-stop')
command.append('--nailgun-port')
command.append(buckd_port)
try:
check_output(
command,
cwd=self._buck_project.root,
stderr=subprocess.STDOUT)
except CalledProcessError as e:
if (e.returncode not in
[NAILGUN_CONNECTION_REFUSED_CODE,
NAILGUN_CONNECTION_BROKEN_CODE,
NAILGUN_UNEXPECTED_CHUNK_TYPE]):
print(e.output, end='', file=sys.stderr)
raise
self._buck_project.clean_up_buckd()
示例5: _is_buckd_running
def _is_buckd_running(self):
with Tracing('BuckRepo._is_buckd_running'):
buckd_port = self._buck_project.get_buckd_port()
if buckd_port is None or not buckd_port.isdigit():
return False
buck_client_file = self._get_resource(CLIENT)
command = [buck_client_file]
command.append('ng-stats')
command.append('--nailgun-port')
command.append(buckd_port)
try:
check_output(
command,
cwd=self._buck_project.root,
stderr=subprocess.STDOUT)
except CalledProcessError as e:
if e.returncode == NAILGUN_CONNECTION_REFUSED_CODE:
return False
else:
print(e.output, end='', file=sys.stderr)
raise
return True
示例6: get_dirty_buck_version
def get_dirty_buck_version(dirpath):
git_tree_in = check_output(["git", "log", "-n1", "--pretty=format:%T", "HEAD", "--"], cwd=dirpath).strip()
with EmptyTempFile(prefix="buck-git-index") as index_file:
new_environ = os.environ.copy()
new_environ["GIT_INDEX_FILE"] = index_file.name
subprocess.check_call(["git", "read-tree", git_tree_in], cwd=dirpath, env=new_environ)
subprocess.check_call(["git", "add", "-A"], cwd=dirpath, env=new_environ)
git_tree_out = check_output(["git", "write-tree"], cwd=dirpath, env=new_environ).strip()
with EmptyTempFile(prefix="buck-version-uid-input", closed=False) as uid_input:
subprocess.check_call(["git", "ls-tree", "--full-tree", git_tree_out], cwd=dirpath, stdout=uid_input)
return check_output(["git", "hash-object", uid_input.name], cwd=dirpath).strip()
示例7: _has_local_changes
def _has_local_changes(self):
if not self.is_git:
return False
output = check_output(
['git', 'ls-files', '-m'],
cwd=self.buck_dir)
return bool(output.strip())
示例8: is_git
def is_git(dirpath):
dot_git = os.path.join(dirpath, ".git")
if which("git") and sys.platform != "cygwin":
if os.path.exists(dot_git) and os.path.isdir(dot_git):
return True
output = check_output(["git", "rev-parse", "--is-inside-work-tree"], cwd=dirpath)
return output.strip() == "true"
return False
示例9: is_java8
def is_java8():
try:
output = check_output(['java', '-version'], stderr=subprocess.STDOUT)
version_line = output.strip().splitlines()[0]
return re.compile('(openjdk|java) version "1\.8\..*').match(version_line)
except CalledProcessError as e:
print(e.output, file=sys.stderr)
raise e
示例10: _watchman_atleast
def _watchman_atleast(self, major, minor):
"""Returns true if the installed watchman is greater than or equal to
the given version."""
response = check_output(['watchman', 'version'])
version = json.loads(response).get("version")
parts = version.split('.')
actualmajor = int(parts[0])
actualminor = int(parts[1])
return actualmajor > major or (actualmajor == major and
actualminor >= minor)
示例11: _setup_watchman_watch
def _setup_watchman_watch(self):
with Tracing('BuckRepo._setup_watchman_watch'):
if not which('watchman'):
message = textwrap.dedent("""\
Watchman not found, please install when using buckd.
See https://github.com/facebook/watchman for details.""")
if sys.platform == "darwin":
message += "\n(brew install watchman on OS X)"
# Bail if watchman isn't installed as we know java's
# FileSystemWatcher will take too long to process events.
raise BuckToolException(message)
print("Using watchman.", file=sys.stderr)
try:
check_output(
['watchman', 'watch', self._buck_project.root],
stderr=subprocess.STDOUT)
except CalledProcessError as e:
print(e.output, end='', file=sys.stderr)
raise
示例12: is_dirty
def is_dirty(dirpath):
# Ignore any changes under these paths for the purposes of forcing a rebuild
# of Buck itself.
IGNORE_PATHS = ["test"]
IGNORE_PATHS_RE_GROUP = "|".join([re.escape(e) for e in IGNORE_PATHS])
IGNORE_PATHS_RE = re.compile("^.. (?:" + IGNORE_PATHS_RE_GROUP + ")")
if not is_git(dirpath):
return False
output = check_output(["git", "status", "--porcelain"], cwd=dirpath)
output = "\n".join([line for line in output.splitlines() if not IGNORE_PATHS_RE.search(line)])
return bool(output.strip())
示例13: _get_java_version
def _get_java_version():
"""
Returns a Java version string (e.g. "7", "8").
Information is provided by java tool and parsing is based on
http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
"""
java_version = check_output(["java", "-version"], stderr=subprocess.STDOUT)
# extract java version from a string like 'java version "1.8.0_144"'
match = re.search("java version \"(?P<version>.+)\"", java_version)
if not match:
return None
return match.group("version").split(".")[1]
示例14: is_java8
def is_java8():
global _java8
if _java8 is not None:
return _java8
try:
output = check_output(['java', '-version'], stderr=subprocess.STDOUT)
version_line = output.strip().splitlines()[0]
m = re.compile('(openjdk|java) version "1\.8\..*').match(version_line)
_java8 = bool(m)
return _java8
except CalledProcessError as e:
print(e.output, file=sys.stderr)
raise e
示例15: is_java8_or_9
def is_java8_or_9():
global _java8_or_9
if _java8_or_9 is not None:
return _java8_or_9
try:
cmd = ["java", "-Xms64m", "-version"]
output = check_output(cmd, stderr=subprocess.STDOUT)
version_line = output.strip().splitlines()[0]
m = re.compile('(openjdk|java) version "(1\.(8|9)\.|9).*').match(version_line)
_java8_or_9 = bool(m)
return _java8_or_9
except CalledProcessError as e:
print(e.output, file=sys.stderr)
raise e