[elbe-devel] [PATCH 3/5] elbepack: shellhelper: rename stdin to input

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


This matches the naming of the stdlib subprocess package.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/init.py |  2 +-
 elbepack/egpg.py          |  2 +-
 elbepack/finetuning.py    | 10 +++++-----
 elbepack/rfs.py           |  3 +--
 elbepack/shellhelper.py   | 24 ++++++++++++------------
 5 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/elbepack/commands/init.py b/elbepack/commands/init.py
index 64a7e8e5666f..02f0a4f5c287 100644
--- a/elbepack/commands/init.py
+++ b/elbepack/commands/init.py
@@ -206,7 +206,7 @@ def run_command(argv):
         do(f'gpg --no-options \
                  --no-default-keyring \
                  --keyring {import_keyring} --import',
-           stdin=''.join(keys).encode('ascii'),
+           input=''.join(keys).encode('ascii'),
            check=False,
            env_add={'GNUPGHOME': out_path})
 
diff --git a/elbepack/egpg.py b/elbepack/egpg.py
index 3ddaa4ab99ab..d4f951d90217 100644
--- a/elbepack/egpg.py
+++ b/elbepack/egpg.py
@@ -292,7 +292,7 @@ def unarmor_openpgp_keyring(armored):
     Returns a binary string (empty for invalid keys).
     """
     try:
-        conv_cmd = get_command_out('/usr/bin/gpg --no-options --dearmor', stdin=armored)
+        conv_cmd = get_command_out('/usr/bin/gpg --no-options --dearmor', input=armored)
     except subprocess.CalledProcessError as e:
         logging.error(e)
         return b''
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index a21bc1aa9d59..a6d30dcd0c5d 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -227,7 +227,7 @@ class AddUserAction(FinetuningAction):
 
             if 'passwd_hashed' in att:
                 chroot(target.path, ['chpasswd', '--encrypted'],
-                       stdin=f"{self.node.et.text}:{att['passwd_hashed']}")
+                       input=f"{self.node.et.text}:{att['passwd_hashed']}")
 
 
 @FinetuningAction.register('addgroup')
@@ -324,18 +324,18 @@ class CmdAction(ImageFinetuningAction):
         dev = f"{loop_dev}p{self.node.et.attrib['part']}"
 
         if self.node.bool_attr('nomount'):
-            do('/bin/sh', stdin=script,
+            do('/bin/sh', input=script,
                env_add={'ELBE_DEV': dev},
                log_cmd=script)
         else:
             with ImgMountFilesystem(mnt, dev) as fs:
-                do('/bin/sh', stdin=script,
+                do('/bin/sh', input=script,
                    env_add={'ELBE_MNT': fs.path},
                    log_cmd=script)
 
     def execute(self, _buildenv, target):
         with target:
-            chroot(target.path, '/bin/sh', stdin=self.node.et.text, log_cmd=self.node.et.text)
+            chroot(target.path, '/bin/sh', input=self.node.et.text, log_cmd=self.node.et.text)
 
 
 @FinetuningAction.register('buildenv_command')
@@ -343,7 +343,7 @@ class BuildenvCmdAction(FinetuningAction):
 
     def execute(self, buildenv, _target):
         with buildenv:
-            chroot(buildenv.path, '/bin/sh', stdin=self.node.et.text)
+            chroot(buildenv.path, '/bin/sh', input=self.node.et.text)
 
 
 @FinetuningAction.register('purge')
diff --git a/elbepack/rfs.py b/elbepack/rfs.py
index 9d49b48160ef..ee30bf917816 100644
--- a/elbepack/rfs.py
+++ b/elbepack/rfs.py
@@ -310,8 +310,7 @@ class BuildEnv:
 
     def seed_etc(self):
         passwd = self.xml.text('target/passwd_hashed')
-        stdin = f'root:{passwd}'
-        chroot(self.rfs.path, ['chpasswd', '--encrypted'], stdin=stdin)
+        chroot(self.rfs.path, ['chpasswd', '--encrypted'], input='root:' + passwd)
 
         hostname = self.xml.text('target/hostname')
         fqdn = hostname
diff --git a/elbepack/shellhelper.py b/elbepack/shellhelper.py
index 3b217e4032f9..d0e0d7a11a04 100644
--- a/elbepack/shellhelper.py
+++ b/elbepack/shellhelper.py
@@ -22,7 +22,7 @@ def _log_cmd(cmd):
         return shlex.join(map(os.fspath, cmd))
 
 
-def do(cmd, /, *, check=True, stdin=None, env_add=None, log_cmd=None):
+def do(cmd, /, *, check=True, input=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 check=True
@@ -40,10 +40,10 @@ def do(cmd, /, *, check=True, stdin=None, env_add=None, log_cmd=None):
     >>> do("false", check=False)
     [CMD] false
 
-    >>> do("cat -", stdin=b"ELBE")
+    >>> do("cat -", input=b"ELBE")
     [CMD] cat -
 
-    >>> do("cat - && false", stdin=b"ELBE") # doctest: +ELLIPSIS
+    >>> do("cat - && false", input=b"ELBE") # doctest: +ELLIPSIS
     Traceback (most recent call last):
     ...
     subprocess.CalledProcessError: ...
@@ -58,14 +58,14 @@ def do(cmd, /, *, check=True, stdin=None, env_add=None, log_cmd=None):
     if env_add:
         new_env.update(env_add)
 
-    if isinstance(stdin, str):
-        stdin = stdin.encode()
+    if isinstance(input, str):
+        input = input.encode()
 
     logging.info(log_cmd or _log_cmd(cmd), extra={'context': '[CMD] '})
 
     with async_logging_ctx() as w:
         subprocess.run(cmd, shell=_is_shell_cmd(cmd), stdout=w, stderr=subprocess.STDOUT,
-                       env=new_env, check=check, input=stdin)
+                       env=new_env, check=check, input=input)
 
 
 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, check=True, env_add=None):
+def get_command_out(cmd, /, *, input=None, check=True, env_add=None):
     """get_command_out() - Like do() but returns stdout.
 
     --
@@ -119,10 +119,10 @@ def get_command_out(cmd, /, *, stdin=None, check=True, env_add=None):
     >>> get_command_out("false", check=False)
     b''
 
-    >>> get_command_out("cat -", stdin=b"ELBE", env_add={"TRUE":"true"})
+    >>> get_command_out("cat -", input=b"ELBE", env_add={"TRUE":"true"})
     b'ELBE'
 
-    >>> get_command_out("cat -", stdin="ELBE", env_add={"TRUE":"true"})
+    >>> get_command_out("cat -", input="ELBE", env_add={"TRUE":"true"})
     b'ELBE'
     """
 
@@ -131,14 +131,14 @@ def get_command_out(cmd, /, *, stdin=None, check=True, env_add=None):
     if env_add:
         new_env.update(env_add)
 
-    if isinstance(stdin, str):
-        stdin = stdin.encode()
+    if isinstance(input, str):
+        input = input.encode()
 
     logging.info(_log_cmd(cmd), extra={'context': '[CMD] '})
 
     with async_logging_ctx() as w:
         ps = subprocess.run(cmd, shell=_is_shell_cmd(cmd), stdout=subprocess.PIPE, stderr=w,
-                            env=new_env, check=check, input=stdin)
+                            env=new_env, check=check, input=input)
         return ps.stdout
 
 

-- 
2.45.0



More information about the elbe-devel mailing list