[elbe-devel] [PATCH 4/5] elbepack: simplify implementation of command chroot

Thomas Weißschuh thomas.weissschuh at linutronix.de
Fri Apr 5 11:53:58 CEST 2024


Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/chroot.py | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/elbepack/commands/chroot.py b/elbepack/commands/chroot.py
index d16bd2d76fd3..b5a441cf1cee 100644
--- a/elbepack/commands/chroot.py
+++ b/elbepack/commands/chroot.py
@@ -57,15 +57,11 @@ def run_command(argv):
             for c in cmd2:
                 cmd += (c + ' ')
 
-        if opt.target:
-            try:
-                with project.targetfs:
-                    system(f'/usr/sbin/chroot {project.targetpath} {cmd}')
-            except subprocess.CalledProcessError as e:
-                print(repr(e))
-        else:
-            try:
-                with project.buildenv:
-                    system(f'/usr/sbin/chroot {project.chrootpath} {cmd}')
-            except subprocess.CalledProcessError as e:
-                print(repr(e))
+        chroot, path = (project.targetfs, project.targetpath) if opt.target else \
+                       (project.buildenv, project.chrootpath)
+
+        try:
+            with chroot:
+                system(f'/usr/sbin/chroot {path} {cmd}')
+        except subprocess.CalledProcessError as e:
+            print(repr(e))

-- 
2.44.0



More information about the elbe-devel mailing list