wic: code cleanup

Fixed indentation, unused imports, trailing lines etc.

[YOCTO #10619]

(From OE-Core rev: 5fa7768bfb4b6d464c6a812822b0665f52e7bea4)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2017-01-31 19:31:55 +02:00 committed by Richard Purdie
parent 1f7ce90af6
commit 653aaea3cc
15 changed files with 36 additions and 43 deletions

View File

@ -1 +0,0 @@
VERSION = "2.00"

View File

@ -190,7 +190,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
crobj = creator.Creator()
cmdline = ["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
wks_file, image_output_dir, oe_builddir, compressor or ""]
wks_file, image_output_dir, oe_builddir, compressor or ""]
if bmap:
cmdline.append('--bmap')

View File

@ -31,7 +31,7 @@ import logging
from wic.plugin import pluginmgr, PLUGIN_TYPES
def subcommand_error(args):
logging.info("invalid subcommand %s" % args[0])
logging.info("invalid subcommand %s", args[0])
def display_help(subcommand, subcommands):
@ -87,7 +87,7 @@ def invoke_subcommand(args, parser, main_command_usage, subcommands):
elif args[0] == "help":
wic_help(args, main_command_usage, subcommands)
elif args[0] not in subcommands:
logging.error("Unsupported subcommand %s, exiting\n" % (args[0]))
logging.error("Unsupported subcommand %s, exiting\n", args[0])
parser.print_help()
return 1
else:

View File

@ -182,7 +182,7 @@ class Partition():
# further processing required Partition.size to be an integer, make
# sure that it is one
if type(self.size) is not int:
if not isinstance(self.size, int):
msger.error("Partition %s internal size is not an integer. " \
"This a bug in source plugin %s and needs to be fixed." \
% (self.mountpoint, self.source))
@ -242,7 +242,10 @@ class Partition():
# IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
rsize_bb = get_bitbake_var('ROOTFS_SIZE')
if rsize_bb:
msger.warning('overhead-factor was specified, but size was not, so bitbake variables will be used for the size. In this case both IMAGE_OVERHEAD_FACTOR and --overhead-factor will be applied')
msger.warning('overhead-factor was specified, but size was not,'
' so bitbake variables will be used for the size.'
' In this case both IMAGE_OVERHEAD_FACTOR and '
'--overhead-factor will be applied')
self.size = int(round(float(rsize_bb)))
for prefix in ("ext", "btrfs", "vfat", "squashfs"):
@ -402,7 +405,8 @@ class Partition():
"Proceeding as requested." % self.mountpoint)
path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
os.path.isfile(path) and os.remove(path)
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
@ -436,4 +440,3 @@ class Partition():
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)

View File

@ -15,7 +15,8 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os, sys
import os
import sys
from wic import msger
from wic import pluginbase

View File

@ -17,7 +17,6 @@
__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins']
import sys
from collections import defaultdict
from wic import msger

View File

@ -29,7 +29,6 @@ import uuid
import tempfile
from time import strftime
from os.path import basename, splitext
from wic import msger
from wic.ksparser import KickStart, KickStartError
@ -65,7 +64,7 @@ class DirectPlugin(ImagerPlugin):
except KickStartError as err:
msger.error(str(err))
name = "%s-%s" % (splitext(basename(ksconf))[0],
name = "%s-%s" % (os.path.splitext(os.path.basename(ksconf))[0],
strftime("%Y%m%d%H%M"))
# parse possible 'rootfs=name' items

View File

@ -42,7 +42,7 @@ class BootimgEFIPlugin(SourcePlugin):
name = 'bootimg-efi'
@classmethod
def do_configure_grubefi(cls, hdddir, creator, cr_workdir, source_params):
def do_configure_grubefi(cls, creator, cr_workdir):
"""
Create loader-specific (grub-efi) config
"""
@ -54,10 +54,10 @@ class BootimgEFIPlugin(SourcePlugin):
# Use a custom configuration for grub
grubefi_conf = custom_cfg
msger.debug("Using custom configuration file "
"%s for grub.cfg" % configfile)
"%s for grub.cfg" % configfile)
else:
msger.error("configfile is specified but failed to "
"get it from %s." % configfile)
"get it from %s." % configfile)
if not custom_cfg:
# Create grub configuration using parameters from wks file
@ -125,10 +125,10 @@ class BootimgEFIPlugin(SourcePlugin):
# Use a custom configuration for systemd-boot
boot_conf = custom_cfg
msger.debug("Using custom configuration file "
"%s for systemd-boots's boot.conf" % configfile)
"%s for systemd-boots's boot.conf" % configfile)
else:
msger.error("configfile is specified but failed to "
"get it from %s." % configfile)
"get it from %s." % configfile)
if not custom_cfg:
# Create systemd-boot configuration using parameters from wks file
@ -164,7 +164,7 @@ class BootimgEFIPlugin(SourcePlugin):
try:
if source_params['loader'] == 'grub-efi':
cls.do_configure_grubefi(hdddir, creator, cr_workdir, source_params)
cls.do_configure_grubefi(creator, cr_workdir)
elif source_params['loader'] == 'systemd-boot':
cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params)
else:
@ -185,7 +185,7 @@ class BootimgEFIPlugin(SourcePlugin):
if not bootimg_dir:
bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
if not bootimg_dir:
msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
# just so the result notes display it
creator.set_bootimg_dir(bootimg_dir)

View File

@ -26,10 +26,11 @@
import os
import re
from glob import glob
from wic import msger
from wic.pluginbase import SourcePlugin
from wic.utils.misc import exec_cmd, get_bitbake_var
from glob import glob
class BootimgPartitionPlugin(SourcePlugin):
"""
@ -137,4 +138,3 @@ class BootimgPartitionPlugin(SourcePlugin):
msger.debug('Prepare boot partition using rootfs in %s' % (hdddir))
part.prepare_rootfs(cr_workdir, oe_builddir, hdddir,
native_sysroot)

View File

@ -198,7 +198,5 @@ class BootimgPcbiosPlugin(SourcePlugin):
out = exec_cmd(du_cmd)
bootimg_size = out.split()[0]
part.size = int(out.split()[0])
part.size = int(bootimg_size)
part.source_file = bootimg

View File

@ -100,10 +100,10 @@ class IsoImagePlugin(SourcePlugin):
grubefi_conf = get_custom_config(configfile)
if grubefi_conf:
msger.debug("Using custom configuration file "
"%s for grub.cfg" % configfile)
"%s for grub.cfg" % configfile)
else:
msger.error("configfile is specified but failed to "
"get it from %s." % configfile)
"get it from %s." % configfile)
else:
splash = os.path.join(cr_workdir, "EFI/boot/splash.jpg")
if os.path.exists(splash):
@ -285,6 +285,7 @@ class IsoImagePlugin(SourcePlugin):
if not deploy_dir:
msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir)
exec_cmd(cp_cmd)
else:
# Prepare initial ramdisk
initrd = "%s/initrd" % deploy_dir
@ -293,8 +294,7 @@ class IsoImagePlugin(SourcePlugin):
if not os.path.isfile(initrd):
initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir)
install_cmd = "install -m 0644 %s %s/initrd" \
% (initrd, isodir)
install_cmd = "install -m 0644 %s %s/initrd" % (initrd, isodir)
exec_cmd(install_cmd)
# Remove the temporary file created by _build_initramfs_path function
@ -303,7 +303,7 @@ class IsoImagePlugin(SourcePlugin):
# Install bzImage
install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
(kernel_dir, isodir)
(kernel_dir, isodir)
exec_cmd(install_cmd)
#Create bootloader for efi boot
@ -362,7 +362,6 @@ class IsoImagePlugin(SourcePlugin):
exec_native_cmd(grub_cmd, native_sysroot)
else:
# TODO: insert gummiboot stuff
msger.error("unrecognized bootimg-efi loader: %s" \
% source_params['loader'])
except KeyError:

View File

@ -84,4 +84,3 @@ class RawCopyPlugin(SourcePlugin):
part.size = filesize
part.source_file = dst

View File

@ -79,5 +79,5 @@ class RootfsPlugin(SourcePlugin):
real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)
part.rootfs_dir = real_rootfs_dir
part.prepare_rootfs(cr_workdir, oe_builddir, real_rootfs_dir, native_sysroot)
part.prepare_rootfs(cr_workdir, oe_builddir,
real_rootfs_dir, native_sysroot)

View File

@ -77,18 +77,15 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
msger.debug("_exec_cmd: output for %s (rc = %d): %s" % \
(cmd_and_args, ret, out))
return (ret, out)
return ret, out
def exec_cmd(cmd_and_args, as_shell=False, catch=3):
"""
Execute command, catching stderr, stdout
Exits if rc non-zero
Execute command, return output
"""
ret, out = _exec_cmd(cmd_and_args, as_shell, catch)
return _exec_cmd(cmd_and_args, as_shell, catch)[1]
return out
def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
"""

View File

@ -21,7 +21,7 @@
import os
from wic import msger
from wic.utils.errors import ImageError
from wic.utils.misc import exec_cmd, exec_native_cmd
from wic.utils.misc import exec_native_cmd
from wic.filemap import sparse_copy
# Overhead of the MBR partitioning scheme (just one sector)
@ -350,10 +350,9 @@ class Image():
if self.disks:
for dev in self.disks:
disk = self.disks[dev]
try:
if hasattr(disk['disk'], 'cleanup'):
disk['disk'].cleanup()
except:
pass
# remove partition images
for image in self.partimages:
if os.path.isfile(image):