Acloud: print version info.
acloud 2020.02.24 for local build, 2020.02.24 is "%y.%m.%d".
acloud 6230294 for formal build, 6230294 is build id.
Bug: 149841073
Test: acloud --version
acloud list -v
acloud {sub_args} -v or -vv
Change-Id: I28d73fe02832557d09e913b7cd86b1f148eb10e3
diff --git a/Android.bp b/Android.bp
index fb9f40e..b211ee7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -39,6 +39,7 @@
],
data: [
"public/data/default.config",
+ ":acloud_version",
],
libs: [
"acloud_create",
@@ -198,3 +199,10 @@
"asuite_metrics",
],
}
+
+genrule {
+ name: "acloud_version",
+ tool_files: ["gen_version.sh"],
+ cmd: "$(location gen_version.sh) $(out)",
+ out: ["public/data/VERSION"],
+}
diff --git a/gen_version.sh b/gen_version.sh
new file mode 100755
index 0000000..c079611
--- /dev/null
+++ b/gen_version.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+OUTFILE="$1"
+if [[ -n $BUILD_NUMBER ]]; then
+ echo ${BUILD_NUMBER} > ${OUTFILE}
+else
+ DATETIME=$(TZ='UTC' date +'%Y.%m.%d')
+ echo ${DATETIME}_local_build > ${OUTFILE}
+fi
diff --git a/public/acloud_main.py b/public/acloud_main.py
index a483348..94ffe0f 100644
--- a/public/acloud_main.py
+++ b/public/acloud_main.py
@@ -128,6 +128,7 @@
LOGGING_FMT = "%(asctime)s |%(levelname)s| %(module)s:%(lineno)s| %(message)s"
ACLOUD_LOGGER = "acloud"
NO_ERROR_MESSAGE = ""
+PROG = "acloud"
# Commands
CMD_CREATE_CUTTLEFISH = "create_cf"
@@ -156,6 +157,9 @@
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
usage="acloud {" + usage + "} ...")
+ parser = argparse.ArgumentParser(prog=PROG)
+ parser.add_argument('--version', action='version', version=(
+ '%(prog)s ' + config.GetVersion()))
subparsers = parser.add_subparsers(metavar="{" + usage + "}")
subparser_list = []
@@ -347,6 +351,9 @@
_SetupLogging(args.log_file, args.verbose)
_VerifyArgs(args)
+ if args.verbose:
+ print("%s %s" % (PROG, config.GetVersion()))
+
cfg = config.GetAcloudConfig(args)
# TODO: Move this check into the functions it is actually needed.
# Check access.
diff --git a/public/config.py b/public/config.py
index d538230..3c1fa19 100755
--- a/public/config.py
+++ b/public/config.py
@@ -64,6 +64,26 @@
os.path.dirname(os.path.abspath(__file__)), "data")
_DEFAULT_CONFIG_FILE = "acloud.config"
+# VERSION
+_VERSION_FILE = "VERSION"
+_UNKNOWN = "UNKNOWN"
+
+
+def GetVersion():
+ """Print the version of acloud.
+
+ The VERSION file is built into the acloud binary. The version file path is
+ under "public/data".
+
+ Returns:
+ String of the acloud version.
+ """
+ version_file_path = os.path.join(_CONFIG_DATA_PATH, _VERSION_FILE)
+ if os.path.exists(version_file_path):
+ with open(version_file_path) as version_file:
+ return version_file.read()
+ return _UNKNOWN
+
def GetDefaultConfigFile():
"""Return path to default config file."""