public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Alexander Smirnov <asmirnov@ilbers.de>
To: Henning Schild <henning.schild@siemens.com>, isar-users@googlegroups.com
Subject: Re: [PATCH 9/9] wic: now truly go for the wic version we claim to have
Date: Wed, 31 Jan 2018 13:11:11 +0300	[thread overview]
Message-ID: <df52d78d-d1dd-aaf5-44e9-6876ca1ea4ab@ilbers.de> (raw)
In-Reply-To: <540bb04ce24f67c121c83801288a3aea6f4cedac.1517390790.git.henning.schild@siemens.com>

On 01/31/2018 12:42 PM, Henning Schild wrote:
> 2b164b18fd639c9 claims to introduce wic hash 131629ca6238ea05
> This commit really carries that version of wic.
> 
> Issue:
>   - the wic version in Isar was modified
>   - that causes:
>    - confusion, maintainability and updateability issues
>    - potential quality issues
> 
> Impact:
>   This patch and the previous reverts get wic back to a state where all
>   these Issues are solved. We could now just update our wic without having
>   to worry about local patches. In case of a wic-update Isar and layers
>   on top would still have to review their plugins.

Does upstream wic script rely on the content from lib/plugins?

For example some recent commit updates both:

https://github.com/openembedded/openembedded-core/commit/00420ec42140c1b752132bda190dede85756d157#diff-df4a70bc146d3159891d7a410f2521a1

So due to customized plugins below we should worry and keep this in mind.

Alex

> 
> Signed-off-by: Henning Schild <henning.schild@siemens.com>
> ---
>   scripts/lib/wic/canned-wks/qemux86-directdisk.wks |   2 +-
>   scripts/lib/wic/filemap.py                        |   6 +-
>   scripts/lib/wic/help.py                           |   2 -
>   scripts/lib/wic/ksparser.py                       |   4 +-
>   scripts/lib/wic/partition.py                      | 114 ++++++++++++++--------
>   scripts/lib/wic/plugins/imager/direct.py          |  17 +++-
>   scripts/lib/wic/plugins/source/bootimg-pcbios.py  |  48 ++++-----
>   scripts/lib/wic/plugins/source/fsimage.py         |  56 +++++++++++
>   scripts/lib/wic/utils/misc.py                     |  16 +--
>   scripts/lib/wic/utils/runner.py                   |  74 ++++++++++++--
>   10 files changed, 250 insertions(+), 89 deletions(-)
>   create mode 100644 scripts/lib/wic/plugins/source/fsimage.py
> 
> diff --git a/scripts/lib/wic/canned-wks/qemux86-directdisk.wks b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks
> index db30bbc..a6518a0 100644
> --- a/scripts/lib/wic/canned-wks/qemux86-directdisk.wks
> +++ b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks
> @@ -4,5 +4,5 @@
>   
>   include common.wks.inc
>   
> -bootloader  --timeout=0  --append="vga=0 uvesafb.mode_option=640x480-32 root=/dev/sda2 rw mem=256M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 rootfstype=ext4 "
> +bootloader  --timeout=0  --append="vga=0 uvesafb.mode_option=640x480-32 root=/dev/vda2 rw mem=256M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 rootfstype=ext4 "
>   
> diff --git a/scripts/lib/wic/filemap.py b/scripts/lib/wic/filemap.py
> index 1f1aacc..080668e 100644
> --- a/scripts/lib/wic/filemap.py
> +++ b/scripts/lib/wic/filemap.py
> @@ -530,11 +530,9 @@ def filemap(image, log=None):
>       except ErrorNotSupp:
>           return FilemapSeek(image, log)
>   
> -def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None):
> +def sparse_copy(src_fname, dst_fname, offset=0, skip=0):
>       """Efficiently copy sparse file to or into another file."""
> -    if not api:
> -        api = filemap
> -    fmap = api(src_fname)
> +    fmap = filemap(src_fname)
>       try:
>           dst_file = open(dst_fname, 'r+b')
>       except IOError:
> diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
> index aee2451..148da89 100644
> --- a/scripts/lib/wic/help.py
> +++ b/scripts/lib/wic/help.py
> @@ -687,8 +687,6 @@ DESCRIPTION
>              apply to partitions created using '--source rootfs' (see
>              --source above).  Valid values are:
>   
> -             vfat
> -             msdos
>                ext2
>                ext3
>                ext4
> diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
> index d026caa..a039300 100644
> --- a/scripts/lib/wic/ksparser.py
> +++ b/scripts/lib/wic/ksparser.py
> @@ -136,9 +136,7 @@ class KickStart():
>           part.add_argument('--exclude-path', nargs='+')
>           part.add_argument("--extra-space", type=sizetype)
>           part.add_argument('--fsoptions', dest='fsopts')
> -        part.add_argument('--fstype', default='vfat',
> -                          choices=('ext2', 'ext3', 'ext4', 'btrfs',
> -                                   'squashfs', 'vfat', 'msdos', 'swap'))
> +        part.add_argument('--fstype')
>           part.add_argument('--label')
>           part.add_argument('--no-table', action='store_true')
>           part.add_argument('--ondisk', '--ondrive', dest='disk', default='sda')
> diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
> index 939e667..8e32afc 100644
> --- a/scripts/lib/wic/partition.py
> +++ b/scripts/lib/wic/partition.py
> @@ -136,24 +136,22 @@ class Partition():
>                                  "specify a non-zero --size/--fixed-size for that "
>                                  "partition." % self.mountpoint)
>   
> -            if self.fstype == "swap":
> +            if self.fstype and self.fstype == "swap":
>                   self.prepare_swap_partition(cr_workdir, oe_builddir,
>                                               native_sysroot)
>                   self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype)
> -            else:
> -                if self.fstype == 'squashfs':
> -                    raise WicError("It's not possible to create empty squashfs "
> -                                   "partition '%s'" % (self.mountpoint))
> -
> +            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)
> -
> -                prefix = "ext" if self.fstype.startswith("ext") else self.fstype
> -                method = getattr(self, "prepare_empty_partition_" + prefix)
> -                method(rootfs, oe_builddir, native_sysroot)
> -                self.source_file = 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_plugins('source')
> @@ -195,6 +193,19 @@ class Partition():
>                              "larger (%d kB) than its allowed size %d kB" %
>                              (self.mountpoint, self.size, self.fixed_size))
>   
> +    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 = int(rootfs_size)
> +        self.source_file = rootfs
> +
>       def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
>                          native_sysroot):
>           """
> @@ -219,6 +230,10 @@ class Partition():
>           if os.path.isfile(rootfs):
>               os.remove(rootfs)
>   
> +        if not self.fstype:
> +            raise WicError("File system for partition %s not specified in "
> +                           "kickstart, use --fstype option" % self.mountpoint)
> +
>           # Get rootfs size from bitbake variable if it's not set in .ks file
>           if not self.size:
>               # Bitbake variable ROOTFS_SIZE is calculated in
> @@ -233,15 +248,19 @@ class Partition():
>                                  '--overhead-factor will be applied')
>                   self.size = int(round(float(rsize_bb)))
>   
> -        prefix = "ext" if self.fstype.startswith("ext") else self.fstype
> -        method = getattr(self, "prepare_rootfs_" + prefix)
> -        method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)
> -        self.source_file = 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)
>   
> -        # get the rootfs size in the right units for kickstart (kB)
> -        du_cmd = "du -Lbks %s" % rootfs
> -        out = exec_cmd(du_cmd)
> -        self.size = int(out.split()[0])
> +                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 = int(out.split()[0])
> +
> +                break
>   
>       def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
>                              native_sysroot, pseudo):
> @@ -267,7 +286,7 @@ class Partition():
>               (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
>           exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
>   
> -        mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
> +        mkfs_cmd = "fsck.%s -fy %s" % (self.fstype, rootfs)
>           exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
>   
>       def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
> @@ -294,10 +313,10 @@ class Partition():
>               (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs)
>           exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
>   
> -    def prepare_rootfs_msdos(self, rootfs, oe_builddir, rootfs_dir,
> -                             native_sysroot, pseudo):
> +    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
> +                            native_sysroot, pseudo):
>           """
> -        Prepare content for a msdos/vfat rootfs partition.
> +        Prepare content for a vfat rootfs partition.
>           """
>           du_cmd = "du -bks %s" % rootfs_dir
>           out = exec_cmd(du_cmd)
> @@ -309,12 +328,7 @@ class Partition():
>           if self.label:
>               label_str = "-n %s" % self.label
>   
> -        size_str = ""
> -        if self.fstype == 'msdos':
> -            size_str = "-F 16" # FAT 16
> -
> -        dosfs_cmd = "mkdosfs %s -S 512 %s -C %s %d" % (label_str, size_str,
> -                                                       rootfs, rootfs_size)
> +        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, rootfs_size)
>           exec_native_cmd(dosfs_cmd, native_sysroot)
>   
>           mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
> @@ -323,8 +337,6 @@ class Partition():
>           chmod_cmd = "chmod 644 %s" % rootfs
>           exec_cmd(chmod_cmd)
>   
> -    prepare_rootfs_vfat = prepare_rootfs_msdos
> -
>       def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
>                                   native_sysroot, pseudo):
>           """
> @@ -370,8 +382,8 @@ class Partition():
>               (self.fstype, self.size * 1024, label_str, rootfs)
>           exec_native_cmd(mkfs_cmd, native_sysroot)
>   
> -    def prepare_empty_partition_msdos(self, rootfs, oe_builddir,
> -                                      native_sysroot):
> +    def prepare_empty_partition_vfat(self, rootfs, oe_builddir,
> +                                     native_sysroot):
>           """
>           Prepare an empty vfat partition.
>           """
> @@ -381,18 +393,40 @@ class Partition():
>           if self.label:
>               label_str = "-n %s" % self.label
>   
> -        size_str = ""
> -        if self.fstype == 'msdos':
> -            size_str = "-F 16" # FAT 16
> -
> -        dosfs_cmd = "mkdosfs %s -S 512 %s -C %s %d" % (label_str, size_str,
> -                                                       rootfs, blocks)
> +        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)
>   
> -    prepare_empty_partition_vfat = prepare_empty_partition_msdos
> +    def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
> +                                         native_sysroot):
> +        """
> +        Prepare an empty squashfs partition.
> +        """
> +        logger.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)
> +        if os.path.isfile(path):
> +            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 = int(fs_size)
>   
>       def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
>           """
> diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
> index f2e6127..7d38ab3 100644
> --- a/scripts/lib/wic/plugins/imager/direct.py
> +++ b/scripts/lib/wic/plugins/imager/direct.py
> @@ -323,7 +323,7 @@ class PartitionedImage():
>                   if self.ptable_format == 'gpt':
>                       part.uuid = str(uuid.uuid4())
>                   else: # msdos partition table
> -                    part.uuid = '%08x-%02d' % (self.identifier, part.realnum)
> +                    part.uuid = '%0x-%02d' % (self.identifier, part.realnum)
>   
>       def prepare(self, imager):
>           """Prepare an image. Call prepare method of all image partitions."""
> @@ -487,8 +487,8 @@ class PartitionedImage():
>                   parted_fs_type = "fat32"
>               elif part.fstype == "msdos":
>                   parted_fs_type = "fat16"
> -                if not part.system_id:
> -                    part.system_id = '0x6' # FAT16
> +            elif part.fstype == "ontrackdm6aux3":
> +                parted_fs_type = "ontrackdm6aux3"
>               else:
>                   # Type for ext2/ext3/ext4/btrfs
>                   parted_fs_type = "ext2"
> @@ -538,6 +538,17 @@ class PartitionedImage():
>                                   (self.path, part.num, part.system_id),
>                                   self.native_sysroot)
>   
> +            # Parted defaults to enabling the lba flag for fat16 partitions,
> +            # which causes compatibility issues with some firmware (and really
> +            # isn't necessary).
> +            if parted_fs_type == "fat16":
> +                if self.ptable_format == 'msdos':
> +                    logger.debug("Disable 'lba' flag for partition '%s' on disk '%s'",
> +                                 part.num, self.path)
> +                    exec_native_cmd("parted -s %s set %d lba off" % \
> +                                    (self.path, part.num),
> +                                    self.native_sysroot)
> +
>       def cleanup(self):
>           # remove partition images
>           for image in set(self.partimages):
> diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
> index 5890c12..11db304 100644
> --- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py
> +++ b/scripts/lib/wic/plugins/source/bootimg-pcbios.py
> @@ -44,16 +44,19 @@ class BootimgPcbiosPlugin(SourcePlugin):
>       name = 'bootimg-pcbios'
>   
>       @classmethod
> -    def _get_bootimg_dir(cls, bootimg_dir, dirname):
> +    def _get_syslinux_dir(cls, bootimg_dir):
>           """
> -        Check if dirname exists in default bootimg_dir or
> -        in wic-tools STAGING_DIR.
> +        Get path to syslinux from either default bootimg_dir
> +        or wic-tools STAGING_DIR.
>           """
> -        for result in (bootimg_dir, get_bitbake_var("STAGING_DATADIR", "wic-tools")):
> -            if os.path.exists("%s/%s" % (result, dirname)):
> -                return result
> +        for path in (bootimg_dir, get_bitbake_var("STAGING_DATADIR", "wic-tools")):
> +            if not path:
> +                continue
> +            syslinux_dir = os.path.join(path, 'syslinux')
> +            if os.path.exists(syslinux_dir):
> +                return syslinux_dir
>   
> -        raise WicError("Couldn't find correct bootimg_dir, exiting")
> +        raise WicError("Couldn't find syslinux directory, exiting")
>   
>       @classmethod
>       def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
> @@ -62,12 +65,11 @@ class BootimgPcbiosPlugin(SourcePlugin):
>           Called after all partitions have been prepared and assembled into a
>           disk image.  In this case, we install the MBR.
>           """
> -        bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux')
> -        mbrfile = "%s/syslinux/" % bootimg_dir
> +        syslinux_dir = cls._get_syslinux_dir(bootimg_dir)
>           if creator.ptable_format == 'msdos':
> -            mbrfile += "mbr.bin"
> +            mbrfile = os.path.join(syslinux_dir, "mbr.bin")
>           elif creator.ptable_format == 'gpt':
> -            mbrfile += "gptmbr.bin"
> +            mbrfile = os.path.join(syslinux_dir, "gptmbr.bin")
>           else:
>               raise WicError("Unsupported partition table: %s" %
>                              creator.ptable_format)
> @@ -81,8 +83,10 @@ class BootimgPcbiosPlugin(SourcePlugin):
>           logger.debug("Installing MBR on disk %s as %s with size %s bytes",
>                        disk_name, full_path, disk.min_size)
>   
> -        dd_cmd = "dd if=%s of=%s conv=notrunc" % (mbrfile, full_path)
> -        exec_cmd(dd_cmd, native_sysroot)
> +        rcode = runner.show(['dd', 'if=%s' % mbrfile,
> +                             'of=%s' % full_path, 'conv=notrunc'])
> +        if rcode != 0:
> +            raise WicError("Unable to set MBR to %s" % full_path)
>   
>       @classmethod
>       def do_configure_partition(cls, part, source_params, creator, cr_workdir,
> @@ -151,7 +155,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
>           'prepares' the partition to be incorporated into the image.
>           In this case, prepare content for legacy bios boot partition.
>           """
> -        bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux')
> +        syslinux_dir = cls._get_syslinux_dir(bootimg_dir)
>   
>           staging_kernel_dir = kernel_dir
>   
> @@ -159,14 +163,14 @@ class BootimgPcbiosPlugin(SourcePlugin):
>   
>           cmds = ("install -m 0644 %s/bzImage %s/vmlinuz" %
>                   (staging_kernel_dir, hdddir),
> -                "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" %
> -                (bootimg_dir, hdddir),
> -                "install -m 0644 %s/syslinux/vesamenu.c32 %s/vesamenu.c32" %
> -                (bootimg_dir, hdddir),
> -                "install -m 444 %s/syslinux/libcom32.c32 %s/libcom32.c32" %
> -                (bootimg_dir, hdddir),
> -                "install -m 444 %s/syslinux/libutil.c32 %s/libutil.c32" %
> -                (bootimg_dir, hdddir))
> +                "install -m 444 %s/ldlinux.sys %s/ldlinux.sys" %
> +                (syslinux_dir, hdddir),
> +                "install -m 0644 %s/vesamenu.c32 %s/vesamenu.c32" %
> +                (syslinux_dir, hdddir),
> +                "install -m 444 %s/libcom32.c32 %s/libcom32.c32" %
> +                (syslinux_dir, hdddir),
> +                "install -m 444 %s/libutil.c32 %s/libutil.c32" %
> +                (syslinux_dir, hdddir))
>   
>           for install_cmd in cmds:
>               exec_cmd(install_cmd)
> diff --git a/scripts/lib/wic/plugins/source/fsimage.py b/scripts/lib/wic/plugins/source/fsimage.py
> new file mode 100644
> index 0000000..f781499
> --- /dev/null
> +++ b/scripts/lib/wic/plugins/source/fsimage.py
> @@ -0,0 +1,56 @@
> +# ex:ts=4:sw=4:sts=4:et
> +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
> +#
> +# 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.
> +#
> +
> +import logging
> +import os
> +
> +from wic import WicError
> +from wic.pluginbase import SourcePlugin
> +from wic.utils.misc import get_bitbake_var
> +
> +logger = logging.getLogger('wic')
> +
> +class FSImagePlugin(SourcePlugin):
> +    """
> +    Add an already existing filesystem image to the partition layout.
> +    """
> +
> +    name = 'fsimage'
> +
> +    @classmethod
> +    def do_prepare_partition(cls, part, source_params, cr, cr_workdir,
> +                             oe_builddir, bootimg_dir, kernel_dir,
> +                             rootfs_dir, native_sysroot):
> +        """
> +        Called to do the actual content population for a partition i.e. it
> +        'prepares' the partition to be incorporated into the image.
> +        """
> +        if not bootimg_dir:
> +            bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
> +            if not bootimg_dir:
> +                raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
> +
> +        logger.debug('Bootimg dir: %s', bootimg_dir)
> +
> +        if 'file' not in source_params:
> +            raise WicError("No file specified")
> +
> +        src = os.path.join(bootimg_dir, source_params['file'])
> +
> +
> +        logger.debug('Preparing partition using image %s', src)
> +        part.prepare_rootfs_from_fs_image(cr_workdir, src, "")
> diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/utils/misc.py
> index 4609984..c941112 100644
> --- a/scripts/lib/wic/utils/misc.py
> +++ b/scripts/lib/wic/utils/misc.py
> @@ -59,7 +59,7 @@ NATIVE_RECIPES = {"bmaptool": "bmap-tools",
>                     "syslinux": "syslinux"
>                    }
>   
> -def _exec_cmd(cmd_and_args, as_shell=False):
> +def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
>       """
>       Execute command, catching stderr, stdout
>   
> @@ -70,9 +70,9 @@ def _exec_cmd(cmd_and_args, as_shell=False):
>       logger.debug(args)
>   
>       if as_shell:
> -        ret, out = runner.runtool(cmd_and_args)
> +        ret, out = runner.runtool(cmd_and_args, catch)
>       else:
> -        ret, out = runner.runtool(args)
> +        ret, out = runner.runtool(args, catch)
>       out = out.strip()
>       if ret != 0:
>           raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
> @@ -84,14 +84,14 @@ def _exec_cmd(cmd_and_args, as_shell=False):
>       return ret, out
>   
>   
> -def exec_cmd(cmd_and_args, as_shell=False):
> +def exec_cmd(cmd_and_args, as_shell=False, catch=3):
>       """
>       Execute command, return output
>       """
> -    return _exec_cmd(cmd_and_args, as_shell)[1]
> +    return _exec_cmd(cmd_and_args, as_shell, catch)[1]
>   
>   
> -def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""):
> +def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
>       """
>       Execute native command, catching stderr, stdout
>   
> @@ -118,7 +118,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""):
>   
>       # If the command isn't in the native sysroot say we failed.
>       if spawn.find_executable(args[0], native_paths):
> -        ret, out = _exec_cmd(native_cmd_and_args, True)
> +        ret, out = _exec_cmd(native_cmd_and_args, True, catch)
>       else:
>           ret = 127
>           out = "can't find native executable %s in %s" % (args[0], native_paths)
> @@ -131,7 +131,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""):
>                 "was not found (see details above).\n\n" % prog
>           recipe = NATIVE_RECIPES.get(prog)
>           if recipe:
> -            msg += "Please make sure wic-tools have %s-native in its DEPENDS, bake it with 'bitbake wic-tools' "\
> +            msg += "Please bake it with 'bitbake %s-native' "\
>                      "and try again.\n" % recipe
>           else:
>               msg += "Wic failed to find a recipe to build native %s. Please "\
> diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py
> index 4aa00fb..56d7ea3 100644
> --- a/scripts/lib/wic/utils/runner.py
> +++ b/scripts/lib/wic/utils/runner.py
> @@ -14,17 +14,32 @@
>   # 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.
> +
> +import logging
> +import os
>   import subprocess
>   
>   from wic import WicError
>   
> -def runtool(cmdln_or_args):
> +logger = logging.getLogger('wic')
> +
> +def runtool(cmdln_or_args, catch=1):
>       """ wrapper for most of the subprocess calls
>       input:
>           cmdln_or_args: can be both args and cmdln str (shell=True)
> +        catch: 0, quitely run
> +               1, only STDOUT
> +               2, only STDERR
> +               3, both STDOUT and STDERR
>       return:
> -        rc, output
> +        (rc, output)
> +        if catch==0: the output will always None
>       """
> +
> +    if catch not in (0, 1, 2, 3):
> +        # invalid catch selection, will cause exception, that's good
> +        return None
> +
>       if isinstance(cmdln_or_args, list):
>           cmd = cmdln_or_args[0]
>           shell = False
> @@ -33,13 +48,26 @@ def runtool(cmdln_or_args):
>           cmd = shlex.split(cmdln_or_args)[0]
>           shell = True
>   
> -    sout = subprocess.PIPE
> -    serr = subprocess.STDOUT
> +    if catch != 3:
> +        dev_null = os.open("/dev/null", os.O_WRONLY)
> +
> +    if catch == 0:
> +        sout = dev_null
> +        serr = dev_null
> +    elif catch == 1:
> +        sout = subprocess.PIPE
> +        serr = dev_null
> +    elif catch == 2:
> +        sout = dev_null
> +        serr = subprocess.PIPE
> +    elif catch == 3:
> +        sout = subprocess.PIPE
> +        serr = subprocess.STDOUT
>   
>       try:
>           process = subprocess.Popen(cmdln_or_args, stdout=sout,
>                                      stderr=serr, shell=shell)
> -        sout, serr = process.communicate()
> +        (sout, serr) = process.communicate()
>           # combine stdout and stderr, filter None out and decode
>           out = ''.join([out.decode('utf-8') for out in [sout, serr] if out])
>       except OSError as err:
> @@ -48,5 +76,39 @@ def runtool(cmdln_or_args):
>               raise WicError('Cannot run command: %s, lost dependency?' % cmd)
>           else:
>               raise # relay
> +    finally:
> +        if catch != 3:
> +            os.close(dev_null)
> +
> +    return (process.returncode, out)
> +
> +def show(cmdln_or_args):
> +    """Show all messages using logger.debug."""
> +
> +    rcode, out = runtool(cmdln_or_args, catch=3)
> +
> +    if isinstance(cmdln_or_args, list):
> +        cmd = ' '.join(cmdln_or_args)
> +    else:
> +        cmd = cmdln_or_args
> +
> +    msg = 'running command: "%s"' % cmd
> +    if out:
> +        out = out.strip()
> +    if out:
> +        msg += ', with output::'
> +        msg += '\n  +----------------'
> +        for line in out.splitlines():
> +            msg += '\n  | %s' % line
> +        msg += '\n  +----------------'
> +
> +    logger.debug(msg)
> +
> +    return rcode
> +
> +def outs(cmdln_or_args, catch=1):
> +    # get the outputs of tools
> +    return runtool(cmdln_or_args, catch)[1].strip()
>   
> -    return process.returncode, out
> +def quiet(cmdln_or_args):
> +    return runtool(cmdln_or_args, catch=0)[0]
> 

-- 
With best regards,
Alexander Smirnov

ilbers GmbH
Baierbrunner Str. 28c
D-81379 Munich
+49 (89) 122 67 24-0
http://ilbers.de/
Commercial register Munich, HRB 214197
General manager: Baurzhan Ismagulov

  reply	other threads:[~2018-01-31 10:11 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-31  9:41 [PATCH 0/9] first wic integration Henning Schild
2018-01-31  9:41 ` [PATCH 1/9] classes: image: introduce size measuring function, for before do_*_image Henning Schild
2018-01-31  9:41 ` [PATCH 2/9] images: new class wic-img for wic intregration Henning Schild
2018-02-13 14:44   ` Alexander Smirnov
2018-02-13 16:06     ` Henning Schild
2018-01-31  9:41 ` [PATCH 3/9] wic: add a bootimg-efi-isar plugin outside the wic tree Henning Schild
2018-02-12 17:48   ` Jan Kiszka
2018-01-31  9:41 ` [PATCH 4/9] Revert "wic: Make the bootimg-efi plugin generate usable images" Henning Schild
2018-01-31  9:41 ` [PATCH 5/9] Revert "wic: Introduce the `WicExecError` exception class" Henning Schild
2018-01-31  9:41 ` [PATCH 6/9] Revert "wic: Work around mcopy error" Henning Schild
2018-01-31  9:41 ` [PATCH 7/9] Revert "wic: Use sudo instead of pseudo" Henning Schild
2018-01-31  9:41 ` [PATCH 8/9] Revert "wic: Remove sysroot support" Henning Schild
2018-01-31  9:42 ` [PATCH 9/9] wic: now truly go for the wic version we claim to have Henning Schild
2018-01-31 10:11   ` Alexander Smirnov [this message]
2018-01-31 10:55     ` Jan Kiszka
2018-01-31 11:11       ` Alexander Smirnov
2018-01-31 11:43         ` Jan Kiszka
2018-01-31 11:53           ` Baurzhan Ismagulov
2018-01-31 12:01             ` Jan Kiszka
2018-01-31 12:28               ` Baurzhan Ismagulov
2018-01-31 13:53                 ` Henning Schild
2018-01-31 14:01                   ` Baurzhan Ismagulov
2018-01-31 14:21                     ` Henning Schild
2018-01-31 10:02 ` [PATCH 0/9] first wic integration Alexander Smirnov
2018-01-31 10:12   ` Henning Schild
2018-01-31 11:24     ` Baurzhan Ismagulov
2018-01-31 11:47       ` Jan Kiszka
2018-01-31 12:02         ` Baurzhan Ismagulov
2018-01-31 12:15           ` Jan Kiszka
2018-01-31 13:30             ` Jan Kiszka
2018-01-31 13:41               ` Baurzhan Ismagulov
2018-01-31 14:01                 ` Jan Kiszka
2018-01-31 15:21                   ` Baurzhan Ismagulov
2018-01-31 15:46                     ` Henning Schild
2018-01-31 16:13                     ` Jan Kiszka
2018-01-31 13:35             ` Baurzhan Ismagulov
2018-01-31 13:47               ` Henning Schild
2018-01-31 14:00                 ` Baurzhan Ismagulov
2018-01-31 13:46             ` Henning Schild
2018-01-31 13:36           ` Henning Schild
2018-01-31 13:40             ` Baurzhan Ismagulov
2018-01-31 13:05       ` Henning Schild
2018-02-01 12:41 ` [PATCH] images: wic: limit use of sudo and enable manual call again Henning Schild
2018-02-01 12:44   ` Henning Schild
2018-02-01 16:09     ` Baurzhan Ismagulov
2018-02-01 18:10       ` Henning Schild
2018-02-01 18:55         ` Henning Schild
2018-02-12 19:07   ` Henning Schild
2018-02-12 17:27 ` [PATCH 0/9] first wic integration Henning Schild
2018-02-12 18:21   ` Alexander Smirnov
2018-02-12 18:30     ` Henning Schild

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df52d78d-d1dd-aaf5-44e9-6876ca1ea4ab@ilbers.de \
    --to=asmirnov@ilbers.de \
    --cc=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox