[elbe-devel] [PATCH 2/5] elbepack: shellhelper: rename allow_fail to check

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon May 6 10:07:48 CEST 2024


This matches the naming of the stdlib subprocess package.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/asyncworker.py   |  2 +-
 elbepack/commands/init.py |  2 +-
 elbepack/elbeproject.py   |  4 ++--
 elbepack/hdimg.py         | 24 ++++++++++++------------
 elbepack/imgutils.py      |  2 +-
 elbepack/shellhelper.py   | 14 +++++++-------
 elbepack/updatepkg.py     |  2 +-
 7 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/elbepack/asyncworker.py b/elbepack/asyncworker.py
index 810137c86008..f1149bbd3348 100644
--- a/elbepack/asyncworker.py
+++ b/elbepack/asyncworker.py
@@ -451,7 +451,7 @@ class SaveVersionJob(AsyncWorkerJob):
             do((f'{self.project.savesh_file} "{self.project.builddir} '
                 f'{self.project.xml.text("project/version")} '
                 f'{self.project.xml.text("project/name")}"'
-                ), allow_fail=True)
+                ), check=False)
 
         logging.info('Enqueueing project to save package archive')
         AsyncWorkerJob.enqueue(self, queue, db)
diff --git a/elbepack/commands/init.py b/elbepack/commands/init.py
index 4149ca344370..64a7e8e5666f 100644
--- a/elbepack/commands/init.py
+++ b/elbepack/commands/init.py
@@ -207,7 +207,7 @@ def run_command(argv):
                  --no-default-keyring \
                  --keyring {import_keyring} --import',
            stdin=''.join(keys).encode('ascii'),
-           allow_fail=True,
+           check=False,
            env_add={'GNUPGHOME': out_path})
 
         export_keyring = import_keyring + '.gpg'
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index cb400f26a5b4..105a272bb102 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -293,7 +293,7 @@ class ElbeProject:
 
         paths = self.get_sysroot_paths()
 
-        do(f'rm {sysrootfilelist}', allow_fail=True)
+        do(f'rm {sysrootfilelist}', check=False)
         os.chdir(self.sysrootpath)
         for p in paths:
             do(f'find -path "{p}" >> {sysrootfilelist}')
@@ -675,7 +675,7 @@ class ElbeProject:
             logging.info('Postbuild script')
             cmd = (f' "{self.builddir} {self.xml.text("project/version")} '
                    f'{self.xml.text("project/name")}"')
-            do(self.postbuild_file + cmd, allow_fail=True)
+            do(self.postbuild_file + cmd, check=False)
 
         do_prj_finetuning(self.xml,
                           self.buildenv,
diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 515528e6721b..31a4a5190dcd 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -189,14 +189,14 @@ class grubinstaller202(grubinstaller_base):
 
         finally:
             os.unlink(imagemntfs.fname('boot/grub/device.map'))
-            do(f"umount {imagemntfs.fname('dev')}", allow_fail=True)
-            do(f"umount {imagemntfs.fname('proc')}", allow_fail=True)
-            do(f"umount {imagemntfs.fname('sys')}", allow_fail=True)
+            do(f"umount {imagemntfs.fname('dev')}", check=False)
+            do(f"umount {imagemntfs.fname('proc')}", check=False)
+            do(f"umount {imagemntfs.fname('sys')}", check=False)
 
             for entry in reversed(self.fs.depthlist()):
                 do(
                     f'umount {loopdev}p{entry.partnum}',
-                    allow_fail=True)
+                    check=False)
 
 
 class grubinstaller97(grubinstaller_base):
@@ -251,14 +251,14 @@ class grubinstaller97(grubinstaller_base):
 
         finally:
             os.unlink(imagemntfs.fname('boot/grub/device.map'))
-            do(f"umount {imagemntfs.fname('dev')}", allow_fail=True)
-            do(f"umount {imagemntfs.fname('proc')}", allow_fail=True)
-            do(f"umount {imagemntfs.fname('sys')}", allow_fail=True)
+            do(f"umount {imagemntfs.fname('dev')}", check=False)
+            do(f"umount {imagemntfs.fname('proc')}", check=False)
+            do(f"umount {imagemntfs.fname('sys')}", check=False)
 
             for entry in reversed(self.fs.depthlist()):
                 do(
                     f'umount {loopdev}p{entry.partnum}',
-                    allow_fail=True)
+                    check=False)
 
 
 class simple_fstype:
@@ -334,7 +334,7 @@ def create_label(disk, part, ppart, fslabel, target, grub):
             do(
                 f'cp -a "{os.path.join(target, "filesystems", entry.id)}/." '
                 f'"{mount_path}/"',
-                allow_fail=True)
+                check=False)
         finally:
             do(f'umount {loopdev}')
 
@@ -404,7 +404,7 @@ def do_image_hd(hd, fslabel, target, grub_version, grub_fw_type=None):
     size_in_sectors = s // sector_size
 
     imagename = os.path.join(target, hd.text('name'))
-    do(f'rm -f "{imagename}"', allow_fail=True)
+    do(f'rm -f "{imagename}"', check=False)
     f = open(imagename, 'wb')
     f.truncate(size_in_sectors * sector_size)
     f.close()
@@ -539,7 +539,7 @@ def do_hdimg(xml, target, rfs, grub_version, grub_fw_type=None):
             do(
                f'mv "{rfs.fname(lic.mountpoint)}"/* '
                f'"{os.path.join(fspath, lic.id)}"',
-               allow_fail=True)
+               check=False)
 
     try:
         # Now iterate over all images and create filesystems and partitions
@@ -571,7 +571,7 @@ def do_hdimg(xml, target, rfs, grub_version, grub_fw_type=None):
                 do(
                    f'mv "{os.path.join(fspath, i.id)}"/* '
                    f'"{rfs.fname(i.mountpoint)}"',
-                   allow_fail=True)
+                   check=False)
 
     # Files are now moved back. ubinize needs files in place, so we run it now.
     for i in xml.tgt.node('images'):
diff --git a/elbepack/imgutils.py b/elbepack/imgutils.py
index 672eeac588b1..e74b46bc41f3 100644
--- a/elbepack/imgutils.py
+++ b/elbepack/imgutils.py
@@ -16,4 +16,4 @@ def losetup(dev, extra_args=[]):
     try:
         yield loopdev
     finally:
-        do(f'losetup --detach {loopdev}', allow_fail=True)
+        do(f'losetup --detach {loopdev}', check=False)
diff --git a/elbepack/shellhelper.py b/elbepack/shellhelper.py
index 088939761c28..3b217e4032f9 100644
--- a/elbepack/shellhelper.py
+++ b/elbepack/shellhelper.py
@@ -22,10 +22,10 @@ def _log_cmd(cmd):
         return shlex.join(map(os.fspath, cmd))
 
 
-def do(cmd, /, *, allow_fail=False, stdin=None, env_add=None, log_cmd=None):
+def do(cmd, /, *, check=True, stdin=None, env_add=None, log_cmd=None):
     """do() - Execute cmd in a shell and redirect outputs to logging.
 
-    Throws a subprocess.CalledProcessError if cmd returns none-zero and allow_fail=False
+    Throws a subprocess.CalledProcessError if cmd returns none-zero and check=True
 
     --
 
@@ -37,7 +37,7 @@ def do(cmd, /, *, allow_fail=False, stdin=None, env_add=None, log_cmd=None):
     >>> do("true")
     [CMD] true
 
-    >>> do("false", allow_fail=True)
+    >>> do("false", check=False)
     [CMD] false
 
     >>> do("cat -", stdin=b"ELBE")
@@ -65,7 +65,7 @@ def do(cmd, /, *, allow_fail=False, stdin=None, env_add=None, log_cmd=None):
 
     with async_logging_ctx() as w:
         subprocess.run(cmd, shell=_is_shell_cmd(cmd), stdout=w, stderr=subprocess.STDOUT,
-                       env=new_env, check=not allow_fail, input=stdin)
+                       env=new_env, check=check, input=stdin)
 
 
 def chroot(directory, cmd, /, *, env_add=None, **kwargs):
@@ -97,7 +97,7 @@ def chroot(directory, cmd, /, *, env_add=None, **kwargs):
         do(['chroot', directory] + cmd, env_add=new_env, **kwargs)
 
 
-def get_command_out(cmd, /, *, stdin=None, allow_fail=False, env_add=None):
+def get_command_out(cmd, /, *, stdin=None, check=True, env_add=None):
     """get_command_out() - Like do() but returns stdout.
 
     --
@@ -116,7 +116,7 @@ def get_command_out(cmd, /, *, stdin=None, allow_fail=False, env_add=None):
     ...
     subprocess.CalledProcessError: ...
 
-    >>> get_command_out("false", allow_fail=True)
+    >>> get_command_out("false", check=False)
     b''
 
     >>> get_command_out("cat -", stdin=b"ELBE", env_add={"TRUE":"true"})
@@ -138,7 +138,7 @@ def get_command_out(cmd, /, *, stdin=None, allow_fail=False, env_add=None):
 
     with async_logging_ctx() as w:
         ps = subprocess.run(cmd, shell=_is_shell_cmd(cmd), stdout=subprocess.PIPE, stderr=w,
-                            env=new_env, check=not allow_fail, input=stdin)
+                            env=new_env, check=check, input=stdin)
         return ps.stdout
 
 
diff --git a/elbepack/updatepkg.py b/elbepack/updatepkg.py
index 2295ee9a5027..ab0391823a16 100644
--- a/elbepack/updatepkg.py
+++ b/elbepack/updatepkg.py
@@ -141,4 +141,4 @@ def gen_update_pkg(project, xml_filename, upd_filename,
         logging.info('Postbuild script')
         cmd = (f' "{upd_filename} {project.xml.text("project/version")} '
                f'{project.xml.text("project/name")}"')
-        do(project.postbuild_file + cmd, allow_fail=True)
+        do(project.postbuild_file + cmd, check=False)

-- 
2.45.0



More information about the elbe-devel mailing list