[elbe-devel] [PATCH 6/7] elbepack: finetuning: use mount helper

Thomas Weißschuh thomas.weissschuh at linutronix.de
Tue May 7 11:54:42 CEST 2024


Make use of its automatic resource management and better ergonomics.
Also drop the now unused class ImgMountFilesystem.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/filesystem.py | 17 -----------------
 elbepack/finetuning.py | 14 ++++++++------
 2 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index 41cabb92f8a7..b159d7c23a1f 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -10,8 +10,6 @@ from glob import glob
 from string import digits
 from tempfile import mkdtemp
 
-from elbepack.shellhelper import do
-
 
 def size_to_int(size):
     if size[-1] in digits:
@@ -481,18 +479,3 @@ class TmpdirFilesystem (Filesystem):
     def __exit__(self, exec_type, exec_value, tb):
         self.delete()
         return False
-
-
-class ImgMountFilesystem(Filesystem):
-    def __init__(self, mntpoint, dev):
-        Filesystem.__init__(self, mntpoint)
-
-        self.dev = dev
-
-    def __enter__(self):
-        do(f'mount "{self.dev}" "{self.path}"')
-
-        return self
-
-    def __exit__(self, typ, value, traceback):
-        do(f'umount "{self.path}"')
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index a10c89e55ea3..3a95c440650e 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -15,8 +15,8 @@ from gpg import core
 from gpg.constants import PROTOCOL_OpenPGP
 
 from elbepack.egpg import unlock_key
-from elbepack.filesystem import ImgMountFilesystem
-from elbepack.imgutils import losetup
+from elbepack.filesystem import Filesystem
+from elbepack.imgutils import losetup, mount
 from elbepack.packers import default_packer, packers
 from elbepack.repomanager import UpdateRepo
 from elbepack.rpcaptcache import get_rpcaptcache
@@ -328,9 +328,9 @@ class CmdAction(ImageFinetuningAction):
                env_add={'ELBE_DEV': dev},
                log_cmd=script)
         else:
-            with ImgMountFilesystem(mnt, dev) as fs:
+            with mount(dev, mnt):
                 do('/bin/sh', input=script.encode('ascii'),
-                   env_add={'ELBE_MNT': fs.path},
+                   env_add={'ELBE_MNT': mnt},
                    log_cmd=script)
 
     def execute(self, _buildenv, target):
@@ -555,7 +555,8 @@ class CopyFromPartition(ImageFinetuningAction):
         img_mnt = os.path.join(builddir, 'imagemnt')
         device = f'{loop_dev}p{part_nr}'
 
-        with ImgMountFilesystem(img_mnt, device) as mnt_fs:
+        with mount(device, img_mnt.path) as mnt_fs:
+            mnt_fs = Filesystem(img_mnt)
             fname = mnt_fs.glob(self.node.et.text)
 
             if not fname:
@@ -587,7 +588,8 @@ class CopyToPartition(ImageFinetuningAction):
         img_mnt = os.path.join(builddir, 'imagemnt')
         device = f'{loop_dev}p{part_nr}'
 
-        with ImgMountFilesystem(img_mnt, device) as mnt_fs:
+        with mount(device, img_mnt):
+            mnt_fs = Filesystem(img_mnt)
             fname = mnt_fs.fname(self.node.et.text)
             do(f'cp -av "{os.path.join(builddir, aname)}" "{fname}"')
 

-- 
2.45.0



More information about the elbe-devel mailing list