[blivet:master 16/16] Use _resizefsUnit in resizeArgs() method implementations.
Vratislav Podzimek
vpodzime at redhat.com
Fri Jan 9 07:47:38 UTC 2015
On Thu, 2015-01-08 at 12:45 -0500, mulhern wrote:
> The reason it is used elsewhere, i.e., when calculating minimum size
> is because of the constraint on the resizeArgs() method to use the
> units defined by _resizefsUnit. This patch makes that explicit.
>
> The appropriate format string for the size specification for the particular
> resizing application and resizefsUnit combination is looked up dynamically
> during execution of resizeArgs(). Ideally, it would be calculated when
> the class is read, rather than at every invocation. However, due to the
> fact that the format string is a function of the class's resizefsUnit
> that is tricky. The only principled way to do it is to construct the class
> dynamically, passing the resizefsUnit value as an argument. This is
> definite overkill for this particular problem, so it seems better to
> accept this slightly wasteful dynamic calculation.
>
> There is no try/except KeyError block surrounding the FMT calculations.
> Since the key is known statically and does not change between one invocation
> and the next, this would be overkill.
>
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
> blivet/formats/fs.py | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
> index 17faf5b..ad2542a 100644
> --- a/blivet/formats/fs.py
> +++ b/blivet/formats/fs.py
> @@ -35,7 +35,8 @@ from ..flags import flags
> from parted import fileSystemType
> from ..storage_log import log_exception_info, log_method_call
> from .. import arch
> -from ..size import Size, ROUND_UP, ROUND_DOWN, MiB, B, unitStr
> +from ..size import Size, ROUND_UP, ROUND_DOWN, unitStr
> +from ..size import B, KiB, MiB, GiB, KB, MB, GB
> from ..i18n import _, N_
> from .. import udev
>
> @@ -1030,8 +1031,10 @@ class Ext2FS(FS):
>
> @property
> def resizeArgs(self):
> - argv = ["-p", self.device, "%dM" % (self.targetSize.convertTo(MiB))]
> - return argv
> + # No unit specifier is interpreted not as bytes, but block size.
> + FMT = {KiB: "%dK", MiB: "%dM", GiB: "%dG"}[self._resizefsUnit]
> + size_spec = FMT % self.targetSize.convertTo(self._resizefsUnit)
> + return ["-p", self.device, size_spec]
>
> register_device_format(Ext2FS)
>
> @@ -1423,11 +1426,12 @@ class NTFS(FS):
>
> @property
> def resizeArgs(self):
> + FMT = {B: "%d", KB: "%dK", MB: "%dM", GB: "%dG"}[self._resizefsUnit]
> + size_spec = FMT % self.targetSize.convertTo(self._resizefsUnit)
> +
> # You must supply at least two '-f' options to ntfsresize or
> # the proceed question will be presented to you.
> - argv = ["-ff", "-s", "%d" % self.targetSize.convertTo(B),
> - self.device]
> - return argv
> + return ["-ff", "-s", size_spec, self.device]
Looks good to me.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list