From 93a3f75eca231efd4cfb85d9488dc1e8cec18c7e Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Wed, 14 May 2014 02:37:16 -0400 Subject: [PATCH] relocate create.logfile to conf module Change-Id: I276069bb1c33c1ef9a6c3eaac5ce409c211a9a51 Signed-off-by: Gui Chen --- mic/conf.py | 22 ++++++++++++++++++++++ mic/creator.py | 12 ++---------- mic/imager/baseimager.py | 12 +++++------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/mic/conf.py b/mic/conf.py index a9e77a8..a945f6a 100644 --- a/mic/conf.py +++ b/mic/conf.py @@ -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'], diff --git a/mic/creator.py b/mic/creator.py index 9650309..b21ebda 100644 --- a/mic/creator.py +++ b/mic/creator.py @@ -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() diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 3bd48a8..43896bf 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -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): -- 2.7.4