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/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."""