Add --quiet option to pungi-koji

log will not be printed to screen when quiet mode is enabled.

Signed-off-by: Qixiang Wan <qwan@redhat.com>
This commit is contained in:
Qixiang Wan 2017-02-17 13:28:30 -06:00
parent d496eeb090
commit a57bc13e30
3 changed files with 25 additions and 8 deletions

View File

@ -133,6 +133,12 @@ def main():
dest="no_latest_link", dest="no_latest_link",
help="don't create latest symbol link to this compose" help="don't create latest symbol link to this compose"
) )
parser.add_option(
"--quiet",
action="store_true",
default=False,
help="quiet mode, don't print log on screen"
)
opts, args = parser.parse_args() opts, args = parser.parse_args()
import pungi.notifier import pungi.notifier
@ -190,7 +196,8 @@ def main():
logger = logging.getLogger("Pungi") logger = logging.getLogger("Pungi")
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
kobo.log.add_stderr_logger(logger) if not opts.quiet:
kobo.log.add_stderr_logger(logger)
conf = kobo.conf.PyConfigParser() conf = kobo.conf.PyConfigParser()
conf.load_from_file(opts.config) conf.load_from_file(opts.config)

View File

@ -16,12 +16,20 @@
import datetime import datetime
import json import json
import logging
import os import os
import rpmUtils.arch import rpmUtils.arch
from pungi.util import makedirs 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): def make_log_file(log_dir, filename):
"""Return path to log file with given name, if log_dir is set.""" """Return path to log file with given name, if log_dir is set."""
if not log_dir: if not log_dir:
@ -30,7 +38,7 @@ def make_log_file(log_dir, filename):
return os.path.join(log_dir, '%s.log' % filename) return os.path.join(log_dir, '%s.log' % filename)
def get_ref_from_treefile(treefile, arch=None): def get_ref_from_treefile(treefile, arch=None, logger=ostree_utils_logger):
""" """
Return ref name by parsing the tree config file. Replacing ${basearch} with 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. the basearch of the architecture we are running on or of the passed in arch.
@ -46,20 +54,20 @@ def get_ref_from_treefile(treefile, arch=None):
basearch = rpmUtils.arch.getBaseArch(arch) basearch = rpmUtils.arch.getBaseArch(arch)
ref = parsed['ref'].replace('${basearch}', basearch) ref = parsed['ref'].replace('${basearch}', basearch)
except Exception as e: except Exception as e:
print('Unable to get ref from treefile: %s' % e) logger.error('Unable to get ref from treefile: %s' % e)
else: else:
print('Unable to open treefile') logger.error('Unable to open treefile')
return ref return ref
def get_commitid_from_commitid_file(commitid_file): def get_commitid_from_commitid_file(commitid_file, logger=ostree_utils_logger):
"""Return commit id which is read from the commitid file""" """Return commit id which is read from the commitid file"""
commitid = None commitid = None
if os.path.isfile(commitid_file): if os.path.isfile(commitid_file):
with open(commitid_file, 'r') as f: with open(commitid_file, 'r') as f:
commitid = f.read().replace('\n', '') commitid = f.read().replace('\n', '')
else: else:
print('Unable to find commitid file') logger.error('Unable to find commitid file')
return commitid return commitid

View File

@ -104,9 +104,11 @@ class OSTreeThread(WorkerThread):
extra_config_file=extra_config_file) extra_config_file=extra_config_file)
if compose.notifier: if compose.notifier:
ref = get_ref_from_treefile(os.path.join(repodir, config['treefile']), arch) ref = get_ref_from_treefile(os.path.join(repodir, config['treefile']),
arch, logger=self.pool._logger)
# 'pungi-make-ostree tree' writes commitid to commitid.log in logdir # 'pungi-make-ostree tree' writes commitid to commitid.log in logdir
commitid = get_commitid_from_commitid_file(os.path.join(self.logdir, 'commitid.log')) commitid = get_commitid_from_commitid_file(os.path.join(self.logdir, 'commitid.log'),
logger=self.pool._logger)
compose.notifier.send('ostree', compose.notifier.send('ostree',
variant=variant.uid, variant=variant.uid,
arch=arch, arch=arch,