relocate create.logfile to conf module
authorGui Chen <gui.chen@intel.com>
Wed, 14 May 2014 06:37:16 +0000 (02:37 -0400)
committerGui Chen <gui.chen@intel.com>
Fri, 16 May 2014 08:00:55 +0000 (04:00 -0400)
Change-Id: I276069bb1c33c1ef9a6c3eaac5ce409c211a9a51
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/conf.py
mic/creator.py
mic/imager/baseimager.py

index a9e77a8..a945f6a 100644 (file)
@@ -32,6 +32,11 @@ def get_siteconf():
     else:
         return DEFAULT_GSITECONF
 
+def inbootstrap():
+    if os.path.exists(os.path.join("/", ".chroot.lock")):
+        return True
+    return (os.stat("/").st_ino != 2)
+
 class ConfigMgr(object):
     prefer_backends = ["zypp", "yum"]
 
@@ -53,6 +58,7 @@ class ConfigMgr(object):
                     "local_pkgs_path": None,
                     "release": None,
                     "logfile": None,
+                    "releaselog": False,
                     "record_pkgs": [],
                     "pack_to": None,
                     "name_prefix": None,
@@ -209,6 +215,22 @@ class ConfigMgr(object):
                                                            self.create['name'])
             self.create['name'] = self.create['release'] + '_' + self.create['name']
 
+            if not self.create['logfile']:
+                self.create['logfile'] = os.path.join(self.create['outdir'],
+                                                      self.create['name'] + ".log")
+                self.create['releaselog'] = True
+
+        if self.create['logfile']:
+            logfile_dir = os.path.dirname(self.create['logfile'])
+            if not os.path.exists(logfile_dir):
+                os.makedirs(logfile_dir)
+            msger.set_interactive(False)
+            if inbootstrap():
+                mode = 'a'
+            else:
+                mode = 'w'
+            msger.set_logfile(self.create['logfile'], mode)
+
         msger.info("Retrieving repo metadata:")
         ksrepos = kickstart.get_repos(ks,
                                       self.create['extrarepos'],
index 9650309..b21ebda 100644 (file)
@@ -19,7 +19,7 @@ import os, sys, re
 import pwd
 from optparse import SUPPRESS_HELP
 
-from mic import msger, rt_util
+from mic import msger
 from mic.utils import cmdln, errors, rpmmisc
 from mic.conf import configmgr
 from mic.plugin import pluginmgr
@@ -182,15 +182,7 @@ class Creator(cmdln.Cmdln):
             if os.path.isdir(logfile_abs_path):
                 raise errors.Usage("logfile's path %s should be file"
                                    % self.options.logfile)
-            if not os.path.exists(os.path.dirname(logfile_abs_path)):
-                os.makedirs(os.path.dirname(logfile_abs_path))
-            msger.set_interactive(False)
-            if rt_util.inbootstrap():
-                mode = 'a'
-            else:
-                mode = 'w'
-            msger.set_logfile(logfile_abs_path, mode)
-            configmgr.create['logfile'] = self.options.logfile
+            configmgr.create['logfile'] = logfile_abs_path
 
         if self.options.config:
             configmgr.reset()
index 3bd48a8..43896bf 100644 (file)
@@ -1284,13 +1284,11 @@ class BaseImageCreator(object):
         outimages.append(new_kspath)
 
         # save log file, logfile is only available in creator attrs
-        if hasattr(self, 'logfile') and not self.logfile:
-            log_path = _rpath(self.name + ".log")
-            # touch the log file, else outimages will filter it out
-            with open(log_path, 'w') as wf:
-                wf.write('')
-            msger.set_logfile(log_path)
-            outimages.append(_rpath(self.name + ".log"))
+        if hasattr(self, 'releaselog') and self.releaselog:
+            final_logfile = _rpath(self.name+'.log')
+            shutil.move(self.logfile, final_logfile)
+            self.logfile = final_logfile
+            outimages.append(self.logfile)
 
         # rename iso and usbimg
         for f in os.listdir(destdir):