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

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

View File

@ -182,7 +182,7 @@ class Partition():
# further processing required Partition.size to be an integer, make # further processing required Partition.size to be an integer, make
# sure that it is one # 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. " \ msger.error("Partition %s internal size is not an integer. " \
"This a bug in source plugin %s and needs to be fixed." \ "This a bug in source plugin %s and needs to be fixed." \
% (self.mountpoint, self.source)) % (self.mountpoint, self.source))
@ -242,7 +242,10 @@ class Partition():
# IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE # IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
rsize_bb = get_bitbake_var('ROOTFS_SIZE') rsize_bb = get_bitbake_var('ROOTFS_SIZE')
if rsize_bb: 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))) self.size = int(round(float(rsize_bb)))
for prefix in ("ext", "btrfs", "vfat", "squashfs"): for prefix in ("ext", "btrfs", "vfat", "squashfs"):
@ -402,7 +405,8 @@ class Partition():
"Proceeding as requested." % self.mountpoint) "Proceeding as requested." % self.mountpoint)
path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype) 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, # it is not possible to create a squashfs without source data,
# thus prepare an empty temp dir that is used as source # thus prepare an empty temp dir that is used as source
@ -436,4 +440,3 @@ class Partition():
label_str = "-L %s" % self.label label_str = "-L %s" % self.label
mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path) mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
exec_native_cmd(mkswap_cmd, native_sysroot) 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 # with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os, sys import os
import sys
from wic import msger from wic import msger
from wic import pluginbase from wic import pluginbase

View File

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

View File

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

View File

@ -42,7 +42,7 @@ class BootimgEFIPlugin(SourcePlugin):
name = 'bootimg-efi' name = 'bootimg-efi'
@classmethod @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 Create loader-specific (grub-efi) config
""" """
@ -164,7 +164,7 @@ class BootimgEFIPlugin(SourcePlugin):
try: try:
if source_params['loader'] == 'grub-efi': 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': elif source_params['loader'] == 'systemd-boot':
cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params) cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params)
else: else:

View File

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

View File

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

View File

@ -285,6 +285,7 @@ class IsoImagePlugin(SourcePlugin):
if not deploy_dir: if not deploy_dir:
msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n") msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir) cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir)
exec_cmd(cp_cmd)
else: else:
# Prepare initial ramdisk # Prepare initial ramdisk
initrd = "%s/initrd" % deploy_dir initrd = "%s/initrd" % deploy_dir
@ -293,8 +294,7 @@ class IsoImagePlugin(SourcePlugin):
if not os.path.isfile(initrd): if not os.path.isfile(initrd):
initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir) initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir)
install_cmd = "install -m 0644 %s %s/initrd" \ install_cmd = "install -m 0644 %s %s/initrd" % (initrd, isodir)
% (initrd, isodir)
exec_cmd(install_cmd) exec_cmd(install_cmd)
# Remove the temporary file created by _build_initramfs_path function # Remove the temporary file created by _build_initramfs_path function
@ -362,7 +362,6 @@ class IsoImagePlugin(SourcePlugin):
exec_native_cmd(grub_cmd, native_sysroot) exec_native_cmd(grub_cmd, native_sysroot)
else: else:
# TODO: insert gummiboot stuff
msger.error("unrecognized bootimg-efi loader: %s" \ msger.error("unrecognized bootimg-efi loader: %s" \
% source_params['loader']) % source_params['loader'])
except KeyError: except KeyError:

View File

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

View File

@ -79,5 +79,5 @@ class RootfsPlugin(SourcePlugin):
real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir) real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)
part.rootfs_dir = real_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" % \ msger.debug("_exec_cmd: output for %s (rc = %d): %s" % \
(cmd_and_args, ret, out)) (cmd_and_args, ret, out))
return (ret, out) return ret, out
def exec_cmd(cmd_and_args, as_shell=False, catch=3): def exec_cmd(cmd_and_args, as_shell=False, catch=3):
""" """
Execute command, catching stderr, stdout Execute command, return output
Exits if rc non-zero
""" """
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=""): def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
""" """

View File

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