Skip to contentSkip to conversation

Reimplement kickstart parser

PATCH New Ed Bartosh 1 participant 10 messages Jan 14, 2016

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

cover Reimplement kickstart parser

Hi,

This patchset contains reimplementation of .ks file parser.
New parser code is much smaller (around 4K) than complex pykickstart parser from Fedora (around 170K). I hope it's much more clean and mainainable too.

Getting rid of dependency to pykickstart was in my TODO list since March 2015 when I first looked at wic codebase. When I started to work on #8848 (sharing a single Kickstart partition layout definition (.wks) between several images) I decided to implement new parser instead of tweaking complicated pykickstart condebase.

As as side effect of this work test coverage report for wic codebase looks shorter and coverage is increased from 58% to 63%:

Name Stmts Miss Branch BrMiss Cover
-------------------------------------------------------------------------------------

scripts/lib/wic/__init__                                3      0      0      0   100%
scripts/lib/wic/conf                                   45      4     12      5    84%
scripts/lib/wic/creator                                61     19     29     15    62%
scripts/lib/wic/engine                                102     61     56     44    34%
scripts/lib/wic/help                                   49      4     18      3    90%
scripts/lib/wic/imager/__init__                         0      0      0      0   100%
scripts/lib/wic/imager/baseimager                      73     15     26     10    75%
scripts/lib/wic/imager/direct                         171     25     79     24    80%
scripts/lib/wic/kickstart                              67     18     20     12    66%
scripts/lib/wic/msger                                 187    101     86     54    43%
scripts/lib/wic/partition                             199     95     50     36    47%
scripts/lib/wic/plugin                                 84      7     34      6    89%
scripts/lib/wic/pluginbase                             34      4     12      5    80%
scripts/lib/wic/plugins/imager/direct_plugin           36      3      4      1    90%
scripts/lib/wic/plugins/source/bootimg-efi            119     17     26     13    79%
scripts/lib/wic/plugins/source/bootimg-partition       56     45     24     24    14%
scripts/lib/wic/plugins/source/bootimg-pcbios         103      8     30     10    86%
scripts/lib/wic/plugins/source/fsimage                 22     13      6      6    32%
scripts/lib/wic/plugins/source/isoimage-isohybrid     294     95    107     67    60%
scripts/lib/wic/plugins/source/rawcopy                 31     22     10     10    22%
scripts/lib/wic/plugins/source/rootfs                  31     10     12      5    65%
scripts/lib/wic/plugins/source/rootfs_pcbios_ext       73     59     24     24    14%
scripts/lib/wic/utils/__init__                          0      0      0      0   100%
scripts/lib/wic/utils/errors                            8      0      0      0   100%
scripts/lib/wic/utils/fs_related                       41      9      6      3    74%
scripts/lib/wic/utils/misc                             41      4     24      9    80%
scripts/lib/wic/utils/oe/__init__                       0      0      0      0   100%
scripts/lib/wic/utils/oe/misc                         112     20     47     15    78%
scripts/lib/wic/utils/partitionedfs                   151     23     79     24    80%
scripts/lib/wic/utils/runner                           57     16     26     12    66%
scripts/lib/wic/utils/syslinux                         18     15     12     12    10%
scripts/wic                                           170     53     78     30    67%

-------------------------------------------------------------------------------------
TOTAL 2438 765 937 479 63%

The following changes since commit da43a56d3533db37592a1698777af08f51a5800f:

bitbake: Revert "fetch2/local.py: avoid using PREMIRROR" (2016-01-13 09:47:28 +0000)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib ed/wic/get-rid-of-ks-parser
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=ed/wic/get-rid-of-ks-parser

Ed Bartosh (9):
wic: add partition module
wic: add kickstart parser module
wic: use new kickstart parser
wic: remove pykickstart code
wic: adjust code for new data structure
wic: get rid of get_timeout getter
wic: get rid of get_rootfs and set_rootfs
wic: get rid of set_size and set_source_file setters
wic: get rid of 2 getters

 scripts/lib/wic/3rdparty/pykickstart/__init__.py   |   0
 scripts/lib/wic/3rdparty/pykickstart/base.py       | 466 ----------------
 .../wic/3rdparty/pykickstart/commands/__init__.py  |  20 -
 .../3rdparty/pykickstart/commands/bootloader.py    | 216 -------
 .../wic/3rdparty/pykickstart/commands/partition.py | 314 -----------
 scripts/lib/wic/3rdparty/pykickstart/constants.py  |  57 --
 scripts/lib/wic/3rdparty/pykickstart/errors.py     | 103 ----
 .../wic/3rdparty/pykickstart/handlers/__init__.py  |   0
 .../wic/3rdparty/pykickstart/handlers/control.py   |  46 --
 .../lib/wic/3rdparty/pykickstart/handlers/f16.py   |  24 -
 scripts/lib/wic/3rdparty/pykickstart/ko.py         |  37 --
 scripts/lib/wic/3rdparty/pykickstart/options.py    | 223 --------
 scripts/lib/wic/3rdparty/pykickstart/parser.py     | 619 ---------------------
 scripts/lib/wic/3rdparty/pykickstart/sections.py   | 244 --------
 scripts/lib/wic/3rdparty/pykickstart/version.py    | 168 ------
 scripts/lib/wic/conf.py                            |   4 +-
 scripts/lib/wic/imager/baseimager.py               |   2 +-
 scripts/lib/wic/imager/direct.py                   |  26 +-
 scripts/lib/wic/kickstart.py                       | 120 ++++
 scripts/lib/wic/kickstart/__init__.py              | 129 -----
 .../lib/wic/kickstart/custom_commands/__init__.py  |   7 -
 .../lib/wic/kickstart/custom_commands/wicboot.py   |  65 ---
 .../{kickstart/custom_commands => }/partition.py   | 170 +-----
 scripts/lib/wic/plugins/source/bootimg-efi.py      |  28 +-
 scripts/lib/wic/plugins/source/bootimg-pcbios.py   |  24 +-
 .../lib/wic/plugins/source/isoimage-isohybrid.py   |  36 +-
 scripts/lib/wic/plugins/source/rootfs.py           |  14 +-
 .../lib/wic/plugins/source/rootfs_pcbios_ext.py    |  11 +-
 28 files changed, 212 insertions(+), 2961 deletions(-)
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/__init__.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/base.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/commands/__init__.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/commands/bootloader.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/commands/partition.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/constants.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/errors.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/handlers/__init__.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/handlers/control.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/handlers/f16.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/ko.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/options.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/parser.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/sections.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/version.py
 create mode 100644 scripts/lib/wic/kickstart.py
 delete mode 100644 scripts/lib/wic/kickstart/__init__.py
 delete mode 100644 scripts/lib/wic/kickstart/custom_commands/__init__.py
 delete mode 100644 scripts/lib/wic/kickstart/custom_commands/wicboot.py
 rename scripts/lib/wic/{kickstart/custom_commands => }/partition.py (73%)

--
Regards,
Ed

author
#1 lore raw

PATCH 1/9 wic: add partition module

Copied partition-related API from kickstart/custom_commands/partition.py to separate module in preparation for removal of all pykickstart related code.

---
 scripts/lib/wic/partition.py | 410 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 410 insertions(+)
 create mode 100644 scripts/lib/wic/partition.py
scripts/lib/wic/partition.py new file +410 -0
new file mode 100644
index 0000000..9bb1a0a
@@ -0,0 +1,410 @@
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2013-2016 Intel Corporation.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# DESCRIPTION
+# This module provides the OpenEmbedded partition object definitions.
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
+
+import os
+import tempfile
+import uuid
+
+from wic.utils.oe.misc import msger, parse_sourceparams
+from wic.utils.oe.misc import exec_cmd, exec_native_cmd
+from wic.plugin import pluginmgr
+
+partition_methods = {
+    "do_stage_partition":None,
+    "do_prepare_partition":None,
+    "do_configure_partition":None,
+}
+
+class Partition(object):
+
+    def __init__(self, args, lineno):
+        self.args = args
+        self.active = args.active
+        self.align = args.align
+        self.disk = args.disk
+        self.extra_space = args.extra_space
+        self.fsopts = args.fsopts
+        self.fstype = args.fstype
+        self.label = args.label
+        self.mountpoint = args.mountpoint
+        self.no_table = args.no_table
+        self.overhead_factor = args.overhead_factor
+        self.part_type = args.part_type
+        self.rootfs_dir = args.rootfs_dir
+        self.size = args.size
+        self.source = args.source
+        self.sourceparams = args.sourceparams
+        self.uuid = args.uuid
+
+        self.lineno = lineno
+        self.source_file = ""
+        self.sourceparams_dict = {}
+
+    def get_extra_block_count(self, current_blocks):
+        """
+        The --size param is reflected in self.size (in kB), and we already
+        have current_blocks (1k) blocks, calculate and return the
+        number of (1k) blocks we need to add to get to --size, 0 if
+        we're already there or beyond.
+        """
+        msger.debug("Requested partition size for %s: %d" % \
+                    (self.mountpoint, self.size))
+
+        if not self.size:
+            return 0
+
+        requested_blocks = self.size
+
+        msger.debug("Requested blocks %d, current_blocks %d" % \
+                    (requested_blocks, current_blocks))
+
+        if requested_blocks > current_blocks:
+            return requested_blocks - current_blocks
+        else:
+            return 0
+
+    def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir,
+                bootimg_dir, kernel_dir, native_sysroot):
+        """
+        Prepare content for individual partitions, depending on
+        partition command parameters.
+        """
+        if self.sourceparams:
+            self.sourceparams_dict = parse_sourceparams(self.sourceparams)
+
+        if not self.source:
+            if not self.size:
+                msger.error("The %s partition has a size of zero.  Please "
+                            "specify a non-zero --size for that partition." % \
+                            self.mountpoint)
+            if self.fstype and self.fstype == "swap":
+                self.prepare_swap_partition(cr_workdir, oe_builddir,
+                                            native_sysroot)
+            elif self.fstype:
+                rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label,
+                                             self.lineno, self.fstype)
+                if os.path.isfile(rootfs):
+                    os.remove(rootfs)
+                for prefix in ("ext", "btrfs", "vfat", "squashfs"):
+                    if self.fstype.startswith(prefix):
+                        method = getattr(self,
+                                         "prepare_empty_partition_" + prefix)
+                        method(rootfs, oe_builddir, native_sysroot)
+                        self.source_file = rootfs
+                        break
+            return
+
+        plugins = pluginmgr.get_source_plugins()
+
+        if self.source not in plugins:
+            msger.error("The '%s' --source specified for %s doesn't exist.\n\t"
+                        "See 'wic list source-plugins' for a list of available"
+                        " --sources.\n\tSee 'wic help source-plugins' for "
+                        "details on adding a new source plugin." % \
+                        (self.source, self.mountpoint))
+
+        self._source_methods = pluginmgr.get_source_plugin_methods(\
+                                   self.source, partition_methods)
+        self._source_methods["do_configure_partition"](self, self.sourceparams_dict,
+                                                       creator, cr_workdir,
+                                                       oe_builddir,
+                                                       bootimg_dir,
+                                                       kernel_dir,
+                                                       native_sysroot)
+        self._source_methods["do_stage_partition"](self, self.sourceparams_dict,
+                                                   creator, cr_workdir,
+                                                   oe_builddir,
+                                                   bootimg_dir, kernel_dir,
+                                                   native_sysroot)
+        self._source_methods["do_prepare_partition"](self, self.sourceparams_dict,
+                                                     creator, cr_workdir,
+                                                     oe_builddir,
+                                                     bootimg_dir, kernel_dir, rootfs_dir,
+                                                     native_sysroot)
+
+    def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
+                                     rootfs_dir):
+        """
+        Handle an already-created partition e.g. xxx.ext3
+        """
+        rootfs = oe_builddir
+        du_cmd = "du -Lbks %s" % rootfs
+        out = exec_cmd(du_cmd)
+        rootfs_size = out.split()[0]
+
+        self.size = rootfs_size
+        self.source_file = rootfs
+
+    def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
+                       native_sysroot):
+        """
+        Prepare content for a rootfs partition i.e. create a partition
+        and fill it from a /rootfs dir.
+
+        Currently handles ext2/3/4, btrfs and vfat.
+        """
+        p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
+        p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
+                                         "%s/../pseudo" % rootfs_dir)
+        p_passwd = os.environ.get("PSEUDO_PASSWD", rootfs_dir)
+        p_nosymlinkexp = os.environ.get("PSEUDO_NOSYMLINKEXP", "1")
+        pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
+        pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % p_localstatedir
+        pseudo += "export PSEUDO_PASSWD=%s;" % p_passwd
+        pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp
+        pseudo += "%s/usr/bin/pseudo " % native_sysroot
+
+        rootfs = "%s/rootfs_%s.%s.%s" % (cr_workdir, self.label,
+                                         self.lineno, self.fstype)
+        if os.path.isfile(rootfs):
+            os.remove(rootfs)
+
+        for prefix in ("ext", "btrfs", "vfat", "squashfs"):
+            if self.fstype.startswith(prefix):
+                method = getattr(self, "prepare_rootfs_" + prefix)
+                method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)
+
+                self.source_file = rootfs
+
+                # get the rootfs size in the right units for kickstart (kB)
+                du_cmd = "du -Lbks %s" % rootfs
+                out = exec_cmd(du_cmd)
+                self.size = out.split()[0]
+
+                break
+
+    def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
+                           native_sysroot, pseudo):
+        """
+        Prepare content for an ext2/3/4 rootfs partition.
+        """
+        du_cmd = "du -ks %s" % rootfs_dir
+        out = exec_cmd(du_cmd)
+        actual_rootfs_size = int(out.split()[0])
+
+        extra_blocks = self.get_extra_block_count(actual_rootfs_size)
+        if extra_blocks < self.extra_space:
+            extra_blocks = self.extra_space
+
+        rootfs_size = actual_rootfs_size + extra_blocks
+        rootfs_size *= self.overhead_factor
+
+        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
+                    (extra_blocks, self.mountpoint, rootfs_size))
+
+        dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
+            (rootfs, rootfs_size)
+        exec_cmd(dd_cmd)
+
+        extra_imagecmd = "-i 8192"
+
+        label_str = ""
+        if self.label:
+            label_str = "-L %s" % self.label
+
+        mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \
+            (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
+        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
+
+    def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
+                             native_sysroot, pseudo):
+        """
+        Prepare content for a btrfs rootfs partition.
+
+        Currently handles ext2/3/4 and btrfs.
+        """
+        du_cmd = "du -ks %s" % rootfs_dir
+        out = exec_cmd(du_cmd)
+        actual_rootfs_size = int(out.split()[0])
+
+        extra_blocks = self.get_extra_block_count(actual_rootfs_size)
+        if extra_blocks < self.extra_space:
+            extra_blocks = self.extra_space
+
+        rootfs_size = actual_rootfs_size + extra_blocks
+        rootfs_size *= self.overhead_factor
+
+        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
+                    (extra_blocks, self.mountpoint, rootfs_size))
+
+        dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
+            (rootfs, rootfs_size)
+        exec_cmd(dd_cmd)
+
+        label_str = ""
+        if self.label:
+            label_str = "-L %s" % self.label
+
+        mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \
+            (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs)
+        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
+
+    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
+                            native_sysroot, pseudo):
+        """
+        Prepare content for a vfat rootfs partition.
+        """
+        du_cmd = "du -bks %s" % rootfs_dir
+        out = exec_cmd(du_cmd)
+        blocks = int(out.split()[0])
+
+        extra_blocks = self.get_extra_block_count(blocks)
+        if extra_blocks < self.extra_space:
+            extra_blocks = self.extra_space
+
+        blocks += extra_blocks
+
+        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
+                    (extra_blocks, self.mountpoint, blocks))
+
+        # Ensure total sectors is an integral number of sectors per
+        # track or mcopy will complain. Sectors are 512 bytes, and we
+        # generate images with 32 sectors per track. This calculation
+        # is done in blocks, thus the mod by 16 instead of 32. Apply
+        # sector count fix only when needed.
+        if blocks % 16 != 0:
+            blocks += (16 - (blocks % 16))
+
+        label_str = "-n boot"
+        if self.label:
+            label_str = "-n %s" % self.label
+
+        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
+        exec_native_cmd(dosfs_cmd, native_sysroot)
+
+        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
+        exec_native_cmd(mcopy_cmd, native_sysroot)
+
+        chmod_cmd = "chmod 644 %s" % rootfs
+        exec_cmd(chmod_cmd)
+
+    def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
+                                native_sysroot, pseudo):
+        """
+        Prepare content for a squashfs rootfs partition.
+        """
+        squashfs_cmd = "mksquashfs %s %s -noappend" % \
+                       (rootfs_dir, rootfs)
+        exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
+
+    def prepare_empty_partition_ext(self, rootfs, oe_builddir,
+                                    native_sysroot):
+        """
+        Prepare an empty ext2/3/4 partition.
+        """
+        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
+            (rootfs, self.size)
+        exec_cmd(dd_cmd)
+
+        extra_imagecmd = "-i 8192"
+
+        label_str = ""
+        if self.label:
+            label_str = "-L %s" % self.label
+
+        mkfs_cmd = "mkfs.%s -F %s %s %s" % \
+            (self.fstype, extra_imagecmd, label_str, rootfs)
+        exec_native_cmd(mkfs_cmd, native_sysroot)
+
+    def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
+                                      native_sysroot):
+        """
+        Prepare an empty btrfs partition.
+        """
+        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
+            (rootfs, self.size)
+        exec_cmd(dd_cmd)
+
+        label_str = ""
+        if self.label:
+            label_str = "-L %s" % self.label
+
+        mkfs_cmd = "mkfs.%s -b %d %s %s" % \
+            (self.fstype, self.size * 1024, label_str, rootfs)
+        exec_native_cmd(mkfs_cmd, native_sysroot)
+
+    def prepare_empty_partition_vfat(self, rootfs, oe_builddir,
+                                     native_sysroot):
+        """
+        Prepare an empty vfat partition.
+        """
+        blocks = self.size
+
+        label_str = "-n boot"
+        if self.label:
+            label_str = "-n %s" % self.label
+
+        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
+        exec_native_cmd(dosfs_cmd, native_sysroot)
+
+        chmod_cmd = "chmod 644 %s" % rootfs
+        exec_cmd(chmod_cmd)
+
+    def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
+                                         native_sysroot):
+        """
+        Prepare an empty squashfs partition.
+        """
+        msger.warning("Creating of an empty squashfs %s partition was attempted. " \
+                      "Proceeding as requested." % self.mountpoint)
+
+        path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
+        os.path.isfile(path) and os.remove(path)
+
+        # it is not possible to create a squashfs without source data,
+        # thus prepare an empty temp dir that is used as source
+        tmpdir = tempfile.mkdtemp()
+
+        squashfs_cmd = "mksquashfs %s %s -noappend" % \
+                       (tmpdir, path)
+        exec_native_cmd(squashfs_cmd, native_sysroot)
+
+        os.rmdir(tmpdir)
+
+        # get the rootfs size in the right units for kickstart (kB)
+        du_cmd = "du -Lbks %s" % path
+        out = exec_cmd(du_cmd)
+        fs_size = out.split()[0]
+
+        self.size = fs_size
+
+    def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
+        """
+        Prepare a swap partition.
+        """
+        path = "%s/fs.%s" % (cr_workdir, self.fstype)
+
+        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
+            (path, self.size)
+        exec_cmd(dd_cmd)
+
+        import uuid
+        label_str = ""
+        if self.label:
+            label_str = "-L %s" % self.label
+        mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
+        exec_native_cmd(mkswap_cmd, native_sysroot)
+
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH 2/9 wic: add kickstart parser module

In reply to Ed Bartosh

This module will replace existing pykickstart machinery it contains only option used by wic, it's simple and clear. And It will allow to remove a lot of old complex code from 3rdparty/pykickstart/ and kickstart/custom_commands.

---
 scripts/lib/wic/kickstart.py | 120 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)
 create mode 100644 scripts/lib/wic/kickstart.py
scripts/lib/wic/kickstart.py new file +120 -0
new file mode 100644
index 0000000..2208395
@@ -0,0 +1,120 @@
+#!/usr/bin/env python -tt
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2016 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# DESCRIPTION
+# This module provides parser for kickstart format
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
+
+
+
+import shlex
+from argparse import ArgumentParser, ArgumentTypeError
+
+from wic.partition import Partition
+
+def sizetype(arg):
+    """
+    Custom type for ArgumentParser
+    Converts size string in <num>[K|k|M|G] format into the integer value
+    """
+    if arg.isdigit():
+        return int(arg) * 1024L
+
+    if not arg[:-1].isdigit():
+        raise ArgumentTypeError("Invalid size: %r" % arg)
+
+    size = int(arg[:-1])
+    if arg.endswith("k") or arg.endswith("K"):
+        return size
+    if arg.endswith("M"):
+        return size * 1024L
+    if arg.endswith("G"):
+        return size * 1024L * 1024L
+
+    raise ArgumentTypeError("Invalid size: %r" % arg)
+
+def overheadtype(arg):
+    """
+    Custom type for ArgumentParser
+    Converts overhead string to float and checks if it's bigger than 1.0
+    """
+    try:
+        result = float(arg)
+    except ValueError:
+        raise ArgumentTypeError("Invalid value: %r" % arg)
+
+    if result < 1.0:
+        raise ArgumentTypeError("Overhead factor should be > 1.0" % arg)
+
+    return result
+
+class KickStart(object):
+    def __init__(self, confpath):
+
+        self.partitions = []
+        self.bootloader = None
+        self.lineno = 0
+
+        parser = ArgumentParser()
+        subparsers = parser.add_subparsers()
+
+        part = subparsers.add_parser('part')
+        part.add_argument('mountpoint')
+        part.add_argument('--active', action='store_true')
+        part.add_argument('--align', type=int)
+        part.add_argument("--extra-space", type=sizetype, default=10*1024L)
+        part.add_argument('--fsoptions', dest='fsopts')
+        part.add_argument('--fstype')
+        part.add_argument('--label')
+        part.add_argument('--no-table')
+        part.add_argument('--ondisk', '--ondrive', dest='disk')
+        part.add_argument("--overhead-factor", type=overheadtype, default=1.3)
+        part.add_argument('--part-type')
+        part.add_argument('--rootfs-dir')
+        part.add_argument('--size', type=sizetype, default=0)
+        part.add_argument('--source')
+        part.add_argument('--sourceparams')
+        part.add_argument('--use-uuid', action='store_true')
+        part.add_argument('--uuid')
+
+        bootloader = subparsers.add_parser('bootloader')
+        bootloader.add_argument('--append')
+        bootloader.add_argument('--configfile')
+        bootloader.add_argument('--ptable', choices=('msdos', 'gpt'),
+                                default='msdos')
+        bootloader.add_argument('--timeout', type=int)
+        bootloader.add_argument('--source')
+
+        with open(confpath) as conf:
+            lineno = 0
+            for line in conf:
+                line = line.strip()
+                lineno += 1
+                if line and line[0] != '#':
+                    parsed = parser.parse_args(shlex.split(line))
+                    if line.startswith('part'):
+                        self.partitions.append(Partition(parsed, lineno))
+                    else:
+                        if not self.bootloader:
+                             self.bootloader = parsed
+                        else:
+                             raise KickStartError("Error: more than one bootloader specified")
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/9 wic: use new kickstart parser

In reply to Ed Bartosh

Used KickStart parser class instead of pykickstart API.

This commit breaks wic as data structures and field names provided by new API are a bit different from old ones. This issue will be addressed in the following commits.

---
 scripts/lib/wic/conf.py          | 4 ++--
 scripts/lib/wic/imager/direct.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
scripts/lib/wic/conf.py +2 -2
index 1d4363a..2e29451 100644
@@ -17,8 +17,8 @@
 
 import os
 
+from wic.kickstart import KickStart
 from wic import msger
-from wic import kickstart
 from wic.utils import misc
 
 
@@ -87,7 +87,7 @@ class ConfigMgr(object):
         if not ksconf:
             return
 
-        ksobj = kickstart.read_kickstart(ksconf)
+        ksobj = KickStart(ksconf)
 
         self.create['ks'] = ksobj
         self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0]
scripts/lib/wic/imager/direct.py +1 -1
index d5603fa..f89c42c 100644
@@ -27,7 +27,7 @@
 import os
 import shutil
 
-from wic import kickstart, msger
+from wic import msger
 from wic.utils import fs_related
 from wic.utils.oe.misc import get_bitbake_var
 from wic.utils.partitionedfs import Image
Signature · 1 line
2.1.4
author
#4 lore raw

PATCH 4/9 wic: remove pykickstart code

In reply to Ed Bartosh

Removed pykickstart-related code as it's replaced by new kickstart parser.

---
 scripts/lib/wic/3rdparty/pykickstart/__init__.py   |   0
 scripts/lib/wic/3rdparty/pykickstart/base.py       | 466 ----------------
 .../wic/3rdparty/pykickstart/commands/__init__.py  |  20 -
 .../3rdparty/pykickstart/commands/bootloader.py    | 216 -------
 .../wic/3rdparty/pykickstart/commands/partition.py | 314 -----------
 scripts/lib/wic/3rdparty/pykickstart/constants.py  |  57 --
 scripts/lib/wic/3rdparty/pykickstart/errors.py     | 103 ----
 .../wic/3rdparty/pykickstart/handlers/__init__.py  |   0
 .../wic/3rdparty/pykickstart/handlers/control.py   |  46 --
 .../lib/wic/3rdparty/pykickstart/handlers/f16.py   |  24 -
 scripts/lib/wic/3rdparty/pykickstart/ko.py         |  37 --
 scripts/lib/wic/3rdparty/pykickstart/options.py    | 223 --------
 scripts/lib/wic/3rdparty/pykickstart/parser.py     | 619 ---------------------
 scripts/lib/wic/3rdparty/pykickstart/sections.py   | 244 --------
 scripts/lib/wic/3rdparty/pykickstart/version.py    | 168 ------
 scripts/lib/wic/kickstart/__init__.py              | 129 -----
 .../lib/wic/kickstart/custom_commands/__init__.py  |   7 -
 .../lib/wic/kickstart/custom_commands/partition.py | 526 -----------------
 .../lib/wic/kickstart/custom_commands/wicboot.py   |  65 ---
 19 files changed, 3264 deletions(-)
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/__init__.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/base.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/commands/__init__.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/commands/bootloader.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/commands/partition.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/constants.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/errors.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/handlers/__init__.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/handlers/control.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/handlers/f16.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/ko.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/options.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/parser.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/sections.py
 delete mode 100644 scripts/lib/wic/3rdparty/pykickstart/version.py
 delete mode 100644 scripts/lib/wic/kickstart/__init__.py
 delete mode 100644 scripts/lib/wic/kickstart/custom_commands/__init__.py
 delete mode 100644 scripts/lib/wic/kickstart/custom_commands/partition.py
 delete mode 100644 scripts/lib/wic/kickstart/custom_commands/wicboot.py
scripts/lib/wic/3rdparty/pykickstart/__init__.py deleted +0 -0
deleted file mode 100644
index e69de29..0000000
scripts/lib/wic/3rdparty/pykickstart/base.py deleted +0 -466

466 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/commands/__init__.py deleted +0 -20
deleted file mode 100644
index 2d94550..0000000
@@ -1,20 +0,0 @@
-#
-# Chris Lumens <[email protected]>
-#
-# Copyright 2009 Red Hat, Inc.
-#
-# This copyrighted material is made available to anyone wishing to use, modify,
-# copy, or redistribute it subject to the terms and conditions of the GNU
-# General Public License v.2.  This program is distributed in the hope that it
-# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
-# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc., 51
-# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
-# trademarks that are incorporated in the source code or documentation are not
-# subject to the GNU General Public License and may only be used or replicated
-# with the express permission of Red Hat, Inc. 
-#
-import bootloader, partition
scripts/lib/wic/3rdparty/pykickstart/commands/bootloader.py deleted +0 -216

216 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/commands/partition.py deleted +0 -314

314 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/constants.py deleted +0 -57

57 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/errors.py deleted +0 -103

103 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/handlers/__init__.py deleted +0 -0
deleted file mode 100644
index e69de29..0000000
scripts/lib/wic/3rdparty/pykickstart/handlers/control.py deleted +0 -46

46 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/handlers/f16.py deleted +0 -24
deleted file mode 100644
index 3c52f8d..0000000
@@ -1,24 +0,0 @@
-#
-# Chris Lumens <[email protected]>
-#
-# Copyright 2011 Red Hat, Inc.
-#
-# This copyrighted material is made available to anyone wishing to use, modify,
-# copy, or redistribute it subject to the terms and conditions of the GNU
-# General Public License v.2.  This program is distributed in the hope that it
-# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
-# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc., 51
-# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
-# trademarks that are incorporated in the source code or documentation are not
-# subject to the GNU General Public License and may only be used or replicated
-# with the express permission of Red Hat, Inc. 
-#
-from pykickstart.base import *
-from pykickstart.version import *
-
-class F16Handler(BaseHandler):
-    version = F16
scripts/lib/wic/3rdparty/pykickstart/ko.py deleted +0 -37
deleted file mode 100644
index 1350d19..0000000
@@ -1,37 +0,0 @@
-#
-# Chris Lumens <[email protected]>
-#
-# Copyright 2009 Red Hat, Inc.
-#
-# This copyrighted material is made available to anyone wishing to use, modify,
-# copy, or redistribute it subject to the terms and conditions of the GNU
-# General Public License v.2.  This program is distributed in the hope that it
-# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
-# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc., 51
-# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
-# trademarks that are incorporated in the source code or documentation are not
-# subject to the GNU General Public License and may only be used or replicated
-# with the express permission of Red Hat, Inc. 
-#
-"""
-Base classes for internal pykickstart use.
-
-The module exports the following important classes:
-
-    KickstartObject - The base class for all classes in pykickstart
-"""
-
-class KickstartObject(object):
-    """The base class for all other classes in pykickstart."""
-    def __init__(self, *args, **kwargs):
-        """Create a new KickstartObject instance.  All other classes in
-           pykickstart should be derived from this one.  Instance attributes:
-        """
-        pass
-
-    def __str__(self):
-        return ""
scripts/lib/wic/3rdparty/pykickstart/options.py deleted +0 -223

223 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/parser.py deleted +0 -619

619 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/sections.py deleted +0 -244

244 lines not on this page · raw message

scripts/lib/wic/3rdparty/pykickstart/version.py deleted +0 -168

168 lines not on this page · raw message

scripts/lib/wic/kickstart/__init__.py deleted +0 -129

129 lines not on this page · raw message

scripts/lib/wic/kickstart/custom_commands/__init__.py deleted +0 -7
deleted file mode 100644
index e4ae406..0000000
@@ -1,7 +0,0 @@
-from partition import Wic_Partition
-from partition import Wic_PartData
-
-__all__ = (
-    "Wic_Partition",
-    "Wic_PartData",
-)
scripts/lib/wic/kickstart/custom_commands/partition.py deleted +0 -526

327 lines not on this page · raw message

scripts/lib/wic/kickstart/custom_commands/wicboot.py deleted +0 -65

65 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.1.4

Part of the diff is not shown here. View the raw message.

author
#5 lore raw

PATCH 5/9 wic: adjust code for new data structure

In reply to Ed Bartosh

New data structure is less nested than old one.
Adjusted bootloader and partitions fields:
self.ks.handler.bootloader -> self.ks.bootoader
self.ks.handler.partitions -> self.ks.partitions

---
 scripts/lib/wic/imager/baseimager.py                |  2 +-
 scripts/lib/wic/imager/direct.py                    | 16 ++++++++--------
 scripts/lib/wic/plugins/source/bootimg-efi.py       |  2 +-
 scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py |  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)
scripts/lib/wic/imager/baseimager.py +1 -1
index acbe948..760cf8a 100644
@@ -85,7 +85,7 @@ class BaseImageCreator(object):
         # No ks provided when called by convertor, so skip the dependency check
         if self.ks:
             # If we have btrfs partition we need to check necessary tools
-            for part in self.ks.handler.partition.partitions:
+            for part in self.ks.partitions:
                 if part.fstype and part.fstype == "btrfs":
                     self._dep_checks.append("mkfs.btrfs")
                     break
scripts/lib/wic/imager/direct.py +8 -8
index f89c42c..25bab89 100644
@@ -64,7 +64,7 @@ class DirectImageCreator(BaseImageCreator):
         self.__disks = {}
         self.__disk_format = "direct"
         self._disk_names = []
-        self.ptable_format = self.ks.handler.bootloader.ptable
+        self.ptable_format = self.ks.bootloader.ptable
 
         self.oe_builddir = oe_builddir
         if image_output_dir:
@@ -151,12 +151,12 @@ class DirectImageCreator(BaseImageCreator):
                                "please check your kickstart setting.")
 
         # Set a default partition if no partition is given out
-        if not self.ks.handler.partition.partitions:
+        if not self.ks.partitions:
             partstr = "part / --size 1900 --ondisk sda --fstype=ext3"
             args = partstr.split()
-            part = self.ks.handler.partition.parse(args[1:])
-            if part not in self.ks.handler.partition.partitions:
-                self.ks.handler.partition.partitions.append(part)
+            part = self.ks.parse(args[1:])
+            if part not in self.ks.partitions:
+                self.ks.partitions.append(part)
 
         # partitions list from kickstart file
         return kickstart.get_partitions(self.ks)
@@ -206,7 +206,7 @@ class DirectImageCreator(BaseImageCreator):
         bootloader object, the default can be explicitly set using the
         --source bootloader param.
         """
-        return self.ks.handler.bootloader.source
+        return self.ks.bootloader.source
 
     #
     # Actual implemention
@@ -224,8 +224,8 @@ class DirectImageCreator(BaseImageCreator):
         for part in parts:
             # as a convenience, set source to the boot partition source
             # instead of forcing it to be set via bootloader --source
-            if not self.ks.handler.bootloader.source and part.mountpoint == "/boot":
-                self.ks.handler.bootloader.source = part.source
+            if not self.ks.bootloader.source and part.mountpoint == "/boot":
+                self.ks.bootloader.source = part.source
 
         fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
 
scripts/lib/wic/plugins/source/bootimg-efi.py +1 -1
index 5feb79d..556586f 100644
@@ -61,7 +61,7 @@ class BootimgEFIPlugin(SourcePlugin):
 
         if not custom_cfg:
             # Create grub configuration using parameters from wks file
-            options = creator.ks.handler.bootloader.appendLine
+            bootloader = creator.ks.bootloader
 
             grubefi_conf = ""
             grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n"
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +2 -2
index 76e7b03..4280ff7 100644
@@ -78,7 +78,7 @@ class RootfsPlugin(SourcePlugin):
 
         Called before do_prepare_partition()
         """
-        options = image_creator.ks.handler.bootloader.appendLine
+        bootloader = image_creator.ks.bootloader
 
         syslinux_conf = ""
         syslinux_conf += "PROMPT 0\n"
@@ -97,7 +97,7 @@ class RootfsPlugin(SourcePlugin):
         syslinux_conf += "  KERNEL /boot/bzImage\n"
 
         syslinux_conf += "  APPEND label=boot root=%s %s\n" % \
-                             (image_creator.rootdev, options)
+                             (image_creator.rootdev, bootloader.append)
 
         syslinux_cfg = os.path.join(image_creator.rootfs_dir['ROOTFS_DIR'], "boot", "syslinux.cfg")
         msger.debug("Writing syslinux config %s" % syslinux_cfg)
Signature · 1 line
2.1.4
author
#6 lore raw

PATCH 6/9 wic: get rid of get_timeout getter

In reply to Ed Bartosh

Used bootloader.timeout instead of kickstart.get_timeout getter.

Accessing attributes instead of getting them with getters is more pythonic, shorter and readable. It also more consistent as most of partition and bootloader attributes are used this way.

This change also takes care of appendLine bootloader attribute:
it's renamed to bootloader.append attribute provided by new parser.

---
 scripts/lib/wic/plugins/source/bootimg-efi.py        | 18 ++++++------------
 scripts/lib/wic/plugins/source/bootimg-pcbios.py     |  9 ++-------
 scripts/lib/wic/plugins/source/isoimage-isohybrid.py | 16 +++++++---------
 scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py  |  5 +----
 4 files changed, 16 insertions(+), 32 deletions(-)
scripts/lib/wic/plugins/source/bootimg-efi.py +6 -12
index 556586f..35afa30 100644
@@ -66,16 +66,13 @@ class BootimgEFIPlugin(SourcePlugin):
             grubefi_conf = ""
             grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n"
             grubefi_conf += "default=boot\n"
-            timeout = kickstart.get_timeout(creator.ks)
-            if not timeout:
-                timeout = 0
-            grubefi_conf += "timeout=%s\n" % timeout
+            grubefi_conf += "timeout=%s\n" % bootloader.timeout
             grubefi_conf += "menuentry 'boot'{\n"
 
             kernel = "/bzImage"
 
             grubefi_conf += "linux %s root=%s rootwait %s\n" \
-                % (kernel, creator.rootdev, options)
+                % (kernel, creator.rootdev, bootloader.append)
             grubefi_conf += "}\n"
 
         msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \
@@ -95,15 +92,11 @@ class BootimgEFIPlugin(SourcePlugin):
         install_cmd = "install -d %s/loader/entries" % hdddir
         exec_cmd(install_cmd)
 
-        options = creator.ks.handler.bootloader.appendLine
-
-        timeout = kickstart.get_timeout(creator.ks)
-        if not timeout:
-            timeout = 0
+        bootloader = creator.ks.bootloader
 
         loader_conf = ""
         loader_conf += "default boot\n"
-        loader_conf += "timeout %d\n" % timeout
+        loader_conf += "timeout %d\n" % bootloader.timeout
 
         msger.debug("Writing gummiboot config %s/hdd/boot/loader/loader.conf" \
                         % cr_workdir)
@@ -131,7 +124,8 @@ class BootimgEFIPlugin(SourcePlugin):
             boot_conf = ""
             boot_conf += "title boot\n"
             boot_conf += "linux %s\n" % kernel
-            boot_conf += "options LABEL=Boot root=%s %s\n" % (creator.rootdev, options)
+            boot_conf += "options LABEL=Boot root=%s %s\n" % \
+                             (creator.rootdev, bootloader.append)
 
         msger.debug("Writing gummiboot config %s/hdd/boot/loader/entries/boot.conf" \
                         % cr_workdir)
scripts/lib/wic/plugins/source/bootimg-pcbios.py +2 -7
index 80c7dfb..255684b 100644
@@ -105,14 +105,9 @@ class BootimgPcbiosPlugin(SourcePlugin):
             else:
                 splashline = ""
 
-            options = creator.ks.handler.bootloader.appendLine
-
             syslinux_conf = ""
             syslinux_conf += "PROMPT 0\n"
-            timeout = kickstart.get_timeout(creator.ks)
-            if not timeout:
-                timeout = 0
-            syslinux_conf += "TIMEOUT " + str(timeout) + "\n"
+            syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n"
             syslinux_conf += "\n"
             syslinux_conf += "ALLOWOPTIONS 1\n"
             syslinux_conf += "SERIAL 0 115200\n"
@@ -126,7 +121,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
             syslinux_conf += "KERNEL " + kernel + "\n"
 
             syslinux_conf += "APPEND label=boot root=%s %s\n" % \
-                                 (creator.rootdev, options)
+                             (creator.rootdev, bootloader.append)
 
         msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \
                     % cr_workdir)
scripts/lib/wic/plugins/source/isoimage-isohybrid.py +7 -9
index 9472d8a..9ad0bc7 100644
@@ -64,13 +64,11 @@ class IsoImagePlugin(SourcePlugin):
         else:
             splashline = ""
 
-        options = creator.ks.handler.bootloader.appendLine
-
-        timeout = kickstart.get_timeout(creator.ks, 10)
+        bootloader = creator.ks.bootloader
 
         syslinux_conf = ""
         syslinux_conf += "PROMPT 0\n"
-        syslinux_conf += "TIMEOUT %s \n" % timeout
+        syslinux_conf += "TIMEOUT %s \n" % (bootloader.timeout or 10)
         syslinux_conf += "\n"
         syslinux_conf += "ALLOWOPTIONS 1\n"
         syslinux_conf += "SERIAL 0 115200\n"
@@ -82,7 +80,8 @@ class IsoImagePlugin(SourcePlugin):
 
         kernel = "/bzImage"
         syslinux_conf += "KERNEL " + kernel + "\n"
-        syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" % options
+        syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" \
+                             % bootloader.append
 
         msger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg" \
                     % cr_workdir)
@@ -100,14 +99,13 @@ class IsoImagePlugin(SourcePlugin):
         else:
             splashline = ""
 
-        options = creator.ks.handler.bootloader.appendLine
+        bootloader = creator.ks.bootloader
 
         grubefi_conf = ""
         grubefi_conf += "serial --unit=0 --speed=115200 --word=8 "
         grubefi_conf += "--parity=no --stop=1\n"
         grubefi_conf += "default=boot\n"
-        timeout = kickstart.get_timeout(creator.ks, 10)
-        grubefi_conf += "timeout=%s\n" % timeout
+        grubefi_conf += "timeout=%s\n" % (bootloader.timeout or 10)
         grubefi_conf += "\n"
         grubefi_conf += "search --set=root --label %s " % part.label
         grubefi_conf += "\n"
@@ -116,7 +114,7 @@ class IsoImagePlugin(SourcePlugin):
         kernel = "/bzImage"
 
         grubefi_conf += "linux %s rootwait %s\n" \
-            % (kernel, options)
+            % (kernel, bootloader.append)
         grubefi_conf += "initrd /initrd \n"
         grubefi_conf += "}\n"
 
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +1 -4
index 4280ff7..bdf1b54 100644
@@ -83,10 +83,7 @@ class RootfsPlugin(SourcePlugin):
         syslinux_conf = ""
         syslinux_conf += "PROMPT 0\n"
 
-        timeout = kickstart.get_timeout(image_creator.ks)
-        if not timeout:
-            timeout = 0
-        syslinux_conf += "TIMEOUT " + str(timeout) + "\n"
+        syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n"
         syslinux_conf += "ALLOWOPTIONS 1\n"
 
         # Derive SERIAL... line from from kernel boot parameters
Signature · 1 line
2.1.4
author
#7 lore raw

PATCH 7/9 wic: get rid of get_rootfs and set_rootfs

In reply to Ed Bartosh

Got rid of get_rootfs and set_rootfs java-like getter and setter. Renamed rootfs to rootfs_dir to be consistent with the name of kickstart parameter --rootfs-dir.

---
 scripts/lib/wic/imager/direct.py                     |  6 +++---
 scripts/lib/wic/plugins/source/isoimage-isohybrid.py | 14 +++++++-------
 scripts/lib/wic/plugins/source/rootfs.py             | 14 +++++++-------
 scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py  |  2 +-
 4 files changed, 18 insertions(+), 18 deletions(-)
scripts/lib/wic/imager/direct.py +3 -3
index 25bab89..09ff5f8 100644
@@ -233,7 +233,7 @@ class DirectImageCreator(BaseImageCreator):
             # get rootfs size from bitbake variable if it's not set in .ks file
             if not part.size:
                 # and if rootfs name is specified for the partition
-                image_name = part.get_rootfs()
+                image_name = part.rootfs_dir
                 if image_name:
                     # Bitbake variable ROOTFS_SIZE is calculated in
                     # Image._get_rootfs_size method from meta/lib/oe/image.py
@@ -336,13 +336,13 @@ class DirectImageCreator(BaseImageCreator):
 
         msg += 'The following build artifacts were used to create the image(s):\n'
         for part in parts:
-            if part.get_rootfs() is None:
+            if part.rootfs_dir is None:
                 continue
             if part.mountpoint == '/':
                 suffix = ':'
             else:
                 suffix = '["%s"]:' % (part.mountpoint or part.label)
-            msg += '  ROOTFS_DIR%s%s\n' % (suffix.ljust(20), part.get_rootfs())
+            msg += '  ROOTFS_DIR%s%s\n' % (suffix.ljust(20), part.rootfs_dir)
 
         msg += '  BOOTIMG_DIR:                  %s\n' % self.bootimg_dir
         msg += '  KERNEL_DIR:                   %s\n' % self.kernel_dir
scripts/lib/wic/plugins/source/isoimage-isohybrid.py +7 -7
index 9ad0bc7..b5ca4d3 100644
@@ -262,26 +262,26 @@ class IsoImagePlugin(SourcePlugin):
 
         isodir = "%s/ISO" % cr_workdir
 
-        if part.rootfs is None:
+        if part.rootfs_dir is None:
             if not 'ROOTFS_DIR' in rootfs_dir:
                 msger.error("Couldn't find --rootfs-dir, exiting.\n")
             rootfs_dir = rootfs_dir['ROOTFS_DIR']
         else:
-            if part.rootfs in rootfs_dir:
-                rootfs_dir = rootfs_dir[part.rootfs]
-            elif part.rootfs:
-                rootfs_dir = part.rootfs
+            if part.rootfs_dir in rootfs_dir:
+                rootfs_dir = rootfs_dir[part.rootfs_dir]
+            elif part.rootfs_dir:
+                rootfs_dir = part.rootfs_dir
             else:
                 msg = "Couldn't find --rootfs-dir=%s connection "
                 msg += "or it is not a valid path, exiting.\n"
-                msger.error(msg % part.rootfs)
+                msger.error(msg % part.rootfs_dir)
 
         if not os.path.isdir(rootfs_dir):
             rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
         if not os.path.isdir(rootfs_dir):
             msger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")
 
-        part.set_rootfs(rootfs_dir)
+        part.rootfs_dir = rootfs_dir
 
         # Prepare rootfs.img
         hdd_dir = get_bitbake_var("HDDDIR")
scripts/lib/wic/plugins/source/rootfs.py +7 -7
index a90712b..425da8b 100644
@@ -61,23 +61,23 @@ class RootfsPlugin(SourcePlugin):
         'prepares' the partition to be incorporated into the image.
         In this case, prepare content for legacy bios boot partition.
         """
-        if part.rootfs is None:
+        if part.rootfs_dir is None:
             if not 'ROOTFS_DIR' in krootfs_dir:
                 msg = "Couldn't find --rootfs-dir, exiting"
                 msger.error(msg)
             rootfs_dir = krootfs_dir['ROOTFS_DIR']
         else:
-            if part.rootfs in krootfs_dir:
-                rootfs_dir = krootfs_dir[part.rootfs]
-            elif part.rootfs:
-                rootfs_dir = part.rootfs
+            if part.rootfs_dir in krootfs_dir:
+                rootfs_dir = krootfs_dir[part.rootfs_dir]
+            elif part.rootfs_dir:
+                rootfs_dir = part.rootfs_dir
             else:
                 msg = "Couldn't find --rootfs-dir=%s connection"
                 msg += " or it is not a valid path, exiting"
-                msger.error(msg % part.rootfs)
+                msger.error(msg % part.rootfs_dir)
 
         real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)
 
-        part.set_rootfs(real_rootfs_dir)
+        part.rootfs_dir = real_rootfs_dir
         part.prepare_rootfs(cr_workdir, oe_builddir, real_rootfs_dir, native_sysroot)
 
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +1 -1
index bdf1b54..48b4817 100644
@@ -141,7 +141,7 @@ class RootfsPlugin(SourcePlugin):
 
         real_rootfs_dir = cls._get_rootfs_dir(rootfs_dir)
 
-        part.set_rootfs(real_rootfs_dir)
+        part.rootfs_dir = real_rootfs_dir
         part.prepare_rootfs(image_creator_workdir, oe_builddir, real_rootfs_dir, native_sysroot)
 
         # install syslinux into rootfs partition
Signature · 1 line
2.1.4
author
#8 lore raw

PATCH 8/9 wic: get rid of set_size and set_source_file setters

In reply to Ed Bartosh

Used size and source_file attributes instead of using setters. It's more pythonic, clear an consistent.

---
 scripts/lib/wic/plugins/source/bootimg-efi.py        | 4 ++--
 scripts/lib/wic/plugins/source/bootimg-pcbios.py     | 4 ++--
 scripts/lib/wic/plugins/source/isoimage-isohybrid.py | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)
scripts/lib/wic/plugins/source/bootimg-efi.py +2 -2
index 35afa30..8bfa3a9 100644
@@ -235,5 +235,5 @@ class BootimgEFIPlugin(SourcePlugin):
         out = exec_cmd(du_cmd)
         bootimg_size = out.split()[0]
 
-        part.set_size(bootimg_size)
-        part.set_source_file(bootimg)
+        part.size = bootimg_size
+        part.source_file = bootimg
scripts/lib/wic/plugins/source/bootimg-pcbios.py +2 -2
index 255684b..e84bddf 100644
@@ -205,7 +205,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
         out = exec_cmd(du_cmd)
         bootimg_size = out.split()[0]
 
-        part.set_size(bootimg_size)
-        part.set_source_file(bootimg)
+        part.size = int(out.split()[0])
+        part.source_file = bootimg
 
 
scripts/lib/wic/plugins/source/isoimage-isohybrid.py +3 -3
index b5ca4d3..daefff3 100644
@@ -302,7 +302,7 @@ class IsoImagePlugin(SourcePlugin):
             # which contains rootfs
             du_cmd = "du -bks %s" % rootfs_dir
             out = exec_cmd(du_cmd)
-            part.set_size(int(out.split()[0]))
+            part.size = int(out.split()[0])
             part.extra_space = 0
             part.overhead_factor = 1.2
             part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, \
@@ -502,8 +502,8 @@ class IsoImagePlugin(SourcePlugin):
         out = exec_cmd(du_cmd)
         isoimg_size = int(out.split()[0])
 
-        part.set_size(isoimg_size)
-        part.set_source_file(iso_img)
+        part.size = isoimg_size
+        part.source_file = iso_img
 
     @classmethod
     def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
Signature · 1 line
2.1.4
author
#9 lore raw

PATCH 9/9 wic: get rid of 2 getters

In reply to Ed Bartosh

Used partitions and configfile bootloader attributes instead of using getters get_bootloader_file and get_partitions.

---
 scripts/lib/wic/imager/direct.py                 |  2 +-
 scripts/lib/wic/plugins/source/bootimg-efi.py    |  4 ++--
 scripts/lib/wic/plugins/source/bootimg-pcbios.py | 11 ++++++-----
 3 files changed, 9 insertions(+), 8 deletions(-)
scripts/lib/wic/imager/direct.py +1 -1
index 09ff5f8..8d4daec 100644
@@ -159,7 +159,7 @@ class DirectImageCreator(BaseImageCreator):
                 self.ks.partitions.append(part)
 
         # partitions list from kickstart file
-        return kickstart.get_partitions(self.ks)
+        return self.ks.partitions
 
     def get_disk_names(self):
         """ Returns a list of physical target disk names (e.g., 'sdb') which
scripts/lib/wic/plugins/source/bootimg-efi.py +2 -2
index 8bfa3a9..22f9813 100644
@@ -46,7 +46,7 @@ class BootimgEFIPlugin(SourcePlugin):
         """
         Create loader-specific (grub-efi) config
         """
-        configfile = kickstart.get_bootloader_file(creator.ks)
+        configfile = creator.ks.bootloader.configfile
         custom_cfg = None
         if configfile:
             custom_cfg = get_custom_config(configfile)
@@ -104,7 +104,7 @@ class BootimgEFIPlugin(SourcePlugin):
         cfg.write(loader_conf)
         cfg.close()
 
-        configfile = kickstart.get_bootloader_file(creator.ks)
+        configfile = creator.ks.bootloader.configfile
         custom_cfg = None
         if configfile:
             custom_cfg = get_custom_config(configfile)
scripts/lib/wic/plugins/source/bootimg-pcbios.py +6 -5
index e84bddf..0b5478e 100644
@@ -84,18 +84,19 @@ class BootimgPcbiosPlugin(SourcePlugin):
         install_cmd = "install -d %s" % hdddir
         exec_cmd(install_cmd)
 
-        configfile = kickstart.get_bootloader_file(creator.ks)
+        bootloader = creator.ks.bootloader
+
         custom_cfg = None
-        if configfile:
-            custom_cfg = get_custom_config(configfile)
+        if bootloader.configfile:
+            custom_cfg = get_custom_config(bootloader.configfile)
             if custom_cfg:
                 # Use a custom configuration for grub
                 syslinux_conf = custom_cfg
                 msger.debug("Using custom configuration file "
-                        "%s for syslinux.cfg" % configfile)
+                            "%s for syslinux.cfg" % bootloader.configfile)
             else:
                 msger.error("configfile is specified but failed to "
-                        "get it from %s." % configfile)
+                            "get it from %s." % bootloader.configfile)
 
         if not custom_cfg:
             # Create syslinux configuration using parameters from wks file
Signature · 1 line
2.1.4