[elbe-devel] [PATCH v2 12/27] hdimg: use integer division for size

Torben Hohn torben.hohn at linutronix.de
Thu Sep 24 16:56:09 CEST 2020


with python3 the size calculation fails:

Traceback (most recent call last):
  File "/var/cache/elbe/devel/elbepack/asyncworker.py", line 194, in execute
    skip_pbuild=self.skip_pbuilder)
  File "/var/cache/elbe/devel/elbepack/elbeproject.py", line 686, in build
    self.targetfs.part_target(self.builddir, grub_version, grub_fw_type)
  File "/var/cache/elbe/devel/elbepack/efilesystem.py", line 425, in part_target
    grub_fw_type)
  File "/var/cache/elbe/devel/elbepack/hdimg.py", line 569, in do_hdimg
    grub_fw_type)
  File "/var/cache/elbe/devel/elbepack/hdimg.py", line 445, in do_image_hd
    current_sector)
  File "/var/cache/elbe/devel/elbepack/hdimg.py", line 322, in create_partition
    g = parted.Geometry(device=disk.device, start=current_sector, length=sz)
  File "/usr/lib/python3/dist-packages/parted/decorators.py", line 42, in new
    ret = fn(*args, **kwds)
  File "/usr/lib/python3/dist-packages/parted/geometry.py", line 56, in __init__
    self.__geometry = _ped.Geometry(self.device.getPedDevice(), start, length)
TypeError: integer argument expected, got float

Use the integer division from python3

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/hdimg.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 5af46de4c..1d22cd49d 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -317,7 +317,7 @@ def create_partition(
     elif part.text("size") == "remain":
         sz = size_in_sectors - current_sector
     else:
-        sz = size_to_int(part.text("size")) / sector_size
+        sz = size_to_int(part.text("size")) // sector_size
 
     g = parted.Geometry(device=disk.device, start=current_sector, length=sz)
     if ptype != parted.PARTITION_EXTENDED and \
@@ -409,7 +409,7 @@ def do_image_hd(hd, fslabel, target, grub_version, grub_fw_type=None):
 
     sector_size = 512
     s = size_to_int(hd.text("size"))
-    size_in_sectors = s / sector_size
+    size_in_sectors = s // sector_size
 
     imagename = os.path.join(target, hd.text("name"))
     do('rm -f "%s"' % imagename, allow_fail=True)
-- 
2.20.1



More information about the elbe-devel mailing list