[lorax 5/7] Get the log directory from the configfile

Brian C. Lane bcl at redhat.com
Wed Feb 11 18:40:10 UTC 2015


In the lorax script create it if missing and override it with the
path of --logfile
---
 src/pylorax/__init__.py | 3 ++-
 src/sbin/lorax          | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
index 8a46c06..fc489c6 100644
--- a/src/pylorax/__init__.py
+++ b/src/pylorax/__init__.py
@@ -87,6 +87,7 @@ class Lorax(BaseLoraxClass):
         self.conf.add_section("lorax")
         self.conf.set("lorax", "debug", "1")
         self.conf.set("lorax", "sharedir", "/usr/share/lorax")
+        self.conf.set("lorax", "logdir", "/var/log/lorax")
 
         self.conf.add_section("output")
         self.conf.set("output", "colors", "1")
@@ -179,7 +180,7 @@ class Lorax(BaseLoraxClass):
             os.makedirs(self.workdir)
 
         # set up log directory
-        logdir = '/var/log/lorax'
+        logdir = self.conf.get("lorax", "logdir")
         if not os.path.isdir(logdir):
             os.makedirs(logdir)
 
diff --git a/src/sbin/lorax b/src/sbin/lorax
index cd14550..6e76c2f 100755
--- a/src/sbin/lorax
+++ b/src/sbin/lorax
@@ -171,6 +171,8 @@ def main(args):
         parser.error("output directory %s should not exist." % outputdir)
 
     opts.logfile = os.path.abspath(opts.logfile)
+    if not os.path.exists(os.path.dirname(opts.logfile)):
+        os.makedirs(os.path.dirname(opts.logfile))
     if opts.cachedir:
         opts.cachedir = os.path.abspath(opts.cachedir)
     if opts.workdir:
@@ -214,6 +216,7 @@ def main(args):
     # run lorax
     lorax = pylorax.Lorax()
     lorax.configure(conf_file=opts.config)
+    lorax.conf.set("lorax", "logdir", os.path.dirname(opts.logfile))
     lorax.run(dnfbase, opts.product, opts.version, opts.release,
               opts.variant, opts.bugurl, opts.isfinal,
               workdir=tempdir, outputdir=outputdir, buildarch=opts.buildarch,
-- 
2.1.0



More information about the anaconda-patches mailing list