From 9e020c2782a653a5cc0aa9ec098f2ce8770b33fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 22 Feb 2017 10:09:39 +0100 Subject: [PATCH] ostree: Silence logger in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of creating and configuring the logger at module import time, we can only get the logger if it's actually needed and configure it from the main script. Signed-off-by: Lubomír Sedlář --- pungi/ostree/__init__.py | 4 ++++ pungi/ostree/utils.py | 13 ++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pungi/ostree/__init__.py b/pungi/ostree/__init__.py index 4a487bfd..e113137e 100644 --- a/pungi/ostree/__init__.py +++ b/pungi/ostree/__init__.py @@ -15,6 +15,7 @@ import argparse +import logging from .tree import Tree from .installer import Installer @@ -79,6 +80,9 @@ def main(args=None): help='JSON file contains extra configurations') args = parser.parse_args(args) + + logging.basicConfig(format="%(message)s", level=logging.DEBUG) + _class = args._class() _class.set_args(args) func = getattr(_class, args.func) diff --git a/pungi/ostree/utils.py b/pungi/ostree/utils.py index 3fe83f6a..930fbfba 100644 --- a/pungi/ostree/utils.py +++ b/pungi/ostree/utils.py @@ -23,13 +23,6 @@ import rpmUtils.arch from pungi.util import makedirs -ostree_utils_logger = logging.getLogger("ostree.utils") -handler = logging.StreamHandler() -handler.setFormatter(logging.Formatter("%(message)s")) -handler.setLevel(logging.DEBUG) -ostree_utils_logger.addHandler(handler) - - def make_log_file(log_dir, filename): """Return path to log file with given name, if log_dir is set.""" if not log_dir: @@ -38,11 +31,12 @@ def make_log_file(log_dir, filename): return os.path.join(log_dir, '%s.log' % filename) -def get_ref_from_treefile(treefile, arch=None, logger=ostree_utils_logger): +def get_ref_from_treefile(treefile, arch=None, logger=None): """ Return ref name by parsing the tree config file. Replacing ${basearch} with the basearch of the architecture we are running on or of the passed in arch. """ + logger = logger or logging.getLogger(__name__) ref = None if os.path.isfile(treefile): with open(treefile, 'r') as f: @@ -60,8 +54,9 @@ def get_ref_from_treefile(treefile, arch=None, logger=ostree_utils_logger): return ref -def get_commitid_from_commitid_file(commitid_file, logger=ostree_utils_logger): +def get_commitid_from_commitid_file(commitid_file, logger=None): """Return commit id which is read from the commitid file""" + logger = logger or logging.getLogger(__name__) commitid = None if os.path.isfile(commitid_file): with open(commitid_file, 'r') as f: