From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [wic][PATCH 12/20] wic: Refactor prepare_empty_partition API
Date: Mon, 29 Jun 2015 22:10:25 +0300 [thread overview]
Message-ID: <1435605033-11509-13-git-send-email-ed.bartosh@linux.intel.com> (raw)
In-Reply-To: <1435605033-11509-1-git-send-email-ed.bartosh@linux.intel.com>
Moved code out of prepare_empty_partition* methods
to avoid code duplication.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
diff --git a/scripts/lib/wic/kickstart/custom_commands/partition.py b/scripts/lib/wic/kickstart/custom_commands/partition.py
index 0741bb2..4e8a6a8 100644
--- a/scripts/lib/wic/kickstart/custom_commands/partition.py
+++ b/scripts/lib/wic/kickstart/custom_commands/partition.py
@@ -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
--
2.1.4
next prev parent reply other threads:[~2015-06-29 19:11 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-29 19:10 [wic][PATCH 00/20] miscellaneous fixes. poky-conrib:ed/wic/misc Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 01/20] wic: Fix misleading message Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 02/20] wic: Test rootfs plugin using image recipes Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 03/20] wic: Test rootfs plugin using rootfs paths Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 04/20] wic: Refactor getting bitbake variables Ed Bartosh
2015-06-29 21:48 ` Christopher Larson
2015-06-30 8:11 ` Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 05/20] wic: Include mount point into image report Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 06/20] wic: Remove annoing debug message Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 07/20] wic: Turn off debug output for 'bitbake -e' Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 08/20] wic: Refactor prepare_rootfs API Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 09/20] wic: Rename partition images Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 10/20] wic: Get rid of useless variable 'image_rootfs' Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 11/20] wic: Call methods better way Ed Bartosh
2015-06-29 19:10 ` Ed Bartosh [this message]
2015-06-29 19:10 ` [wic][PATCH 13/20] wic: Remove duplicated code Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 14/20] wic: Fix naming conflict Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 15/20] wic: Add --uuid partition option Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 16/20] wic: Refactor fstab update code Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 17/20] wic: Remove __write_partition method Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 18/20] wic: Fix confusing error message Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 19/20] wic: Code cleanup: long lines, identation and whitespaces Ed Bartosh
2015-06-29 19:10 ` [wic][PATCH 20/20] wic: Code cleanup: unused imports Ed Bartosh
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=1435605033-11509-13-git-send-email-ed.bartosh@linux.intel.com \
--to=ed.bartosh@linux.intel.com \
--cc=openembedded-core@lists.openembedded.org \
/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