From dfbfc0f2613bf746948da871e3aa0ec054f6bd4f Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Fri, 16 Jun 2017 11:08:23 +0100 Subject: Add "debug" and "quiet" flags These flags aim to control the logging level [1] of virt-bootstrap. Default = INFO (Confirmation that things are working as expected) --debug = DEBUG (Detailed information, typically of interest only when diagnosing problems) --quiet = WARNING (An indication that something unexpected happened, or indicative of some problem in the near future) [1] https://docs.python.org/3/howto/logging.html --- src/virtBootstrap/virt_bootstrap.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/virtBootstrap/virt_bootstrap.py b/src/virtBootstrap/virt_bootstrap.py index 3973720..2ee505e 100755 --- a/src/virtBootstrap/virt_bootstrap.py +++ b/src/virtBootstrap/virt_bootstrap.py @@ -26,6 +26,7 @@ import gettext import sys import os from textwrap import dedent +from logging import getLogger, DEBUG, INFO, WARNING from subprocess import CalledProcessError, Popen, PIPE try: from urlparse import urlparse @@ -85,6 +86,10 @@ def bootstrap(args): """ Get source object and call unpack method """ + # Set log level + logger = getLogger() + logger.setLevel(DEBUG if args.debug else WARNING if args.quiet else INFO) + source = get_source(args) if not os.path.exists(args.dest): os.makedirs(args.dest) @@ -128,6 +133,11 @@ def main(): parser.add_argument("-f", "--format", default='dir', choices=['dir', 'qcow2'], help=_("Format to be used for the root filesystem")) + parser.add_argument("-d", "--debug", action="store_true", + help=_("Show debug messages")) + parser.add_argument("-q", "--quiet", action="store_true", + help=_("Suppresses messages notifying about" + "current state or actions of virt-bootstrap")) # TODO add UID / GID mapping parameters try: -- cgit