From 3d4da9186016d54b76ad2fa710646de253f0f063 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Wed, 4 Feb 2015 23:45:02 +0100 Subject: wic: use kB for the partitions size Use kB instead of MB for the partition size to get a better granularity. This is needed on some SoC (i.mx, omap) where it is necessary to create partitions as small as 64kB. Keep the backward compatibility by assuming MB when no unit is provided. Signed-off-by: Alexandre Belloni Tested-by: Maciej Borzecki Acked-by: Tom Zanussi Tested-by: Tom Zanussi Signed-off-by: Ross Burton --- .../wic/3rdparty/pykickstart/commands/partition.py | 4 ++-- scripts/lib/wic/3rdparty/pykickstart/options.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'scripts/lib/wic/3rdparty') diff --git a/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py b/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py index 56b91aa9d9..b564b1a7ab 100644 --- a/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py +++ b/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py @@ -78,7 +78,7 @@ class FC3_PartData(BaseData): if self.recommended: retval += " --recommended" if self.size and self.size != 0: - retval += " --size=%s" % self.size + retval += " --size=%sk" % self.size if hasattr(self, "start") and self.start != 0: retval += " --start=%s" % self.start @@ -216,7 +216,7 @@ class FC3_Partition(KickstartCommand): callback=part_cb, nargs=1, type="string") op.add_option("--recommended", dest="recommended", action="store_true", default=False) - op.add_option("--size", dest="size", action="store", type="int", + op.add_option("--size", dest="size", action="store", type="size", nargs=1) op.add_option("--start", dest="start", action="store", type="int", nargs=1) diff --git a/scripts/lib/wic/3rdparty/pykickstart/options.py b/scripts/lib/wic/3rdparty/pykickstart/options.py index 341c5d7298..b2d8e3e516 100644 --- a/scripts/lib/wic/3rdparty/pykickstart/options.py +++ b/scripts/lib/wic/3rdparty/pykickstart/options.py @@ -143,6 +143,24 @@ def _check_string(option, opt, value): else: return value +def _check_size(option, opt, value): + # Former default was MB + if (value.isdigit()): + return int(value) * 1024L + + mapping = {"opt": opt, "value": value} + if (not value[:-1].isdigit()): + raise OptionValueError(_("Option %(opt)s: invalid size value: %(value)r") % mapping) + + size = int(value[:-1]) + if (value.endswith("k") or value.endswith("K")): + return size + if (value.endswith("M")): + return size * 1024L + if (value.endswith("G")): + return size * 1024L * 1024L + raise OptionValueError(_("Option %(opt)s: invalid size value: %(value)r") % mapping) + # Creates a new Option class that supports several new attributes: # - required: any option with this attribute must be supplied or an exception # is thrown @@ -169,10 +187,11 @@ class KSOption (Option): ACTIONS = Option.ACTIONS + ("map", "map_extend",) STORE_ACTIONS = Option.STORE_ACTIONS + ("map", "map_extend",) - TYPES = Option.TYPES + ("ksboolean", "string") + TYPES = Option.TYPES + ("ksboolean", "string", "size") TYPE_CHECKER = copy(Option.TYPE_CHECKER) TYPE_CHECKER["ksboolean"] = _check_ksboolean TYPE_CHECKER["string"] = _check_string + TYPE_CHECKER["size"] = _check_size def _check_required(self): if self.required and not self.takes_value(): -- cgit v1.2.3