[elbe-devel] [PATCH 02/11] elbe: Use ElbeCoverage

Olivier Dion dion at linutronix.de
Mon Aug 17 18:20:11 CEST 2020


When the environment variable ELBE_COVERAGE is set, it means that one
of ours ancestors asked coverage of Elbe.  Thus, enable coverage of
this process in that case.

This is done very early, i.e. before other importations so that the
coverage is maximized.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbe | 74 ++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 39 insertions(+), 35 deletions(-)

diff --git a/elbe b/elbe
index 76ab43a4..bdea70a3 100755
--- a/elbe
+++ b/elbe
@@ -10,53 +10,57 @@
 
 from __future__ import print_function
 
+import os
 import sys
 
-# We need to import elbepack.commands so that
-# elbepack/commands/__init__.py is run and the commands package is
-# register into the elbepack namespace.  This is later use by
-# get_cmd_list() and the magic stuff with __import__() at the end of
-# this file
-#
-# pylint: disable=unused-import
-import elbepack.commands
+from elbepack.cov import ElbeCoverage
+
+with ElbeCoverage(en_coverage=("ELBE_COVERAGE" in os.environ)):
 
-from elbepack.version import elbe_version
-from elbepack.directories import init_directories, get_cmdlist
+    # We need to import elbepack.commands so that
+    # elbepack/commands/__init__.py is run and the commands package is
+    # register into the elbepack namespace.  This is later use by
+    # get_cmd_list() and the magic stuff with __import__() at the end of
+    # this file
+    #
+    # pylint: disable=unused-import
+    import elbepack.commands
 
+    from elbepack.version import elbe_version
+    from elbepack.directories import init_directories, get_cmdlist
 
-def usage():
-    print("elbe v%s" % elbe_version)
-    print("need a subcommand: e.g. \'elbe initvm\'. \n\
-    Available subcommands are: \n")
-    for i in get_cmdlist():
-        print("        * %s" % i)
+    def usage():
+        print("elbe v%s" % elbe_version)
+        print("need a subcommand: e.g. \'elbe initvm\'. \n\
+        Available subcommands are: \n")
+        for i in get_cmdlist():
+            print("        * %s" % i)
 
-# First initialise the directories module
-# so that it knows, where the current elbe
-# executable can be found.
+    # First initialise the directories module
+    # so that it knows, where the current elbe
+    # executable can be found.
 
 
-init_directories(__file__)
+    init_directories(__file__)
 
-if len(sys.argv) < 2:
-    usage()
-    sys.exit(20)
+    if len(sys.argv) < 2:
+        usage()
+        sys.exit(20)
 
-if sys.argv[1] == "--version":
-    print("elbe v%s" % (elbe_version))
-    sys.exit(0)
+    if sys.argv[1] == "--version":
+        print("elbe v%s" % (elbe_version))
+        sys.exit(0)
 
-cmd_list = get_cmdlist()
+    cmd_list = get_cmdlist()
 
-if not sys.argv[1] in cmd_list:
-    print("Unknown subcommand !\n")
-    usage()
-    sys.exit(20)
+    if not sys.argv[1] in cmd_list:
+        print("Unknown subcommand !\n")
+        usage()
+        sys.exit(20)
 
-modname = "elbepack.commands." + sys.argv[1]
+    modname = "elbepack.commands." + sys.argv[1]
 
-mod = __import__(modname)
-cmdmod = sys.modules[modname]
+    mod = __import__(modname)
+    cmdmod = sys.modules[modname]
 
-cmdmod.run_command(sys.argv[2:])
+    cmdmod.run_command(sys.argv[2:])
-- 
2.28.0



More information about the elbe-devel mailing list