[Fedora-livecd-list] [PATCH 1/2] Change releasever to a command line option (#667474)

Brian C. Lane bcl at redhat.com
Wed Jan 5 20:53:41 UTC 2011


The release version of the running system may not be the release you
want to build the livecd for, or the rpmdb may not be accessable from
the build environment (koji and chroot) so set the value to use for
$releasever in kickstart repo url's by passing --releasever=VER
---
 docs/livecd-creator.pod |    6 +++++-
 imgcreate/creator.py    |   11 +++++++----
 imgcreate/live.py       |    6 +++---
 imgcreate/yuminst.py    |   12 ++++++++++--
 tools/livecd-creator    |   25 ++++++++++++++-----------
 5 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/docs/livecd-creator.pod b/docs/livecd-creator.pod
index 553f865..76099fe 100644
--- a/docs/livecd-creator.pod
+++ b/docs/livecd-creator.pod
@@ -47,6 +47,10 @@ currently requires a custom kernel to produce a functional image. lzo works with
 is used, the -comp option is not passed to mksquashfs to allow the use of
 older versions of mksquashfs.
 
+=item --releasever=VER
+
+Set the value to substitute for $releasever in kickstart repo urls
+
 =back
 
 =head1 SYSTEM DIRECTORY OPTIONS
@@ -81,7 +85,7 @@ livecd-creator \
 =head1 REPO EXTENSIONS
 
 livecd-creator provides for some extensions to the repo commands similar
-to what yum supports. The strings $arch, $basearch and $releveasever
+to what yum supports. The strings $arch, $basearch and $releasever (when --releasever is set)
 are replaced with the system arch, basearch and release version respectively.
 The allows the use of repo commands such as the following:
 
diff --git a/imgcreate/creator.py b/imgcreate/creator.py
index 1f1e5b8..4d0e59d 100644
--- a/imgcreate/creator.py
+++ b/imgcreate/creator.py
@@ -51,7 +51,7 @@ class ImageCreator(object):
 
     """
 
-    def __init__(self, ks, name):
+    def __init__(self, ks, name, releasever=None):
         """Initialize an ImageCreator instance.
 
         ks -- a pykickstart.KickstartParser instance; this instance will be
@@ -61,6 +61,7 @@ class ImageCreator(object):
         name -- a name for the image; used for e.g. image filenames or
                 filesystem labels
 
+        releasever -- Value to substitute for $releasever in repo urls
         """
         self.ks = ks
         """A pykickstart.KickstartParser instance."""
@@ -68,6 +69,8 @@ class ImageCreator(object):
         self.name = name
         """A name for the image."""
 
+        self.releasever = releasever
+
         self.tmpdir = "/var/tmp"
         """The directory in which all temporary files will be created."""
 
@@ -634,7 +637,7 @@ class ImageCreator(object):
         """
         yum_conf = self._mktemp(prefix = "yum.conf-")
 
-        ayum = LiveCDYum()
+        ayum = LiveCDYum(releasever=self.releasever)
         ayum.setup(yum_conf, self._instroot)
 
         for repo in kickstart.get_repos(self.ks, repo_urls):
@@ -793,7 +796,7 @@ class LoopImageCreator(ImageCreator):
 
     """
 
-    def __init__(self, ks, name, fslabel = None):
+    def __init__(self, ks, name, fslabel=None, releasever=None):
         """Initialize a LoopImageCreator instance.
 
         This method takes the same arguments as ImageCreator.__init__() with
@@ -802,7 +805,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, releasever=releasever)
 
         self.__fslabel = None
         self.fslabel = fslabel
diff --git a/imgcreate/live.py b/imgcreate/live.py
index 5e47159..93a4b4e 100644
--- a/imgcreate/live.py
+++ b/imgcreate/live.py
@@ -38,13 +38,13 @@ class LiveImageCreatorBase(LoopImageCreator):
 
     """
 
-    def __init__(self, *args):
+    def __init__(self, ks, name, fslabel=None, releasever=None):
         """Initialise a LiveImageCreator instance.
 
-        This method takes the same arguments as ImageCreator.__init__().
+        This method takes the same arguments as LoopImageCreator.__init__().
 
         """
-        LoopImageCreator.__init__(self, *args)
+        LoopImageCreator.__init__(self, ks, name, fslabel=fslabel, releasever=releasever)
 
         self.compress_type = "gzip"
         """mksquashfs compressor to use."""
diff --git a/imgcreate/yuminst.py b/imgcreate/yuminst.py
index 92b8f45..da035ec 100644
--- a/imgcreate/yuminst.py
+++ b/imgcreate/yuminst.py
@@ -45,8 +45,12 @@ class TextProgress(object):
         self.emit(logging.INFO, "...OK\n")
 
 class LiveCDYum(yum.YumBase):
-    def __init__(self):
+    def __init__(self, releasever=None):
+        """
+        releasever = optional value to use in replacing $releasever in repos
+        """
         yum.YumBase.__init__(self)
+        self.releasever = releasever
 
     def doFileLogSetup(self, uid, logfile):
         # don't do the file log for the livecd as it can lead to open fds
@@ -138,7 +142,11 @@ class LiveCDYum(yum.YumBase):
             # takes a variable and substitutes like yum configs do
             option = option.replace("$basearch", rpmUtils.arch.getBaseArch())
             option = option.replace("$arch", rpmUtils.arch.getCanonArch())
-            option = option.replace("$releasever", yum.config._getsysver("/", "redhat-release"))
+            if option.find("$releasever") > -1:
+                if self.releasever:
+                    option = option.replace("$releasever", self.releasever)
+                else:
+                    raise CreatorError("$releasever in repo url, but no releasever set")
             return option
 
         repo = yum.yumRepo.YumRepository(name)
diff --git a/tools/livecd-creator b/tools/livecd-creator
index afe592f..18c50cd 100755
--- a/tools/livecd-creator
+++ b/tools/livecd-creator
@@ -40,16 +40,19 @@ def parse_options(args):
                       help="Path or url to kickstart config file")
     imgopt.add_option("-b", "--base-on", type="string", dest="base_on",
                       help="Add packages to an existing live CD iso9660 image.")
-    imgopt.add_option("-f", "--fslabel", type="string", dest="fs_label",
+    imgopt.add_option("-f", "--fslabel", type="string", dest="fslabel",
                       help="File system label (default based on config name)")
     # Provided for img-create compatibility
-    imgopt.add_option("-n", "--name", type="string", dest="fs_label",
+    imgopt.add_option("-n", "--name", type="string", dest="fslabel",
                       help=optparse.SUPPRESS_HELP)
     imgopt.add_option("", "--image-type", type="string", dest="image_type",
                       help=optparse.SUPPRESS_HELP)
     imgopt.add_option("", "--compression-type", type="string", dest="compress_type",
                       help="Compression type recognized by mksquashfs (default gzip, lzma needs custom kernel, lzo needs a 2.6.36+ kernel)",
                       default="gzip")
+    imgopt.add_option("", "--releasever", type="string", dest="releasever",
+                      default=None,
+                      help="Value to substitute for $releasever in kickstart repo urls")
     parser.add_option_group(imgopt)
 
     # options related to the config of your system
@@ -97,9 +100,9 @@ def parse_options(args):
     if options.base_on and not os.path.isfile(options.base_on):
         raise Usage("Image file '%s' does not exist" %(options.base_on,))
     if options.image_type == 'livecd':
-        if options.fs_label and len(options.fs_label) > imgcreate.FSLABEL_MAXLEN:
+        if options.fslabel and len(options.fslabel) > imgcreate.FSLABEL_MAXLEN:
             raise Usage("CD labels are limited to 32 characters")
-        if options.fs_label and options.fs_label.find(" ") != -1:
+        if options.fslabel and options.fslabel.find(" ") != -1:
             raise Usage("CD labels cannot contain spaces.")
 
     return options
@@ -122,25 +125,25 @@ def main():
         print >> sys.stderr, "You must run %s as root" % sys.argv[0]
         return 1
 
-    if options.fs_label:
-        fs_label = options.fs_label
-        name = fs_label
+    if options.fslabel:
+        fslabel = options.fslabel
+        name = fslabel
     else:
         name = imgcreate.build_name(options.kscfg, options.image_type + "-")
 
-        fs_label = imgcreate.build_name(options.kscfg,
+        fslabel = imgcreate.build_name(options.kscfg,
                                         options.image_type + "-",
                                         maxlen = imgcreate.FSLABEL_MAXLEN,
                                         suffix = "%s-%s" %(os.uname()[4], time.strftime("%Y%m%d%H%M")))
 
-        logging.info("Using label '%s' and name '%s'" % (fs_label, name))
+        logging.info("Using label '%s' and name '%s'" % (fslabel, name))
 
     ks = imgcreate.read_kickstart(options.kscfg)
 
     if options.image_type == 'livecd':
-        creator = imgcreate.LiveImageCreator(ks, name, fs_label)
+        creator = imgcreate.LiveImageCreator(ks, name, fslabel=fslabel, releasever=options.releasever)
     elif options.image_type == 'image':
-        creator = imgcreate.LoopImageCreator(ks, name, fs_label)
+        creator = imgcreate.LoopImageCreator(ks, name, fslabel=fslabel, releasever=options.releasever)
     else:
         # Cannot happen, we validate this when parsing options.
         logging.error(u"'%s' is not a valid image type" % options.image_type)
-- 
1.7.3.4



More information about the livecd mailing list