sversion: leverage inside servod
Now that sversion.py & util exist to extract the servod version,
leverage those inside servod by
- unifying the --version command-line argument around that version
- introducing --sversion, which prints more details to debug
They are split because neither hashes nor normal strings etc are python
version string compliant.
BUG=chromium:1063519
TEST=servod --version
servod v0.9999.0.dev
TEST=servod --sversion
servod v0.9999.0.dev-a64ec7d
2020-03-20 13:52:28
cococave.mtv.corp.google.com
TEST=dut-control --sversion
dut-control v0.9999.0.dev-a64ec7d
2020-03-20 13:52:28
cococave.mtv.corp.google.com
Change-Id: I888c192da8a7652a0c68dc5d645550a07162f6a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/hdctools/+/2113733
Reviewed-by: Todd Broch <tbroch@chromium.org>
Tested-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Commit-Queue: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
diff --git a/servo/servo_parsing.py b/servo/servo_parsing.py
index 43ae931..5dba2ae 100644
--- a/servo/servo_parsing.py
+++ b/servo/servo_parsing.py
@@ -10,6 +10,7 @@
import client
import servo_logging
+import sversion_util
import utils.scratch
@@ -18,7 +19,7 @@
#
# _BaseServodParser: ArgumentParser with pretty-formatting for example list
#
-# BaseServodParser: adds common args: port, host, and debug
+# BaseServodParser: adds common args: port, host, version, and debug
#
# ServodRCParser: adds -name/-rcfile & overwrites parsing logic so that
# rc parsing & configuration is handled internally
@@ -79,6 +80,11 @@
ARG_BY_USER_MARKER = 'supplied_by_user'
+# Keep track of both the 'version' according to PEP440 and 'sversion' our
+# internal version system, and provide arguments to print those.
+VERSION = '%(prog)s ' + sversion_util.setuptools_version()
+SVERSION = '%(prog)s ' + sversion_util.extended_version()
+
def ArgMarkedAsUserSupplied(namespace, arg_name):
"""Query whether an argument that uses StoreAndMarkAction is user supplied."""
@@ -193,7 +199,10 @@
or to create mutual exclusion with serialname and name (clients)
**kwargs: keyword arguments forwarded to _BaseServodParser
"""
+ if 'version' not in kwargs:
+ kwargs['version'] = VERSION
super(BaseServodParser, self).__init__(**kwargs)
+ self.add_argument('--sversion', action='version', version=SVERSION)
self.add_argument('-d', '--debug', action='store_true', default=False,
help='enable debug messages')
self.add_argument('--host', default='localhost', type=str,