sapling/eden/cli/version.py
Adam Simpkins 65bd6dea07 rename the CLI's "Config" class to "EdenInstance"
Summary:
In the CLI, rename the "Config" class to "EdenInstance".  This class
represents all state about a particular edenfs instance.  It provides APIs for
making thrift calls to edenfs, for creating and destroying checkouts, and
generally does much more than just managing configuration.

Renaming it to "EdenInstance" also helps clarify that it is distinct from the
configuration tracked in the user's ~/.edenrc and the /etc/eden directory.

This change purely renames internal class and variable names and should not
affect any user-visible functionality.

Reviewed By: wez

Differential Revision: D9355515

fbshipit-source-id: ba5d4c3b753c6eb12a3783306dcd29e85fea3f52
2018-08-15 21:36:18 -07:00

46 lines
1.4 KiB
Python

#!/usr/bin/env python3
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
import subprocess
from typing import Optional, Tuple, cast
from .config import EdenInstance
def get_installed_eden_rpm_version() -> str:
proc = subprocess.run(
["rpm", "-q", "fb-eden", "--queryformat", "%{version}-%{release}"],
stdout=subprocess.PIPE,
encoding="utf-8",
)
if proc.returncode != 0:
return "<Not Installed>"
return cast(str, proc.stdout)
# returns (runing_version, release) tuple
def get_running_eden_version_parts(
instance: EdenInstance
) -> Tuple[Optional[str], Optional[str]]:
bi = instance.get_server_build_info()
return (bi.get("build_package_version"), bi.get("build_package_release"))
def format_running_eden_version(parts: Tuple[Optional[str], Optional[str]]) -> str:
running_version, release = parts
if running_version is None:
running_version = ""
if release is None:
release = ""
return f"{running_version}-{release}"
def get_running_eden_version(instance: EdenInstance) -> str:
return format_running_eden_version(get_running_eden_version_parts(instance))