From bf16f628f25d987df8484d440e41fadbcfdb5d8a Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Tue, 21 Aug 2012 23:29:01 +0800 Subject: [PATCH] handle logfile to record bootstrap output when specified Signed-off-by: Gui Chen --- mic/bootstrap.py | 3 +++ mic/msger.py | 6 ++++++ mic/rt_util.py | 1 + 3 files changed, 10 insertions(+) diff --git a/mic/bootstrap.py b/mic/bootstrap.py index 503193d..0b3902c 100644 --- a/mic/bootstrap.py +++ b/mic/bootstrap.py @@ -152,6 +152,7 @@ class Bootstrap(object): self.rootdir = rootdir self.distro = distro self.arch = arch + self.logfile = None self.pkgslist = [] self.repomd = None @@ -208,6 +209,8 @@ class Bootstrap(object): except (OSError, IOError), err: raise RuntimeError(err) finally: + if self.logfile: + msger.log(file(self.logfile).read()) cleanup_chrootenv(self.rootdir, bindmounts, gloablmounts) proxy.unset_proxy_environ() return retcode diff --git a/mic/msger.py b/mic/msger.py index ab94e9e..5deb6bb 100644 --- a/mic/msger.py +++ b/mic/msger.py @@ -179,6 +179,12 @@ def set_interactive(mode=True): else: INTERACTIVE = False +def log(msg=''): + # log msg to LOG_CONTENT then save to logfile + global LOG_CONTENT + if msg: + LOG_CONTENT += msg + def raw(msg=''): _general_print('', NO_COLOR, msg) diff --git a/mic/rt_util.py b/mic/rt_util.py index 3875744..f538271 100644 --- a/mic/rt_util.py +++ b/mic/rt_util.py @@ -57,6 +57,7 @@ def bootstrap_mic(argv=None): # create bootstrap and run mic in bootstrap bsenv = bootstrap.Bootstrap(rootdir, distro, cropts['arch']) + bsenv.logfile = cropts['logfile'] try: msger.info("Creating %s bootstrap ..." % distro) bsenv.create(cropts['repomd'], pkglist) -- 2.7.4