handle logfile to record bootstrap output when specified
authorGui Chen <gui.chen@intel.com>
Tue, 21 Aug 2012 15:29:01 +0000 (23:29 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 21 Aug 2012 15:33:05 +0000 (23:33 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/bootstrap.py
mic/msger.py
mic/rt_util.py

index 503193d..0b3902c 100644 (file)
@@ -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
index ab94e9e..5deb6bb 100644 (file)
@@ -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)
 
index 3875744..f538271 100644 (file)
@@ -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)