diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2015-06-27 12:56:38 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-07-02 23:01:32 +0100 |
commit | 066f713f71828ff6f408448e5ea4fcd56faa423e (patch) | |
tree | 36261e714c6323d2799cb51284db38799aadb7cf | |
parent | 4570412f70188d36312a5f9944d81df884302520 (diff) | |
download | openembedded-core-066f713f71828ff6f408448e5ea4fcd56faa423e.tar.gz openembedded-core-066f713f71828ff6f408448e5ea4fcd56faa423e.tar.bz2 openembedded-core-066f713f71828ff6f408448e5ea4fcd56faa423e.zip |
wic: Call methods better way
Shortened code by using getattr to obtain a method to call for
prepare_empty_partition_* and prepare_rootfs_* methods.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
-rw-r--r-- | scripts/lib/wic/kickstart/custom_commands/partition.py | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/scripts/lib/wic/kickstart/custom_commands/partition.py b/scripts/lib/wic/kickstart/custom_commands/partition.py index e3ae3ce765..0741bb2ab1 100644 --- a/scripts/lib/wic/kickstart/custom_commands/partition.py +++ b/scripts/lib/wic/kickstart/custom_commands/partition.py @@ -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): """ |