summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGui Chen <gui.chen@intel.com>2014-05-14 02:37:16 -0400
committerGui Chen <gui.chen@intel.com>2014-06-09 01:40:10 -0400
commitb0ef922dc9feef3282d1df4e30920c6ba28ae31a (patch)
treee4b340a0d8ed2f0c77778caaa1543a971693e075
parent7fa71bf35ed415052387eb12999879f7a11b78ba (diff)
downloadmic-b0ef922dc9feef3282d1df4e30920c6ba28ae31a.tar.gz
mic-b0ef922dc9feef3282d1df4e30920c6ba28ae31a.tar.bz2
mic-b0ef922dc9feef3282d1df4e30920c6ba28ae31a.zip
relocate create.logfile to conf module
Change-Id: I276069bb1c33c1ef9a6c3eaac5ce409c211a9a51 Signed-off-by: Gui Chen <gui.chen@intel.com>
-rw-r--r--mic/conf.py22
-rw-r--r--mic/creator.py12
-rw-r--r--mic/imager/baseimager.py12
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 ab781b9..2d2fc00 100644
--- a/mic/imager/baseimager.py
+++ b/mic/imager/baseimager.py
@@ -1278,13 +1278,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):