mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
a26b8e9930
Summary: Update most locations in edenfsctl to report the version number that was built into the edenfsctl binary at build time, rather than querying the RPM database for the installed RPM version. The RPM behavior only works on to RedHat-based Linux systems, and the currently running process doesn't necessarily have to have come from the RPM. The one place where we do still attempt to print the RPM version is in the `edenfsctl rage` report, when running on Linux. Reviewed By: wez Differential Revision: D21000168 fbshipit-source-id: 0fb747e71b6950d74f22c458efa0dfcbd45270bd
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
# pyre-strict
|
|
|
|
import subprocess
|
|
from typing import Optional, Tuple, cast
|
|
|
|
|
|
# returns (installed_version, release) tuple
|
|
def get_installed_eden_rpm_version_parts() -> Optional[Tuple[str, str]]:
|
|
fields = ("version", "release")
|
|
query_fmt = r"\n---\n".join(f"%{{{f}}}" for f in fields)
|
|
cmd = ["rpm", "-q", "fb-eden", "--queryformat", query_fmt]
|
|
proc = subprocess.run(cmd, stdout=subprocess.PIPE, encoding="utf-8")
|
|
if proc.returncode != 0:
|
|
return None
|
|
# pyre-fixme[22]: The cast is redundant.
|
|
parts = cast(str, proc.stdout).split("\n---\n")
|
|
assert len(parts) == 2, f"unexpected output: {proc.stdout!r}"
|
|
return (parts[0], parts[1])
|
|
|
|
|
|
def format_eden_version(parts: Optional[Tuple[str, str]]) -> str:
|
|
if parts is None:
|
|
return "<Not Installed>"
|
|
version = parts[0] or ""
|
|
release = parts[1] or ""
|
|
return f"{version}-{release}"
|
|
|
|
|
|
def get_installed_eden_rpm_version() -> str:
|
|
return format_eden_version(get_installed_eden_rpm_version_parts())
|
|
|
|
|
|
def get_current_version_parts() -> Tuple[str, str]:
|
|
"""Get a tuple containing (version, release) of the currently running code.
|
|
|
|
The version and release strings will both be the empty string if this code is part
|
|
of a development build that is not a released package.
|
|
"""
|
|
import eden.config
|
|
|
|
return (eden.config.VERSION, eden.config.RELEASE)
|
|
|
|
|
|
def get_current_version() -> str:
|
|
"""Get a human-readable string describing the version of the currently running code.
|
|
|
|
Returns "-" when running a development build that is not part of an official
|
|
versioned release.
|
|
"""
|
|
return format_eden_version(get_current_version_parts())
|