[elbe-devel] [PATCH v2 8/8] elbepack: hdimg: simplify grub device.map handling
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Wed May 8 16:03:27 CEST 2024
Use some helper functions to simplify the code.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/hdimg.py | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index c246a1f42396..3dc1af82c619 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -161,11 +161,9 @@ class grubinstaller202(grubinstaller_base):
stack.enter_context(
mount(bindmnt, imagemntfs.fname(bindmnt), bind=True))
- do(f'mkdir -p "{imagemntfs.fname("boot/grub")}"')
-
- devmap = open(imagemntfs.fname('boot/grub/device.map'), 'w')
- devmap.write(f'(hd0) {loopdev}\n')
- devmap.close()
+ imagemntfs.mkdir_p('boot/grub')
+ imagemntfs.write_file('boot/grub/device.map', 0o644, f'(hd0) {loopdev}\n')
+ stack.callback(imagemntfs.remove, 'boot/grub/device.map')
chroot(imagemnt, ['update-grub2'])
@@ -188,9 +186,6 @@ class grubinstaller202(grubinstaller_base):
except subprocess.CalledProcessError as E:
logging.error('Fail installing grub device: %s', E)
- finally:
- os.unlink(imagemntfs.fname('boot/grub/device.map'))
-
class grubinstaller97(grubinstaller_base):
@@ -221,11 +216,9 @@ class grubinstaller97(grubinstaller_base):
stack.enter_context(
mount(bindmnt, imagemntfs.fname(bindmnt), bind=True))
- do(f'mkdir -p "{imagemntfs.fname("boot/grub")}"')
-
- devmap = open(imagemntfs.fname('boot/grub/device.map'), 'w')
- devmap.write(f'(hd0) {loopdev}\n')
- devmap.close()
+ imagemntfs.mkdir_p('boot/grub')
+ imagemntfs.write_file('boot/grub/device.map', 0o644, f'(hd0) {loopdev}\n')
+ stack.callback(imagemntfs.remove, 'boot/grub/device.map')
# Replace groot and kopt because else they will be given
# bad values
@@ -241,9 +234,6 @@ class grubinstaller97(grubinstaller_base):
except subprocess.CalledProcessError as E:
logging.error('Fail installing grub device: %s', E)
- finally:
- os.unlink(imagemntfs.fname('boot/grub/device.map'))
-
class simple_fstype:
def __init__(self, typ):
--
2.45.0
More information about the elbe-devel
mailing list