miscellaneous fixes. poky-conrib:ed/wic/misc
v2 cover miscellaneous fixes. poky-conrib:ed/wic/misc
Hi,
This patchset includes usability fixes, new functionality, code cleanup, refactoring and 2 new test cases for wic.
The work was done during verification of multi-rootfs EFI images.
Fixes YOCTO #7854 and #7912
Changes in v2:
- removed global statement in get_bitbake_var. Thanks to Christopher Larson to point that out to me
- added one indentation fix
Ed Bartosh (20):
wic: Fix misleading message
wic: Test rootfs plugin using image recipes
wic: Test rootfs plugin using rootfs paths
wic: Refactor getting bitbake variables
wic: Include mount point into image report
wic: Remove annoing debug message
wic: Turn off debug output for 'bitbake -e'
wic: Refactor prepare_rootfs API
wic: Rename partition images
wic: Get rid of useless variable 'image_rootfs'
wic: Call methods better way
wic: Refactor prepare_empty_partition API
wic: Remove duplicated code
wic: Fix naming conflict
wic: Add --uuid partition option
wic: Refactor fstab update code
wic: Remove __write_partition method
wic: Fix confusing error message
wic: Code cleanup: long lines, identation and whitespaces
wic: Code cleanup: unused imports
meta/lib/oeqa/selftest/wic.py | 27 +++ .../image/canned-wks/directdisk-multi-rootfs.wks | 23 +++ scripts/lib/image/engine.py | 38 +--- scripts/lib/image/help.py | 5 + scripts/lib/wic/conf.py | 28 ++- scripts/lib/wic/imager/baseimager.py | 3 +- scripts/lib/wic/imager/direct.py | 91 ++++----- .../lib/wic/kickstart/custom_commands/micboot.py | 2 +- .../lib/wic/kickstart/custom_commands/partition.py | 209 +++++++-------------- scripts/lib/wic/msger.py | 23 +-- scripts/lib/wic/plugin.py | 2 - scripts/lib/wic/pluginbase.py | 1 - scripts/lib/wic/plugins/imager/direct_plugin.py | 4 +- scripts/lib/wic/plugins/source/bootimg-efi.py | 1 - scripts/lib/wic/plugins/source/bootimg-pcbios.py | 4 +- scripts/lib/wic/plugins/source/rootfs.py | 9 +- .../lib/wic/plugins/source/rootfs_pcbios_ext.py | 6 +- scripts/lib/wic/utils/cmdln.py | 1 - scripts/lib/wic/utils/oe/misc.py | 87 ++++----- scripts/lib/wic/utils/partitionedfs.py | 41 ++-- scripts/lib/wic/utils/runner.py | 2 +- scripts/wic | 66 +++---- 22 files changed, 282 insertions(+), 391 deletions(-) create mode 100644 scripts/lib/image/canned-wks/directdisk-multi-rootfs.wks
--
Ed
PATCH v2 1/20 wic: Fix misleading message
Due to usage of incorrect variable wic produces strange message "No image named None found, exiting." when specified canned .wks doesn't exist.
Fixed by replacing wks_file -> argv[0]
scripts/wic +1 -1
@@ -173,7 +173,7 @@ def wic_create_subcommand(args, usage_str): if not wks_file.endswith(".wks"): wks_file = engine.find_canned_image(scripts_path, wks_file) if not wks_file: - print "No image named %s found, exiting. (Use 'wic list images' to list available images, or specify a fully-qualified OE kickstart (.wks) filename)\n" % wks_file + print "No image named %s found, exiting. (Use 'wic list images' to list available images, or specify a fully-qualified OE kickstart (.wks) filename)\n" % args[0] sys.exit(1) image_output_dir = ""
Signature · 1 line
2.1.4
PATCH v2 2/20 wic: Test rootfs plugin using image recipes
In reply to Ed BartoshAdded canned wks and testcase to create multi-rootfs images referring bitbake image recipes.
create mode 100644 scripts/lib/image/canned-wks/directdisk-multi-rootfs.wks
meta/lib/oeqa/selftest/wic.py +10 -0
@@ -133,3 +133,13 @@ class Wic(oeSelfTest): self.assertEqual(2, runCmd("wic create directdisk " "--image-name core-image-minimal " "-c wrong", ignore_status=True).status) + + def test16_rootfs_indirect_recipes(self): + """Test usage of rootfs plugin with rootfs recipes""" + wks = "directdisk-multi-rootfs" + self.assertEqual(0, runCmd("wic create %s " + "--image-name core-image-minimal " + "--rootfs rootfs1=core-image-minimal " + "--rootfs rootfs2=core-image-minimal" \ + % wks).status) + self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks)))
scripts/lib/image/canned-wks/directdisk-multi-rootfs.wks new file +23 -0
@@ -0,0 +1,23 @@ +# short-description: Create multi rootfs image using rootfs plugin +# long-description: Creates a partitioned disk image with two rootfs partitions +# using rootfs plugin. +# +# Partitions can use either +# - indirect rootfs references to image recipe(s): +# wic create directdisk-multi-indirect-recipes -e core-image-minimal \ +# --rootfs-dir rootfs1=core-image-minimal +# --rootfs-dir rootfs2=core-image-minimal-dev +# +# - or paths to rootfs directories: +# wic create directdisk-multi-rootfs \ +# --rootfs-dir rootfs1=tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/rootfs/ +# --rootfs-dir rootfs2=tmp/work/qemux86_64-poky-linux/core-image-minimal-dev/1.0-r0/rootfs/ +# +# - or any combinations of -r and --rootfs command line options + +part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 +part / --source rootfs --rootfs-dir=rootfs1 --ondisk sda --fstype=ext3 --label platform --align 1024 +part /rescue --source rootfs --rootfs-dir=rootfs2 --ondisk sda --fstype=ext3 --label secondary --align 1024 + +bootloader --timeout=0 --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0" +
Signature · 1 line
2.1.4
PATCH v2 3/20 wic: Test rootfs plugin using rootfs paths
In reply to Ed BartoshAdded testcase to create multi-rootfs images using rootfs plugin with paths to rootfs directories in wic command line.
meta/lib/oeqa/selftest/wic.py +17 -0
@@ -143,3 +143,20 @@ class Wic(oeSelfTest): "--rootfs rootfs2=core-image-minimal" \ % wks).status) self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks))) + + def test17_rootfs_artifacts(self): + """Test usage of rootfs plugin with rootfs paths""" + vars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ + for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', + 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) + vars['wks'] = "directdisk-multi-rootfs" + status = runCmd("wic create %(wks)s " + "-b %(staging_datadir)s " + "-k %(deploy_dir_image)s " + "-n %(staging_dir_native)s " + "--rootfs-dir rootfs1=%(image_rootfs)s " + "--rootfs-dir rootfs2=%(image_rootfs)s" \ + % vars).status + self.assertEqual(0, status) + self.assertEqual(1, len(glob(self.resultdir + \ + "%(wks)s-*.direct" % vars)))
Signature · 1 line
2.1.4
PATCH v2 4/20 wic: Refactor getting bitbake variables
In reply to Ed BartoshWic gets bitbake variables by parsing output of 'bitbake -e' command.
This implementation improves this procedure as it runs 'bitbake -e' only when API is called and does it only once, i.e. in a "lazy" way. As parsing results are cached 'bitbake -e' is run only once and results are parsed only once per requested set of variables.
get_bitbake_var became the only API call. It replaces find_artifacts, find_artifact, find_bitbake_env_lines, get_bitbake_env_lines, set_bitbake_env_lines and get_line_val calls making API much more clear.
scripts/lib/image/engine.py +0 -23
@@ -60,29 +60,6 @@ def verify_build_env(): return True -def find_artifacts(image_name): - """ - Gather the build artifacts for the current image (the image_name - e.g. core-image-minimal) for the current MACHINE set in local.conf - """ - bitbake_env_lines = misc.get_bitbake_env_lines() - - rootfs_dir = kernel_dir = bootimg_dir = native_sysroot = "" - - for line in bitbake_env_lines.split('\n'): - if misc.get_line_val(line, "IMAGE_ROOTFS"): - rootfs_dir = misc.get_line_val(line, "IMAGE_ROOTFS") - continue - if misc.get_line_val(line, "DEPLOY_DIR_IMAGE"): - kernel_dir = misc.get_line_val(line, "DEPLOY_DIR_IMAGE") - continue - if misc.get_line_val(line, "STAGING_DIR_NATIVE"): - native_sysroot = misc.get_line_val(line, "STAGING_DIR_NATIVE") - continue - - return (rootfs_dir, kernel_dir, bootimg_dir, native_sysroot) - - CANNED_IMAGE_DIR = "lib/image/canned-wks" # relative to scripts SCRIPTS_CANNED_IMAGE_DIR = "scripts/" + CANNED_IMAGE_DIR
scripts/lib/wic/plugins/source/rootfs.py +2 -7
@@ -29,7 +29,7 @@ import os from wic import msger from wic.pluginbase import SourcePlugin -from wic.utils.oe.misc import find_bitbake_env_lines, find_artifact +from wic.utils.oe.misc import get_bitbake_var class RootfsPlugin(SourcePlugin): """
@@ -43,12 +43,7 @@ class RootfsPlugin(SourcePlugin): if os.path.isdir(rootfs_dir): return rootfs_dir - bitbake_env_lines = find_bitbake_env_lines(rootfs_dir) - if not bitbake_env_lines: - msg = "Couldn't get bitbake environment, exiting." - msger.error(msg) - - image_rootfs_dir = find_artifact(bitbake_env_lines, "IMAGE_ROOTFS") + image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir) if not os.path.isdir(image_rootfs_dir): msg = "No valid artifact IMAGE_ROOTFS from image named" msg += " %s has been found at %s, exiting.\n" % \
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +1 -5
@@ -59,11 +59,7 @@ class RootfsPlugin(SourcePlugin): if os.path.isdir(rootfs_dir): return rootfs_dir - bitbake_env_lines = misc.find_bitbake_env_lines(rootfs_dir) - if not bitbake_env_lines: - msger.error("Couldn't get bitbake environment, exiting.") - - image_rootfs_dir = misc.find_artifact(bitbake_env_lines, "IMAGE_ROOTFS") + image_rootfs_dir = misc.get_bitbake_var("IMAGE_ROOTFS", rootfs_dir) if not os.path.isdir(image_rootfs_dir): msg = "No valid artifact IMAGE_ROOTFS from image named" msg += " %s has been found at %s, exiting.\n" % \
scripts/lib/wic/utils/oe/misc.py +30 -52
98 lines not on this page · raw message
scripts/wic +5 -16
@@ -52,7 +52,7 @@ if bitbake_exe: else: bitbake_main = None -from wic.utils.oe.misc import find_bitbake_env_lines, set_bitbake_env_lines +from wic.utils.oe.misc import get_bitbake_var from wic.utils.errors import WicError from image import engine from image import help as hlp
@@ -141,12 +141,6 @@ def wic_create_subcommand(args, usage_str): else: print "Done.\n" - bitbake_env_lines = find_bitbake_env_lines(options.image_name) - if not bitbake_env_lines: - print "Couldn't get bitbake environment, exiting." - sys.exit(1) - set_bitbake_env_lines(bitbake_env_lines) - bootimg_dir = "" if options.image_name:
@@ -160,9 +154,10 @@ def wic_create_subcommand(args, usage_str): cookerdata.CookerConfiguration()): sys.exit(1) - (rootfs_dir, kernel_dir, bootimg_dir, native_sysroot) \ - = engine.find_artifacts(options.image_name) - + rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", options.image_name) + kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE", options.image_name) + native_sysroot = get_bitbake_var("STAGING_DIR_NATIVE", + options.image_name) else: if options.build_rootfs: print "Image name is not specified, exiting. (Use -e/--image-name to specify it)\n"
@@ -244,12 +239,6 @@ def wic_list_subcommand(args, usage_str): (options, args) = parser.parse_args(args) - bitbake_env_lines = find_bitbake_env_lines(None) - if not bitbake_env_lines: - print "Couldn't get bitbake environment, exiting." - sys.exit(1) - set_bitbake_env_lines(bitbake_env_lines) - if not engine.wic_list(args, scripts_path, options.properties_file): logging.error("Bad list arguments, exiting\n") parser.print_help()
Signature · 1 line
2.1.4
PATCH v2 5/20 wic: Include mount point into image report
In reply to Ed BartoshWic doesn't show any information for the partition if label is not set. Fixed this by adding mount point to the report.
scripts/lib/wic/imager/direct.py +1 -1
@@ -351,7 +351,7 @@ class DirectImageCreator(BaseImageCreator): if p.mountpoint == '/': str = ':' else: - str = '["%s"]:' % p.label + str = '["%s"]:' % (p.mountpoint or p.label) msg += ' ROOTFS_DIR%s%s\n' % (str.ljust(20), p.get_rootfs()) msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir
Signature · 1 line
2.1.4
PATCH v2 6/20 wic: Remove annoing debug message
In reply to Ed BartoshWic tries to find plugins in every layer and prints a message 'Plugin dir is not a directory or does not exist' if layer doesn't have plugin dir. It causes a lot of duplicated messages in the debug output, which makes it hard to find useful info there.
scripts/lib/wic/plugin.py +0 -2
@@ -74,8 +74,6 @@ class PluginMgr(object): path = os.path.abspath(os.path.expanduser(path)) if not os.path.isdir(path): - msger.debug("Plugin dir is not a directory or does not exist: %s"\ - % path) return if path not in self.plugin_dirs:
Signature · 1 line
2.1.4
PATCH v2 7/20 wic: Turn off debug output for 'bitbake -e'
In reply to Ed BartoshSwitched debug level to 'normal' to prevent huge 'bitbake -e' output to go into wic debug output. This should help to make wic debug info much more clean and easier to read.
scripts/lib/wic/utils/oe/misc.py +5 -0
@@ -122,7 +122,12 @@ def get_bitbake_var(var, image=None): cmd = "bitbake -e" if image: cmd += " %s" % image + + log_level = msger.get_loglevel() + msger.set_loglevel('normal') rc, lines = __exec_cmd(cmd) + msger.set_loglevel(log_level) + if rc: print "Couldn't get '%s' output." % cmd print "Bitbake failed with error:\n%s\n" % lines
Signature · 1 line
2.1.4
PATCH v2 8/20 wic: Refactor prepare_rootfs API
In reply to Ed BartoshMoved code out of prepare_roots* methods to avoid code duplication.
scripts/lib/wic/kickstart/custom_commands/partition.py +12 -16
@@ -219,34 +219,36 @@ class Wic_PartData(Mic_PartData): pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp pseudo += "%s/usr/bin/pseudo " % native_sysroot + rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label, self.fstype) + if os.path.isfile(rootfs): + os.remove(rootfs) + if self.fstype.startswith("ext"): - return self.prepare_rootfs_ext(cr_workdir, oe_builddir, + return self.prepare_rootfs_ext(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo) elif self.fstype.startswith("btrfs"): - return self.prepare_rootfs_btrfs(cr_workdir, oe_builddir, + return self.prepare_rootfs_btrfs(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo) elif self.fstype.startswith("vfat"): - return self.prepare_rootfs_vfat(cr_workdir, oe_builddir, + return self.prepare_rootfs_vfat(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo) elif self.fstype.startswith("squashfs"): - return self.prepare_rootfs_squashfs(cr_workdir, oe_builddir, + return self.prepare_rootfs_squashfs(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo) - def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir, + def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for an ext2/3/4 rootfs partition. """ image_rootfs = rootfs_dir - rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label ,self.fstype) - os.path.isfile(rootfs) and os.remove(rootfs) du_cmd = "du -ks %s" % image_rootfs out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0])
@@ -285,7 +287,7 @@ class Wic_PartData(Mic_PartData): return 0 - def prepare_rootfs_btrfs(self, cr_workdir, oe_builddir, rootfs_dir, + def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for a btrfs rootfs partition.
@@ -293,9 +295,7 @@ class Wic_PartData(Mic_PartData): Currently handles ext2/3/4 and btrfs. """ image_rootfs = rootfs_dir - rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label, self.fstype) - os.path.isfile(rootfs) and os.remove(rootfs) du_cmd = "du -ks %s" % image_rootfs out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0])
@@ -330,15 +330,13 @@ class Wic_PartData(Mic_PartData): self.size = rootfs_size self.source_file = rootfs - def prepare_rootfs_vfat(self, cr_workdir, oe_builddir, rootfs_dir, + def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for a vfat rootfs partition. """ image_rootfs = rootfs_dir - rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label, self.fstype) - os.path.isfile(rootfs) and os.remove(rootfs) du_cmd = "du -bks %s" % image_rootfs out = exec_cmd(du_cmd) blocks = int(out.split()[0])
@@ -381,15 +379,13 @@ class Wic_PartData(Mic_PartData): self.set_size(rootfs_size) self.set_source_file(rootfs) - def prepare_rootfs_squashfs(self, cr_workdir, oe_builddir, rootfs_dir, + def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for a squashfs rootfs partition. """ image_rootfs = rootfs_dir - rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label ,self.fstype) - os.path.isfile(rootfs) and os.remove(rootfs) squashfs_cmd = "mksquashfs %s %s -noappend" % \ (image_rootfs, rootfs) exec_native_cmd(pseudo + squashfs_cmd, native_sysroot)
Signature · 1 line
2.1.4
PATCH v2 9/20 wic: Rename partition images
In reply to Ed BartoshRenamed partition images into <final image>.p<partition number> This should make output directory look more organized and easier to understand.
scripts/lib/wic/utils/partitionedfs.py +2 -0
@@ -18,6 +18,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. +import os from wic import msger from wic.utils.errors import ImageError from wic.utils.oe.misc import exec_cmd, exec_native_cmd
@@ -356,6 +357,7 @@ class Image(object): for p in self.partitions: self.__write_partition(p['num'], p['source_file'], p['start'], p['size'], image_file) + os.rename(p['source_file'], image_file + '.p%d' % p['num']) def create(self): for dev in self.disks.keys():
Signature · 1 line
2.1.4
PATCH v2 10/20 wic: Get rid of useless variable 'image_rootfs'
In reply to Ed BartoshRemoved useless variable 'image_rootfs' from 4 prepare_rootfs_* methods.
scripts/lib/wic/kickstart/custom_commands/partition.py +7 -16
@@ -246,10 +246,7 @@ class Wic_PartData(Mic_PartData): """ Prepare content for an ext2/3/4 rootfs partition. """ - - image_rootfs = rootfs_dir - - du_cmd = "du -ks %s" % image_rootfs + du_cmd = "du -ks %s" % rootfs_dir out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0])
@@ -274,7 +271,7 @@ class Wic_PartData(Mic_PartData): label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \ - (self.fstype, extra_imagecmd, rootfs, label_str, image_rootfs) + (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir) exec_native_cmd(pseudo + mkfs_cmd, native_sysroot) # get the rootfs size in the right units for kickstart (kB)
@@ -294,9 +291,7 @@ class Wic_PartData(Mic_PartData): Currently handles ext2/3/4 and btrfs. """ - image_rootfs = rootfs_dir - - du_cmd = "du -ks %s" % image_rootfs + du_cmd = "du -ks %s" % rootfs_dir out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0])
@@ -319,7 +314,7 @@ class Wic_PartData(Mic_PartData): label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \ - (self.fstype, rootfs_size * 1024, image_rootfs, label_str, rootfs) + (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs) exec_native_cmd(pseudo + mkfs_cmd, native_sysroot) # get the rootfs size in the right units for kickstart (kB)
@@ -335,9 +330,7 @@ class Wic_PartData(Mic_PartData): """ Prepare content for a vfat rootfs partition. """ - image_rootfs = rootfs_dir - - du_cmd = "du -bks %s" % image_rootfs + du_cmd = "du -bks %s" % rootfs_dir out = exec_cmd(du_cmd) blocks = int(out.split()[0])
@@ -365,7 +358,7 @@ class Wic_PartData(Mic_PartData): 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, image_rootfs) + mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) exec_native_cmd(mcopy_cmd, native_sysroot) chmod_cmd = "chmod 644 %s" % rootfs
@@ -384,10 +377,8 @@ class Wic_PartData(Mic_PartData): """ Prepare content for a squashfs rootfs partition. """ - image_rootfs = rootfs_dir - squashfs_cmd = "mksquashfs %s %s -noappend" % \ - (image_rootfs, rootfs) + (rootfs_dir, rootfs) exec_native_cmd(pseudo + squashfs_cmd, native_sysroot) # get the rootfs size in the right units for kickstart (kB)
Signature · 1 line
2.1.4
PATCH v2 11/20 wic: Call methods better way
In reply to Ed BartoshShortened code by using getattr to obtain a method to call for prepare_empty_partition_* and prepare_rootfs_* methods.
scripts/lib/wic/kickstart/custom_commands/partition.py +11 -36
@@ -160,8 +160,12 @@ class Wic_PartData(Mic_PartData): self.prepare_swap_partition(cr_workdir, oe_builddir, native_sysroot) elif self.fstype: - self.prepare_empty_partition(cr_workdir, oe_builddir, - native_sysroot) + for prefix in ("ext", "btrfs", "vfat", "squashfs"): + if self.fstype.startswith(prefix): + method = getattr(self, + "prepare_empty_partition_" + prefix) + method(cr_workdir, oe_builddir, native_sysroot) + break return plugins = pluginmgr.get_source_plugins()
@@ -223,23 +227,11 @@ class Wic_PartData(Mic_PartData): if os.path.isfile(rootfs): os.remove(rootfs) - if self.fstype.startswith("ext"): - return self.prepare_rootfs_ext(rootfs, oe_builddir, - rootfs_dir, native_sysroot, - pseudo) - elif self.fstype.startswith("btrfs"): - return self.prepare_rootfs_btrfs(rootfs, oe_builddir, - rootfs_dir, native_sysroot, - pseudo) - - elif self.fstype.startswith("vfat"): - return self.prepare_rootfs_vfat(rootfs, oe_builddir, - rootfs_dir, native_sysroot, - pseudo) - elif self.fstype.startswith("squashfs"): - return self.prepare_rootfs_squashfs(rootfs, oe_builddir, - rootfs_dir, native_sysroot, - pseudo) + for prefix in ("ext", "btrfs", "vfat", "squashfs"): + if self.fstype.startswith(prefix): + method = getattr(self, "prepare_rootfs_" + prefix) + return method(rootfs, oe_builddir, rootfs_dir, + native_sysroot, pseudo) def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo):
@@ -391,23 +383,6 @@ class Wic_PartData(Mic_PartData): return 0 - def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot): - """ - Prepare an empty partition. - """ - if self.fstype.startswith("ext"): - return self.prepare_empty_partition_ext(cr_workdir, oe_builddir, - native_sysroot) - elif self.fstype.startswith("btrfs"): - return self.prepare_empty_partition_btrfs(cr_workdir, oe_builddir, - native_sysroot) - elif self.fstype.startswith("vfat"): - return self.prepare_empty_partition_vfat(cr_workdir, oe_builddir, - native_sysroot) - elif self.fstype.startswith("squashfs"): - return self.prepare_empty_partition_squashfs(cr_workdir, oe_builddir, - native_sysroot) - def prepare_empty_partition_ext(self, cr_workdir, oe_builddir, native_sysroot): """
Signature · 1 line
2.1.4
PATCH v2 12/20 wic: Refactor prepare_empty_partition API
In reply to Ed BartoshMoved code out of prepare_empty_partition* methods to avoid code duplication.
scripts/lib/wic/kickstart/custom_commands/partition.py +12 -36
@@ -160,11 +160,15 @@ class Wic_PartData(Mic_PartData): self.prepare_swap_partition(cr_workdir, oe_builddir, native_sysroot) elif self.fstype: + rootfs = "%s/fs_%s.%s" % (cr_workdir, self.label, 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(cr_workdir, oe_builddir, native_sysroot) + method(rootfs, oe_builddir, native_sysroot) + self.source_file = rootfs break return
@@ -383,16 +387,13 @@ class Wic_PartData(Mic_PartData): return 0 - def prepare_empty_partition_ext(self, cr_workdir, oe_builddir, + def prepare_empty_partition_ext(self, rootfs, oe_builddir, native_sysroot): """ Prepare an empty ext2/3/4 partition. """ - fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype) - - os.path.isfile(fs) and os.remove(fs) dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ - (fs, self.size) + (rootfs, self.size) exec_cmd(dd_cmd) extra_imagecmd = "-i 8192"
@@ -402,23 +403,16 @@ class Wic_PartData(Mic_PartData): label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -F %s %s %s" % \ - (self.fstype, extra_imagecmd, label_str, fs) + (self.fstype, extra_imagecmd, label_str, rootfs) exec_native_cmd(mkfs_cmd, native_sysroot) - self.source_file = fs - - return 0 - - def prepare_empty_partition_btrfs(self, cr_workdir, oe_builddir, + def prepare_empty_partition_btrfs(self, rootfs, oe_builddir, native_sysroot): """ Prepare an empty btrfs partition. """ - fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype) - - os.path.isfile(fs) and os.remove(fs) dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ - (fs, self.size) + (rootfs, self.size) exec_cmd(dd_cmd) label_str = ""
@@ -426,21 +420,14 @@ class Wic_PartData(Mic_PartData): label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -b %d %s %s" % \ - (self.fstype, self.size * 1024, label_str, fs) + (self.fstype, self.size * 1024, label_str, rootfs) exec_native_cmd(mkfs_cmd, native_sysroot) - self.source_file = fs - - return 0 - - def prepare_empty_partition_vfat(self, cr_workdir, oe_builddir, + def prepare_empty_partition_vfat(self, rootfs, oe_builddir, native_sysroot): """ Prepare an empty vfat partition. """ - fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype) - os.path.isfile(fs) and os.remove(fs) - blocks = self.size label_str = "-n boot"
@@ -453,10 +440,6 @@ class Wic_PartData(Mic_PartData): chmod_cmd = "chmod 644 %s" % fs exec_cmd(chmod_cmd) - self.source_file = fs - - return 0 - def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir, native_sysroot): """
@@ -484,9 +467,6 @@ class Wic_PartData(Mic_PartData): fs_size = out.split()[0] self.size = fs_size - self.source_file = fs - - return 0 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot): """
@@ -505,10 +485,6 @@ class Wic_PartData(Mic_PartData): mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), fs) exec_native_cmd(mkswap_cmd, native_sysroot) - self.source_file = fs - - return 0 - class Wic_Partition(Mic_Partition): removedKeywords = Mic_Partition.removedKeywords removedAttrs = Mic_Partition.removedAttrs
Signature · 1 line
2.1.4
PATCH v2 13/20 wic: Remove duplicated code
In reply to Ed BartoshMoved duplicated code of geting rootfs size
out of prepare_rootfs* methods.
scripts/lib/wic/kickstart/custom_commands/partition.py +10 -38
@@ -234,8 +234,16 @@ class Wic_PartData(Mic_PartData): for prefix in ("ext", "btrfs", "vfat", "squashfs"): if self.fstype.startswith(prefix): method = getattr(self, "prepare_rootfs_" + prefix) - return method(rootfs, oe_builddir, rootfs_dir, - native_sysroot, pseudo) + 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):
@@ -270,16 +278,6 @@ class Wic_PartData(Mic_PartData): (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir) exec_native_cmd(pseudo + mkfs_cmd, native_sysroot) - # get the rootfs size in the right units for kickstart (kB) - du_cmd = "du -Lbks %s" % rootfs - out = exec_cmd(du_cmd) - rootfs_size = out.split()[0] - - self.size = rootfs_size - self.source_file = rootfs - - return 0 - def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """
@@ -313,14 +311,6 @@ class Wic_PartData(Mic_PartData): (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs) exec_native_cmd(pseudo + mkfs_cmd, native_sysroot) - # get the rootfs size in the right units for kickstart (kB) - 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_vfat(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """
@@ -360,14 +350,6 @@ class Wic_PartData(Mic_PartData): chmod_cmd = "chmod 644 %s" % rootfs exec_cmd(chmod_cmd) - # get the rootfs size in the right units for kickstart (kB) - du_cmd = "du -Lbks %s" % rootfs - out = exec_cmd(du_cmd) - rootfs_size = out.split()[0] - - self.set_size(rootfs_size) - self.set_source_file(rootfs) - def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """
@@ -377,16 +359,6 @@ class Wic_PartData(Mic_PartData): (rootfs_dir, rootfs) exec_native_cmd(pseudo + squashfs_cmd, native_sysroot) - # get the rootfs size in the right units for kickstart (kB) - du_cmd = "du -Lbks %s" % rootfs - out = exec_cmd(du_cmd) - rootfs_size = out.split()[0] - - self.size = rootfs_size - self.source_file = rootfs - - return 0 - def prepare_empty_partition_ext(self, rootfs, oe_builddir, native_sysroot): """
Signature · 1 line
2.1.4
PATCH v2 14/20 wic: Fix naming conflict
In reply to Ed BartoshImage file name is not unique for the partitions without label. This causes image being rewritten and used as a source for all partitions without label. Wic produces broken or incorrect result images because of that.
Added wks line number to the image name to make it unique.
scripts/lib/wic/kickstart/custom_commands/partition.py +4 -2
@@ -160,7 +160,8 @@ class Wic_PartData(Mic_PartData): self.prepare_swap_partition(cr_workdir, oe_builddir, native_sysroot) elif self.fstype: - rootfs = "%s/fs_%s.%s" % (cr_workdir, self.label, 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"):
@@ -227,7 +228,8 @@ class Wic_PartData(Mic_PartData): pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp pseudo += "%s/usr/bin/pseudo " % native_sysroot - rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label, self.fstype) + rootfs = "%s/rootfs_%s.%s.%s" % (cr_workdir, self.label, + self.lineno, self.fstype) if os.path.isfile(rootfs): os.remove(rootfs)
Signature · 1 line
2.1.4
PATCH v2 15/20 wic: Add --uuid partition option
In reply to Ed BartoshAdded --uuid option to the configuration of wks parser. This option specifies partition UUID. The code to process it is already in place. It was implemented for --use-uuid option.
scripts/lib/image/help.py +5 -0
@@ -787,6 +787,11 @@ DESCRIPTION random globally unique identifier (GUID) for the partition and use it in bootloader configuration to specify root partition. + --uuid: This option is specific to wic. It specifies partition UUID. + It's useful if preconfigured partition UUID is added to kernel command line + in bootloader configuration before running wic. In this case .wks file can + be generated or modified to set preconfigured parition UUID using this option. + * bootloader This command allows the user to specify various bootloader
scripts/lib/wic/kickstart/custom_commands/partition.py +4 -1
@@ -53,7 +53,7 @@ class Wic_PartData(Mic_PartData): self.extra_space = kwargs.get("extra-space", "10M") self.overhead_factor = kwargs.get("overhead-factor", 1.3) self._use_uuid = False - self.uuid = None + self.uuid = kwargs.get("uuid", None) self.use_uuid = kwargs.get("use-uuid", False) self.source_file = "" self.size = 0
@@ -71,6 +71,8 @@ class Wic_PartData(Mic_PartData): retval += " --no-table" if self.use_uuid: retval += " --use-uuid" + if self.uuid: + retval += " --uuid=%s" % self.uuid retval += " --extra-space=%s" % self.extra_space retval += " --overhead-factor=%f" % self.overhead_factor
@@ -491,5 +493,6 @@ class Wic_Partition(Mic_Partition): nargs=1, default=1.3) op.add_option("--use-uuid", dest="use_uuid", action="store_true", default=False) + op.add_option("--uuid") return op
Signature · 1 line
2.1.4
PATCH v2 16/20 wic: Refactor fstab update code
In reply to Ed BartoshMade the code to backup and restore fstab only if it's modified.
Cleaned up the code. Made it more pythonic.
Improved code readability by moving code from several tiny methods into one place.
scripts/lib/wic/imager/direct.py +30 -53
@@ -90,74 +90,50 @@ class DirectImageCreator(BaseImageCreator): return realnum + 1 return realnum - def __write_fstab(self, image_rootfs): + def _write_fstab(self, image_rootfs): """overriden to generate fstab (temporarily) in rootfs. This is called from _create, make sure it doesn't get called from BaseImage.create() """ - if image_rootfs is None: - return None + if not image_rootfs: + return + + fstab_path = image_rootfs + "/etc/fstab" + if not os.path.isfile(fstab_path): + return - fstab = image_rootfs + "/etc/fstab" - if not os.path.isfile(fstab): - return None + with open(fstab_path) as fstab: + fstab_lines = fstab.readlines() - parts = self._get_parts() + if self._update_fstab(fstab_lines, self._get_parts()): + shutil.copyfile(fstab_path, fstab_path + ".orig") - self._save_fstab(fstab) - fstab_lines = self._get_fstab(fstab, parts) - self._update_fstab(fstab_lines, parts) - self._write_fstab(fstab, fstab_lines) + with open(fstab_path, "w") as fstab: + fstab.writelines(fstab_lines) - return fstab + return fstab_path def _update_fstab(self, fstab_lines, parts): """Assume partition order same as in wks""" - for num, p in enumerate(parts, 1): + updated = False + for num, part in enumerate(parts, 1): pnum = self.__get_part_num(num, parts) - if not p.mountpoint or p.mountpoint == "/" or p.mountpoint == "/boot" or pnum == 0: + if not pnum or not part.mountpoint \ + or part.mountpoint in ("/", "/boot"): continue - part = '' # mmc device partitions are named mmcblk0p1, mmcblk0p2.. - if p.disk.startswith('mmcblk'): - part = 'p' - - device_name = "/dev/" + p.disk + part + str(pnum) - - opts = "defaults" - if p.fsopts: - opts = p.fsopts - - fstab_entry = device_name + "\t" + \ - p.mountpoint + "\t" + \ - p.fstype + "\t" + \ - opts + "\t0\t0\n" - fstab_lines.append(fstab_entry) - - def _write_fstab(self, fstab, fstab_lines): - fstab = open(fstab, "w") - for line in fstab_lines: - fstab.write(line) - fstab.close() - - def _save_fstab(self, fstab): - """Save the current fstab in rootfs""" - shutil.copyfile(fstab, fstab + ".orig") - - def _restore_fstab(self, fstab): - """Restore the saved fstab in rootfs""" - if fstab is None: - return - shutil.move(fstab + ".orig", fstab) + prefix = 'p' if part.disk.startswith('mmcblk') else '' + device_name = "/dev/%s%s%d" % (part.disk, prefix, pnum) + + opts = part.fsopts if part.fsopts else "defaults" + line = "\t".join([device_name, part.mountpoint, part.fstype, + opts, "0", "0"]) + "\n" - def _get_fstab(self, fstab, parts): - """Return the desired contents of /etc/fstab.""" - f = open(fstab, "r") - fstab_contents = f.readlines() - f.close() + fstab_lines.append(line) + updated = True - return fstab_contents + return updated def set_bootimg_dir(self, bootimg_dir): """
@@ -250,7 +226,7 @@ class DirectImageCreator(BaseImageCreator): if not self.ks.handler.bootloader.source and p.mountpoint == "/boot": self.ks.handler.bootloader.source = p.source - fstab = self.__write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) + fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) for p in parts: # need to create the filesystems in order to get their
@@ -277,7 +253,8 @@ class DirectImageCreator(BaseImageCreator): part_type=p.part_type, uuid=p.uuid) - self._restore_fstab(fstab) + if fstab_path: + shutil.move(fstab_path + ".orig", fstab_path) self.__image.layout_partitions(self.ptable_format)
Signature · 1 line
2.1.4
PATCH v2 17/20 wic: Remove __write_partition method
In reply to Ed BartoshMoved code of __write_partition to 'assemble' method. This way it should be more readable.
scripts/lib/wic/utils/partitionedfs.py +15 -21
@@ -334,30 +334,24 @@ class Image(object): except: pass - def __write_partition(self, num, source_file, start, size, image_file): - """ - Install source_file contents into a partition. - """ - if not source_file: # nothing to write - return - - # Start is included in the size so need to substract one from the end. - end = start + size - 1 - msger.debug("Installed %s in partition %d, sectors %d-%d, " - "size %d sectors" % (source_file, num, start, end, size)) - - dd_cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \ - (source_file, image_file, self.sector_size, start, size) - exec_cmd(dd_cmd) - - def assemble(self, image_file): msger.debug("Installing partitions") - for p in self.partitions: - self.__write_partition(p['num'], p['source_file'], - p['start'], p['size'], image_file) - os.rename(p['source_file'], image_file + '.p%d' % p['num']) + for part in self.partitions: + source = part['source_file'] + if source: + # install source_file contents into a partition + cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \ + (source, image_file, self.sector_size, + part['start'], part['size']) + exec_cmd(cmd) + + msger.debug("Installed %s in partition %d, sectors %d-%d, " + "size %d sectors" % \ + (source, part['num'], part['start'], + part['start'] + part['size'] - 1, part['size'])) + + os.rename(source, image_file + '.p%d' % part['num']) def create(self): for dev in self.disks.keys():
Signature · 1 line
2.1.4
PATCH v2 18/20 wic: Fix confusing error message
In reply to Ed BartoshWic throws this message when any of the build artifacts are not provided:
Build artifacts not completely specified, exiting.
(Use 'wic -e' or 'wic -r -b -k -n' to specify artifacts)
It was not clear which artifact was not specified.
Reworked the code to specify list of missed artifacts. Now the message looks like this:
The following build artifacts are not specified:
bootimg-dir, kernel-dir, native-sysroot
[YOCTO #7912]
scripts/wic +12 -7
@@ -122,13 +122,18 @@ def wic_create_subcommand(args, usage_str): logging.error("Can't build roofs as bitbake is not in the $PATH") sys.exit(1) - if not options.image_name and not (options.rootfs_dir and - options.bootimg_dir and - options.kernel_dir and - options.native_sysroot): - print "Build artifacts not completely specified, exiting." - print " (Use 'wic -e' or 'wic -r -b -k -n' to specify artifacts)" - sys.exit(1) + if not options.image_name: + missed = [] + for val, opt in [(options.rootfs_dir, 'rootfs-dir'), + (options.bootimg_dir, 'bootimg-dir'), + (options.kernel_dir, 'kernel-dir'), + (options.native_sysroot, 'native-sysroot')]: + if not val: + missed.append(opt) + if missed: + print "The following build artifacts are not specified:" + print " " + ", ".join(missed) + sys.exit(1) if not options.image_name: options.build_check = False
Signature · 1 line
2.1.4
PATCH v2 19/20 wic: Code cleanup: long lines, identation and whitespaces
In reply to Ed BartoshFixed pylint warnings bad-continuation, bad-continuation and line-too-long.
scripts/lib/image/engine.py +4 -1
@@ -236,7 +236,10 @@ def wic_list(args, scripts_path, properties_file): wks_file = args[0] fullpath = find_canned_image(scripts_path, wks_file) if not fullpath: - print "No image named %s found, exiting. (Use 'wic list images' to list available images, or specify a fully-qualified OE kickstart (.wks) filename)\n" % wks_file + print "No image named %s found, exiting. "\ + "(Use 'wic list images' to list available images, or "\ + "specify a fully-qualified OE kickstart (.wks) "\ + "filename)\n" % wks_file sys.exit(1) list_canned_image_help(scripts_path, fullpath) return True
scripts/lib/wic/conf.py +12 -14
@@ -30,20 +30,18 @@ def get_siteconf(): return scripts_path + "/lib/image/config/wic.conf" class ConfigMgr(object): - DEFAULTS = {'common': { - "distro_name": "Default Distribution", - "plugin_dir": "/usr/lib/wic/plugins", # TODO use prefix also? - }, - 'create': { - "tmpdir": '/var/tmp/wic', - "outdir": './wic-output', - - "release": None, - "logfile": None, - "name_prefix": None, - "name_suffix": None, - }, - } + DEFAULTS = { + 'common': { + "distro_name": "Default Distribution", + "plugin_dir": "/usr/lib/wic/plugins"}, # TODO use prefix also? + 'create': { + "tmpdir": '/var/tmp/wic', + "outdir": './wic-output', + "release": None, + "logfile": None, + "name_prefix": None, + "name_suffix": None} + } # make the manager class as singleton _instance = None
scripts/lib/wic/imager/direct.py +2 -2
@@ -179,8 +179,8 @@ class DirectImageCreator(BaseImageCreator): if parts[i].mountpoint and not parts[i].fstype: raise CreatorError("Failed to create disks, no --fstype " - "specified for partition with mountpoint " - "'%s' in the ks file") + "specified for partition with mountpoint " + "'%s' in the ks file") self._disk_names.append(disk_name)
scripts/lib/wic/kickstart/custom_commands/micboot.py +1 -1
@@ -27,7 +27,7 @@ class Mic_Bootloader(F8_Bootloader): forceLBA=False, location="", md5pass="", password="", upgrade=False, menus=""): F8_Bootloader.__init__(self, writePriority, appendLine, driveorder, - forceLBA, location, md5pass, password, upgrade) + forceLBA, location, md5pass, password, upgrade) self.menus = "" self.ptable = "msdos"
scripts/lib/wic/kickstart/custom_commands/partition.py +14 -6
@@ -157,7 +157,9 @@ class Wic_PartData(Mic_PartData): 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) + 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)
@@ -178,9 +180,14 @@ class Wic_PartData(Mic_PartData): plugins = pluginmgr.get_source_plugins() if self.source not in plugins: - msger.error("The '%s' --source specified for %s doesn't exist.\n\tSee '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) + 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, cr, cr_workdir, oe_builddir,
@@ -466,9 +473,10 @@ class Wic_Partition(Mic_Partition): removedAttrs = Mic_Partition.removedAttrs def _getParser(self): - def overhead_cb (option, opt_str, value, parser): + def overhead_cb(option, opt_str, value, parser): if value < 1: - raise OptionValueError("Option %s: invalid value: %r" % (option, value)) + raise OptionValueError("Option %s: invalid value: %r" % \ + (option, value)) setattr(parser.values, option.dest, value) op = Mic_Partition._getParser(self)
scripts/lib/wic/msger.py +12 -11
@@ -16,7 +16,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 import re import time
@@ -37,8 +38,8 @@ __ALL__ = ['set_mode', # COLORs in ANSI INFO_COLOR = 32 # green WARN_COLOR = 33 # yellow -ERR_COLOR = 31 # red -ASK_COLOR = 34 # blue +ERR_COLOR = 31 # red +ASK_COLOR = 34 # blue NO_COLOR = 0 PREFIX_RE = re.compile('^<(.*?)>\s*(.*)', re.S)
@@ -47,12 +48,12 @@ INTERACTIVE = True LOG_LEVEL = 1 LOG_LEVELS = { - 'quiet': 0, - 'normal': 1, - 'verbose': 2, - 'debug': 3, - 'never': 4, - } + 'quiet': 0, + 'normal': 1, + 'verbose': 2, + 'debug': 3, + 'never': 4, +} LOG_FILE_FP = None LOG_CONTENT = ''
@@ -75,7 +76,7 @@ def _general_print(head, color, msg=None, stream=None, level='normal'): errormsg = '' if CATCHERR_BUFFILE_FD > 0: - size = os.lseek(CATCHERR_BUFFILE_FD , 0, os.SEEK_END) + size = os.lseek(CATCHERR_BUFFILE_FD, 0, os.SEEK_END) os.lseek(CATCHERR_BUFFILE_FD, 0, os.SEEK_SET) errormsg = os.read(CATCHERR_BUFFILE_FD, size) os.ftruncate(CATCHERR_BUFFILE_FD, 0)
@@ -158,7 +159,7 @@ def _split_msg(head, msg): return head, msg def get_loglevel(): - return (k for k,v in LOG_LEVELS.items() if v==LOG_LEVEL).next() + return (k for k, v in LOG_LEVELS.items() if v == LOG_LEVEL).next() def set_loglevel(level): global LOG_LEVEL
scripts/lib/wic/plugins/source/bootimg-pcbios.py +3 -1
@@ -56,7 +56,9 @@ class BootimgPcbiosPlugin(SourcePlugin): msger.error("Unsupported partition table: %s" % cr.ptable_format) if not os.path.exists(mbrfile): - msger.error("Couldn't find %s. If using the -e option, do you have the right MACHINE set in local.conf? If not, is the bootimg_dir path correct?" % mbrfile) + msger.error("Couldn't find %s. If using the -e option, do you " + "have the right MACHINE set in local.conf? If not, " + "is the bootimg_dir path correct?" % mbrfile) full_path = cr._full_path(workdir, disk_name, "direct") msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
scripts/lib/wic/utils/partitionedfs.py +2 -3
@@ -302,9 +302,8 @@ class Image(object): msger.debug("partition %d: set UUID to %s" % \ (p['num'], p['uuid'])) exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \ - (p['num'], p['uuid'], - d['disk'].device), - self.native_sysroot) + (p['num'], p['uuid'], d['disk'].device), + self.native_sysroot) if p['boot']: flag_name = "legacy_boot" if d['ptable_format'] == 'gpt' else "boot"
scripts/lib/wic/utils/runner.py +1 -1
@@ -89,7 +89,7 @@ def show(cmdln_or_args): else: cmd = cmdln_or_args - msg = 'running command: "%s"' % cmd + msg = 'running command: "%s"' % cmd if out: out = out.strip() if out: msg += ', with output::'
scripts/wic +17 -9
@@ -90,18 +90,24 @@ def wic_create_subcommand(args, usage_str): parser = optparse.OptionParser(usage=usage_str) parser.add_option("-o", "--outdir", dest="outdir", - action="store", help="name of directory to create image in") + help="name of directory to create image in") parser.add_option("-e", "--image-name", dest="image_name", - action="store", help="name of the image to use the artifacts from e.g. core-image-sato") - parser.add_option("-r", "--rootfs-dir", dest="rootfs_dir", - action="callback", callback=callback_rootfs_dir, type="string", - help="path to the /rootfs dir to use as the .wks rootfs source") + help="name of the image to use the artifacts from " + "e.g. core-image-sato") + parser.add_option("-r", "--rootfs-dir", dest="rootfs_dir", type="string", + action="callback", callback=callback_rootfs_dir, + help="path to the /rootfs dir to use as the " + ".wks rootfs source") parser.add_option("-b", "--bootimg-dir", dest="bootimg_dir", - action="store", help="path to the dir containing the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the .wks bootimg source") + help="path to the dir containing the boot artifacts " + "(e.g. /EFI or /syslinux dirs) to use as the " + ".wks bootimg source") parser.add_option("-k", "--kernel-dir", dest="kernel_dir", - action="store", help="path to the dir containing the kernel to use in the .wks bootimg") + help="path to the dir containing the kernel to use " + "in the .wks bootimg") parser.add_option("-n", "--native-sysroot", dest="native_sysroot", - action="store", help="path to the native sysroot containing the tools to use to build the image") + help="path to the native sysroot containing the tools " + "to use to build the image") parser.add_option("-p", "--skip-build-check", dest="build_check", action="store_false", default=True, help="skip the build check") parser.add_option("-f", "--build-rootfs", action="store_true", help="build rootfs")
@@ -173,7 +179,9 @@ def wic_create_subcommand(args, usage_str): if not wks_file.endswith(".wks"): wks_file = engine.find_canned_image(scripts_path, wks_file) if not wks_file: - print "No image named %s found, exiting. (Use 'wic list images' to list available images, or specify a fully-qualified OE kickstart (.wks) filename)\n" % args[0] + print "No image named %s found, exiting. (Use 'wic list images' "\ + "to list available images, or specify a fully-qualified OE "\ + "kickstart (.wks) filename)\n" % args[0] sys.exit(1) image_output_dir = ""
Signature · 1 line
2.1.4
PATCH v2 20/20 wic: Code cleanup: unused imports
In reply to Ed BartoshFixed pylint warning unused-import
scripts/lib/image/engine.py +1 -9
@@ -30,18 +30,10 @@ import os import sys -from abc import ABCMeta, abstractmethod -import shlex -import json -import subprocess -import shutil -import os, sys, errno from wic import msger, creator -from wic.utils import cmdln, misc, errors -from wic.conf import configmgr +from wic.utils import misc from wic.plugin import pluginmgr -from wic.__version__ import VERSION from wic.utils.oe import misc
scripts/lib/wic/conf.py +1 -1
@@ -19,7 +19,7 @@ import os from wic import msger from wic import kickstart -from wic.utils import misc, runner, errors +from wic.utils import misc def get_siteconf():
scripts/lib/wic/imager/baseimager.py +1 -2
@@ -21,10 +21,9 @@ import os import tempfile import shutil -from wic import kickstart from wic import msger from wic.utils.errors import CreatorError -from wic.utils import misc, runner, fs_related as fs +from wic.utils import runner class BaseImageCreator(object): """Base class for image creation.
scripts/lib/wic/imager/direct.py +1 -1
@@ -28,7 +28,7 @@ import os import shutil from wic import kickstart, msger -from wic.utils import fs_related, runner, misc +from wic.utils import fs_related from wic.utils.partitionedfs import Image from wic.utils.errors import CreatorError, ImageError from wic.imager.baseimager import BaseImageCreator
scripts/lib/wic/pluginbase.py +0 -1
@@ -16,7 +16,6 @@ # Temple Place - Suite 330, Boston, MA 02111-1307, USA. from wic import msger -from wic.utils import errors class _Plugin(object): class __metaclass__(type):
scripts/lib/wic/plugins/imager/direct_plugin.py +1 -3
@@ -24,10 +24,8 @@ # Tom Zanussi <tom.zanussi (at] linux.intel.com> # -from wic import msger -from wic.utils import misc, fs_related, errors, runner, cmdln +from wic.utils import errors from wic.conf import configmgr -from wic.plugin import pluginmgr import wic.imager.direct as direct from wic.pluginbase import ImagerPlugin
scripts/lib/wic/plugins/source/bootimg-efi.py +0 -1
@@ -27,7 +27,6 @@ import os import shutil -from wic.utils.errors import ImageError from wic import kickstart, msger from wic.pluginbase import SourcePlugin from wic.utils.oe.misc import exec_cmd, exec_native_cmd, get_bitbake_var, \
scripts/lib/wic/utils/cmdln.py +0 -1
@@ -43,7 +43,6 @@ import sys import re import cmd import optparse -from pprint import pprint import sys
Signature · 1 line
2.1.4