[Fedora-livecd-list] [PATCH] add --global-config

Alan Pevec apevec at redhat.com
Wed Oct 29 21:49:57 UTC 2008


to use default YUM config i.e. /etc/yum.conf
With this option you don't have to supply repo kickstart commands.

Also add --cacheonly option to run entirely from YUM cache.

Signed-off-by: Alan Pevec <apevec at redhat.com>
---
 imgcreate/creator.py |   27 ++++++++++++++++++++-------
 imgcreate/yuminst.py |   11 +++++++----
 tools/livecd-creator |    8 +++++++-
 3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/imgcreate/creator.py b/imgcreate/creator.py
index 519735e..48d5d70 100644
--- a/imgcreate/creator.py
+++ b/imgcreate/creator.py
@@ -50,7 +50,7 @@ class ImageCreator(object):
 
     """
 
-    def __init__(self, ks, name):
+    def __init__(self, ks, name, globalYUM = False, cacheonly = False):
         """Initialize an ImageCreator instance.
 
         ks -- a pykickstart.KickstartParser instance; this instance will be
@@ -73,6 +73,9 @@ class ImageCreator(object):
         self.__builddir = None
         self.__bindmounts = []
 
+        self.__globalYUM = globalYUM
+        self.__cacheonly = cacheonly
+
         self.__sanity_check()
 
     def __del__(self):
@@ -396,7 +399,8 @@ class ImageCreator(object):
 
         kickstart.convert_method_to_repo(self.ks)
 
-        if not kickstart.get_repos(self.ks):
+        # with -g global YUM config repositories are not taken from ks
+        if not self.__globalYUM and not kickstart.get_repos(self.ks):
             raise CreatorError("No repositories specified")
 
         if (kickstart.selinux_enabled(self.ks) and
@@ -623,10 +627,17 @@ class ImageCreator(object):
                      the kickstart to be overridden.
 
         """
-        yum_conf = self._mktemp(prefix = "yum.conf-")
 
         ayum = LiveCDYum()
-        ayum.setup(yum_conf, self._instroot)
+        if self.__globalYUM:
+            yum_conf = None
+        else:
+            yum_conf = self._mktemp(prefix = "yum.conf-")
+
+        if self.__cacheonly:
+            ayum.setup(yum_conf, self._instroot, cache=1)
+        else:
+            ayum.setup(yum_conf, self._instroot)
 
         for repo in kickstart.get_repos(self.ks, repo_urls):
             (name, baseurl, mirrorlist, inc, exc) = repo
@@ -659,7 +670,8 @@ class ImageCreator(object):
         finally:
             ayum.closeRpmDB()
             ayum.close()
-            os.unlink(yum_conf)
+            if yum_conf:
+                os.unlink(yum_conf)
 
         # do some clean up to avoid lvm info leakage.  this sucks.
         for subdir in ("cache", "backup", "archive"):
@@ -776,7 +788,8 @@ class LoopImageCreator(ImageCreator):
 
     """
 
-    def __init__(self, ks, name, fslabel = None):
+    def __init__(self, ks, name, fslabel = None,
+                 globalYUM = False, cacheonly = False):
         """Initialize a LoopImageCreator instance.
 
         This method takes the same arguments as ImageCreator.__init__() with
@@ -785,7 +798,7 @@ class LoopImageCreator(ImageCreator):
         fslabel -- A string used as a label for any filesystems created.
 
         """
-        ImageCreator.__init__(self, ks, name)
+        ImageCreator.__init__(self, ks, name, globalYUM, cacheonly)
 
         self.__fslabel = None
         self.fslabel = fslabel
diff --git a/imgcreate/yuminst.py b/imgcreate/yuminst.py
index 04c9b40..c13b162 100644
--- a/imgcreate/yuminst.py
+++ b/imgcreate/yuminst.py
@@ -75,11 +75,14 @@ class LiveCDYum(yum.YumBase):
         for f in glob.glob(installroot + "/var/lib/rpm/__db*"):
             os.unlink(f)
 
-    def setup(self, confpath, installroot):
-        self._writeConf(confpath, installroot)
+    def setup(self, confpath, installroot, cache=0):
         self._cleanupRpmdbLocks(installroot)
-        self.doConfigSetup(fn = confpath, root = installroot)
-        self.conf.cache = 0
+        if confpath:
+            self._writeConf(confpath, installroot)
+            self.doConfigSetup(fn = confpath, root = installroot)
+        else:
+            self.doConfigSetup(root = installroot)
+        self.conf.cache = cache
         self.doTsSetup()
         self.doRpmDBSetup()
         self.doRepoSetup()
diff --git a/tools/livecd-creator b/tools/livecd-creator
index b401190..594686a 100755
--- a/tools/livecd-creator
+++ b/tools/livecd-creator
@@ -52,6 +52,11 @@ def parse_options(args):
     sysopt.add_option("", "--cache", type="string",
                       dest="cachedir", default=None,
                       help="Cache directory to use (default: private cache")
+    sysopt.add_option("--global-config", dest="global_config",
+                      action="store_true",
+                      help="Use global YUM configuration, /etc/yum.conf")
+    sysopt.add_option("--cacheonly", action="store_true", dest="cacheonly",
+                      help="run entirely from YUM cache, don't update YUM cache")
     parser.add_option_group(sysopt)
 
     imgcreate.setup_logging(parser)
@@ -109,7 +114,8 @@ def main():
 
     ks = imgcreate.read_kickstart(options.kscfg)
 
-    creator = imgcreate.LiveImageCreator(ks, name, fs_label)
+    creator = imgcreate.LiveImageCreator(ks, name, fs_label,
+                    options.global_config, options.cacheonly)
     creator.tmpdir = options.tmpdir
     creator.skip_compression = options.skip_compression
     creator.skip_minimize = options.skip_minimize
-- 
1.5.6.5




More information about the Fedora-livecd-list mailing list