summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2015-06-27 13:28:50 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-02 23:08:37 +0100
commitb5dce25ddce631eaa7ebfdfbd3cc0bd4ab3845ca (patch)
treee6e99e4aaf84a6fa02ab4834f286b0e711875bd5
parent052c8198d783cf126594efac7969e49a7b3be99f (diff)
downloadpoky-b5dce25ddce631eaa7ebfdfbd3cc0bd4ab3845ca.tar.gz
wic: Refactor prepare_empty_partition API
Moved code out of prepare_empty_partition* methods to avoid code duplication. (From OE-Core rev: 7dc4e007aa9f02162b3f24705e9d9dba7a1cf7ef) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--scripts/lib/wic/kickstart/custom_commands/partition.py48
1 files changed, 12 insertions, 36 deletions
diff --git a/scripts/lib/wic/kickstart/custom_commands/partition.py b/scripts/lib/wic/kickstart/custom_commands/partition.py
index 0741bb2ab1..4e8a6a89b0 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):
160 self.prepare_swap_partition(cr_workdir, oe_builddir, 160 self.prepare_swap_partition(cr_workdir, oe_builddir,
161 native_sysroot) 161 native_sysroot)
162 elif self.fstype: 162 elif self.fstype:
163 rootfs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
164 if os.path.isfile(rootfs):
165 os.remove(rootfs)
163 for prefix in ("ext", "btrfs", "vfat", "squashfs"): 166 for prefix in ("ext", "btrfs", "vfat", "squashfs"):
164 if self.fstype.startswith(prefix): 167 if self.fstype.startswith(prefix):
165 method = getattr(self, 168 method = getattr(self,
166 "prepare_empty_partition_" + prefix) 169 "prepare_empty_partition_" + prefix)
167 method(cr_workdir, oe_builddir, native_sysroot) 170 method(rootfs, oe_builddir, native_sysroot)
171 self.source_file = rootfs
168 break 172 break
169 return 173 return
170 174
@@ -383,16 +387,13 @@ class Wic_PartData(Mic_PartData):
383 387
384 return 0 388 return 0
385 389
386 def prepare_empty_partition_ext(self, cr_workdir, oe_builddir, 390 def prepare_empty_partition_ext(self, rootfs, oe_builddir,
387 native_sysroot): 391 native_sysroot):
388 """ 392 """
389 Prepare an empty ext2/3/4 partition. 393 Prepare an empty ext2/3/4 partition.
390 """ 394 """
391 fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
392
393 os.path.isfile(fs) and os.remove(fs)
394 dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ 395 dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
395 (fs, self.size) 396 (rootfs, self.size)
396 exec_cmd(dd_cmd) 397 exec_cmd(dd_cmd)
397 398
398 extra_imagecmd = "-i 8192" 399 extra_imagecmd = "-i 8192"
@@ -402,23 +403,16 @@ class Wic_PartData(Mic_PartData):
402 label_str = "-L %s" % self.label 403 label_str = "-L %s" % self.label
403 404
404 mkfs_cmd = "mkfs.%s -F %s %s %s" % \ 405 mkfs_cmd = "mkfs.%s -F %s %s %s" % \
405 (self.fstype, extra_imagecmd, label_str, fs) 406 (self.fstype, extra_imagecmd, label_str, rootfs)
406 exec_native_cmd(mkfs_cmd, native_sysroot) 407 exec_native_cmd(mkfs_cmd, native_sysroot)
407 408
408 self.source_file = fs 409 def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
409
410 return 0
411
412 def prepare_empty_partition_btrfs(self, cr_workdir, oe_builddir,
413 native_sysroot): 410 native_sysroot):
414 """ 411 """
415 Prepare an empty btrfs partition. 412 Prepare an empty btrfs partition.
416 """ 413 """
417 fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
418
419 os.path.isfile(fs) and os.remove(fs)
420 dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ 414 dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
421 (fs, self.size) 415 (rootfs, self.size)
422 exec_cmd(dd_cmd) 416 exec_cmd(dd_cmd)
423 417
424 label_str = "" 418 label_str = ""
@@ -426,21 +420,14 @@ class Wic_PartData(Mic_PartData):
426 label_str = "-L %s" % self.label 420 label_str = "-L %s" % self.label
427 421
428 mkfs_cmd = "mkfs.%s -b %d %s %s" % \ 422 mkfs_cmd = "mkfs.%s -b %d %s %s" % \
429 (self.fstype, self.size * 1024, label_str, fs) 423 (self.fstype, self.size * 1024, label_str, rootfs)
430 exec_native_cmd(mkfs_cmd, native_sysroot) 424 exec_native_cmd(mkfs_cmd, native_sysroot)
431 425
432 self.source_file = fs 426 def prepare_empty_partition_vfat(self, rootfs, oe_builddir,
433
434 return 0
435
436 def prepare_empty_partition_vfat(self, cr_workdir, oe_builddir,
437 native_sysroot): 427 native_sysroot):
438 """ 428 """
439 Prepare an empty vfat partition. 429 Prepare an empty vfat partition.
440 """ 430 """
441 fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
442 os.path.isfile(fs) and os.remove(fs)
443
444 blocks = self.size 431 blocks = self.size
445 432
446 label_str = "-n boot" 433 label_str = "-n boot"
@@ -453,10 +440,6 @@ class Wic_PartData(Mic_PartData):
453 chmod_cmd = "chmod 644 %s" % fs 440 chmod_cmd = "chmod 644 %s" % fs
454 exec_cmd(chmod_cmd) 441 exec_cmd(chmod_cmd)
455 442
456 self.source_file = fs
457
458 return 0
459
460 def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir, 443 def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
461 native_sysroot): 444 native_sysroot):
462 """ 445 """
@@ -484,9 +467,6 @@ class Wic_PartData(Mic_PartData):
484 fs_size = out.split()[0] 467 fs_size = out.split()[0]
485 468
486 self.size = fs_size 469 self.size = fs_size
487 self.source_file = fs
488
489 return 0
490 470
491 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot): 471 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
492 """ 472 """
@@ -505,10 +485,6 @@ class Wic_PartData(Mic_PartData):
505 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), fs) 485 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), fs)
506 exec_native_cmd(mkswap_cmd, native_sysroot) 486 exec_native_cmd(mkswap_cmd, native_sysroot)
507 487
508 self.source_file = fs
509
510 return 0
511
512class Wic_Partition(Mic_Partition): 488class Wic_Partition(Mic_Partition):
513 removedKeywords = Mic_Partition.removedKeywords 489 removedKeywords = Mic_Partition.removedKeywords
514 removedAttrs = Mic_Partition.removedAttrs 490 removedAttrs = Mic_Partition.removedAttrs