[elbe-devel] [PATCH v2 3/7] Call elbe with prepended python executable

Bastian Germann bage at linutronix.de
Tue Dec 20 11:31:26 CET 2022


Calling the elbe executable relies on system support for a shebang.
Prepend each call with the python executable to enable running on Windows.

Signed-off-by: Bastian Germann <bage at linutronix.de>
---
 elbepack/commands/check-build.py |  2 +-
 elbepack/initvmaction.py         | 38 ++++++++++++++++----------------
 elbepack/pbuilderaction.py       | 34 ++++++++++++++--------------
 elbepack/tests/test_preproc.py   |  3 ++-
 elbepack/tests/test_xml.py       | 15 +++++++------
 elbepack/xmlpreprocess.py        |  2 +-
 6 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/elbepack/commands/check-build.py b/elbepack/commands/check-build.py
index 268b594e6d..e95ced262b 100644
--- a/elbepack/commands/check-build.py
+++ b/elbepack/commands/check-build.py
@@ -620,4 +620,4 @@ exit 1
 class CheckRebuild(CheckBase):
 
     def run(self):
-        do(f"{elbe_exe} initvm submit --skip-build-source bin-cdrom.iso")
+        do(f"{sys.executable} {elbe_exe} initvm submit --skip-build-source bin-cdrom.iso")
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index f0eb2a19d2..af153de8fc 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -195,11 +195,11 @@ class EnsureAction(InitVMAction):
         import libvirt
 
         if self.initvm_state() == libvirt.VIR_DOMAIN_SHUTOFF:
-            system(f'{elbe_exe} initvm start')
+            system(f'{sys.executable} {elbe_exe} initvm start')
         elif self.initvm_state() == libvirt.VIR_DOMAIN_RUNNING:
             stop = time.time() + 300
             while time.time() < stop:
-                if command_out(f'{elbe_exe} control list_projects')[0] == 0:
+                if command_out(f'{sys.executable} {elbe_exe} control list_projects')[0] == 0:
                     break
                 time.sleep(10)
             if time.time() > stop:
@@ -273,7 +273,7 @@ def submit_with_repodir_and_dl_result(xmlfile, cdrom, opt):
             with Repodir(xmlfile, preprocess_xmlfile):
                 submit_and_dl_result(preprocess_xmlfile, cdrom, opt)
     except RepodirError as err:
-        print(f"{elbe_exe} repodir failed", file=sys.stderr)
+        print("elbe repodir failed", file=sys.stderr)
         print(err, file=sys.stderr)
         sys.exit(20)
 
@@ -288,7 +288,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
             xmlfile = ppw.preproc
 
             ret, prjdir, err = command_out_stderr(
-                f'{elbe_exe} control create_project')
+                f'{sys.executable} {elbe_exe} control create_project')
             if ret != 0:
                 print("elbe control create_project failed.", file=sys.stderr)
                 print(err, file=sys.stderr)
@@ -297,7 +297,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
 
             prjdir = prjdir.strip()
 
-            cmd = f'{elbe_exe} control set_xml {prjdir} {xmlfile}'
+            cmd = f'{sys.executable} {elbe_exe} control set_xml {prjdir} {xmlfile}'
             ret, _, err = command_out_stderr(cmd)
             if ret != 0:
                 print("elbe control set_xml failed2", file=sys.stderr)
@@ -318,7 +318,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
     if cdrom is not None:
         print("Uploading CDROM. This might take a while")
         try:
-            system(f'{elbe_exe} control set_cdrom "{prjdir}" "{cdrom}"')
+            system(f'{sys.executable} {elbe_exe} control set_cdrom "{prjdir}" "{cdrom}"')
         except CommandError:
             print("elbe control set_cdrom Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -335,7 +335,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
         build_opts += '--skip-pbuilder '
 
     try:
-        system(f'{elbe_exe} control build "{prjdir}" {build_opts}')
+        system(f'{sys.executable} {elbe_exe} control build "{prjdir}" {build_opts}')
     except CommandError:
         print("elbe control build Failed", file=sys.stderr)
         print("Giving up", file=sys.stderr)
@@ -344,7 +344,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
     print("Build started, waiting till it finishes")
 
     try:
-        system(f'{elbe_exe} control wait_busy "{prjdir}"')
+        system(f'{sys.executable} {elbe_exe} control wait_busy "{prjdir}"')
     except CommandError:
         print('elbe control wait_busy Failed', file=sys.stderr)
         print('', file=sys.stderr)
@@ -369,7 +369,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
 
     if opt.build_sdk:
         try:
-            system(f'{elbe_exe} control build_sdk "{prjdir}" {build_opts}')
+            system(f'{sys.executable} {elbe_exe} control build_sdk "{prjdir}" {build_opts}')
         except CommandError:
             print("elbe control build_sdk Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -378,7 +378,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
         print("SDK Build started, waiting till it finishes")
 
         try:
-            system(f'{elbe_exe} control wait_busy "{prjdir}"')
+            system(f'{sys.executable} {elbe_exe} control wait_busy "{prjdir}"')
         except CommandError:
             print('elbe control wait_busy Failed, while waiting for the SDK',
                   file=sys.stderr)
@@ -404,14 +404,14 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
         print("")
 
     try:
-        system(f'{elbe_exe} control dump_file "{prjdir}" validation.txt')
+        system(f'{sys.executable} {elbe_exe} control dump_file "{prjdir}" validation.txt')
     except CommandError:
         print(
             "Project failed to generate validation.txt",
             file=sys.stderr)
         print("Getting log.txt", file=sys.stderr)
         try:
-            system(f'{elbe_exe} control dump_file "{prjdir}" log.txt')
+            system(f'{sys.executable} {elbe_exe} control dump_file "{prjdir}" log.txt')
         except CommandError:
 
             print("Failed to dump log.txt", file=sys.stderr)
@@ -423,7 +423,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
         print("Listing available files:")
         print("")
         try:
-            system(f'{elbe_exe} control get_files "{prjdir}"')
+            system(f'{sys.executable} {elbe_exe} control get_files "{prjdir}"')
         except CommandError:
             print("elbe control get_files Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -440,7 +440,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
 
         try:
             system(
-                f'{elbe_exe} control get_files --output "{opt.outdir}" '
+                f'{sys.executable} {elbe_exe} control get_files --output "{opt.outdir}" '
                 f'"{prjdir}"')
         except CommandError:
             print("elbe control get_files Failed", file=sys.stderr)
@@ -449,7 +449,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
 
         if not opt.keep_files:
             try:
-                system(f'{elbe_exe} control del_project "{prjdir}"')
+                system(f'{sys.executable} {elbe_exe} control del_project "{prjdir}"')
             except CommandError:
                 print("remove project from initvm failed",
                       file=sys.stderr)
@@ -585,12 +585,12 @@ class CreateAction(InitVMAction):
             with PreprocessWrapper(xmlfile, opt) as ppw:
                 if cdrom:
                     system(
-                        f'{elbe_exe} init {init_opts} '
+                        f'{sys.executable} {elbe_exe} init {init_opts} '
                         f'--directory "{initvmdir}" --cdrom "{cdrom}" '
                         f'"{ppw.preproc}"')
                 else:
                     system(
-                        f'{elbe_exe} init {init_opts} '
+                        f'{sys.executable} {elbe_exe} init {init_opts} '
                         f'--directory "{initvmdir}" "{ppw.preproc}"')
 
         except CommandError:
@@ -620,7 +620,7 @@ class CreateAction(InitVMAction):
             sys.exit(20)
 
         try:
-            system(f'{elbe_exe} initvm start')
+            system(f'{sys.executable} {elbe_exe} initvm start')
         except CommandError:
             print("Starting the initvm Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -656,7 +656,7 @@ class SubmitAction(InitVMAction):
 
     def execute(self, _initvmdir, opt, args):
         try:
-            system(f'{elbe_exe} initvm ensure')
+            system(f'{sys.executable} {elbe_exe} initvm ensure')
         except CommandError:
             print("Starting the initvm Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
diff --git a/elbepack/pbuilderaction.py b/elbepack/pbuilderaction.py
index 2eccd115c7..5cfa89c187 100644
--- a/elbepack/pbuilderaction.py
+++ b/elbepack/pbuilderaction.py
@@ -78,7 +78,7 @@ class CreateAction(PBuilderAction):
             try:
                 with PreprocessWrapper(opt.xmlfile, opt) as ppw:
                     ret, prjdir, err = command_out_stderr(
-                        f"{elbe_exe} control create_project")
+                        f'{sys.executable} {elbe_exe} control create_project')
                     if ret != 0:
                         print("elbe control create_project failed.",
                               file=sys.stderr)
@@ -88,7 +88,7 @@ class CreateAction(PBuilderAction):
 
                     prjdir = prjdir.strip()
                     ret, _, err = command_out_stderr(
-                        f'{elbe_exe} control set_xml "{prjdir}" "{ppw.preproc}"')
+                        f'{sys.executable} {elbe_exe} control set_xml "{prjdir}" "{ppw.preproc}"')
 
                     if ret != 0:
                         print("elbe control set_xml failed.", file=sys.stderr)
@@ -116,15 +116,14 @@ class CreateAction(PBuilderAction):
         print("Creating pbuilder")
 
         try:
-            system(
-                f'{elbe_exe} control build_pbuilder "{prjdir}" {crossopt} {ccacheopt} {ccachesize}')
+            system(f'{sys.executable} {elbe_exe} control build_pbuilder "{prjdir}" {crossopt} {ccacheopt} {ccachesize}')
         except CommandError:
             print("elbe control build_pbuilder Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
             sys.exit(20)
 
         try:
-            system(f'{elbe_exe} control wait_busy "{prjdir}"')
+            system(f'{sys.executable} {elbe_exe} control wait_busy "{prjdir}"')
         except CommandError:
             print("elbe control wait_busy Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -156,7 +155,7 @@ class UpdateAction(PBuilderAction):
         print("Updating pbuilder")
 
         try:
-            system(f'{elbe_exe} control update_pbuilder "{prjdir}"')
+            system(f'{sys.executable} {elbe_exe} control update_pbuilder "{prjdir}"')
         except CommandError:
             print("elbe control update_pbuilder Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -189,7 +188,7 @@ class BuildAction(PBuilderAction):
 
         if opt.xmlfile:
             ret, prjdir, err = command_out_stderr(
-                f'{elbe_exe} control create_project --retries 60 "{opt.xmlfile}"')
+                f'{sys.executable} {elbe_exe} control create_project --retries 60 "{opt.xmlfile}"')
             if ret != 0:
                 print("elbe control create_project failed.", file=sys.stderr)
                 print(err, file=sys.stderr)
@@ -199,14 +198,14 @@ class BuildAction(PBuilderAction):
             prjdir = prjdir.strip()
 
             try:
-                system(f'{elbe_exe} control build_pbuilder "{prjdir}"')
+                system(f'{sys.executable} {elbe_exe} control build_pbuilder "{prjdir}"')
             except CommandError:
                 print("elbe control build_pbuilder Failed", file=sys.stderr)
                 print("Giving up", file=sys.stderr)
                 sys.exit(20)
 
             try:
-                system(f'{elbe_exe} control wait_busy "{prjdir}"')
+                system(f'{sys.executable} {elbe_exe} control wait_busy "{prjdir}"')
             except CommandError:
                 print("elbe control wait_busy Failed", file=sys.stderr)
                 print("Giving up", file=sys.stderr)
@@ -217,7 +216,7 @@ class BuildAction(PBuilderAction):
             print("")
         elif opt.project:
             prjdir = opt.project
-            system(f'{elbe_exe} control rm_log {prjdir}')
+            system(f'{sys.executable} {elbe_exe} control rm_log {prjdir}')
         else:
             print(
                 "you need to specify --project or --xmlfile option",
@@ -239,7 +238,8 @@ class BuildAction(PBuilderAction):
             print(f"Pushing orig file '{of}' into pbuilder")
             print("")
             try:
-                system(f'{elbe_exe} control set_orig "{prjdir}" "{of}"')
+                system(
+                    f'{sys.executable} {elbe_exe} control set_orig "{prjdir}" "{of}"')
             except CommandError:
                 print("elbe control set_orig Failed", file=sys.stderr)
                 print("Giving up", file=sys.stderr)
@@ -251,7 +251,7 @@ class BuildAction(PBuilderAction):
 
         try:
             system(
-                f'{elbe_exe} control set_pdebuild --cpuset "{opt.cpuset}" '
+                f'{sys.executable} {elbe_exe} control set_pdebuild --cpuset "{opt.cpuset}" '
                 f'--profile "{opt.profile}" {crossopt} '
                 f'"{prjdir}" "{tmp.fname("pdebuild.tar.gz")}"')
         except CommandError:
@@ -259,7 +259,7 @@ class BuildAction(PBuilderAction):
             print("Giving up", file=sys.stderr)
             sys.exit(20)
         try:
-            system(f'{elbe_exe} control wait_busy "{prjdir}"')
+            system(f'{sys.executable} {elbe_exe} control wait_busy "{prjdir}"')
         except CommandError:
             print("elbe control wait_busy Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -274,14 +274,14 @@ class BuildAction(PBuilderAction):
             print("")
             try:
                 system(
-                    f'{elbe_exe} control --pbuilder-only get_files "{prjdir}"')
+                    f'{sys.executable} {elbe_exe} control --pbuilder-only get_files "{prjdir}"')
             except CommandError:
                 print("elbe control get_files Failed", file=sys.stderr)
                 print("", file=sys.stderr)
                 print("dumping logfile", file=sys.stderr)
 
                 try:
-                    system(f'{elbe_exe} control dump_file "{prjdir}" log.txt')
+                    system(f'{sys.executable} {elbe_exe} control dump_file "{prjdir}" log.txt')
                 except CommandError:
                     print("elbe control dump_file Failed", file=sys.stderr)
                     print("", file=sys.stderr)
@@ -300,7 +300,7 @@ class BuildAction(PBuilderAction):
 
             try:
                 system(
-                    f'{elbe_exe} control --pbuilder-only get_files '
+                    f'{sys.executable} {elbe_exe} control --pbuilder-only get_files '
                     f'--output "{opt.outdir}" "{prjdir}"')
             except CommandError:
                 print("elbe control get_files Failed", file=sys.stderr)
@@ -308,7 +308,7 @@ class BuildAction(PBuilderAction):
                 print("dumping logfile", file=sys.stderr)
 
                 try:
-                    system(f'{elbe_exe} control dump_file "{prjdir}" log.txt')
+                    system(f'{sys.executable} {elbe_exe} control dump_file "{prjdir}" log.txt')
                 except CommandError:
                     print("elbe control dump_file Failed", file=sys.stderr)
                     print("", file=sys.stderr)
diff --git a/elbepack/tests/test_preproc.py b/elbepack/tests/test_preproc.py
index 6840001229..87ed1dd4ad 100644
--- a/elbepack/tests/test_preproc.py
+++ b/elbepack/tests/test_preproc.py
@@ -5,6 +5,7 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 
 import os
+import sys
 
 from elbepack.commands.test import ElbeTestCase, system, ElbeTestException
 from elbepack.directories import elbe_exe, elbe_dir
@@ -25,7 +26,7 @@ class TestPreproc(ElbeTestCase):
     def test_preproc(self):
 
         try:
-            system(f'{elbe_exe} preprocess "{self.param}"')
+            system(f'{sys.executable} {elbe_exe} preprocess "{self.param}"')
         except ElbeTestException as e:
             if self.param in TestPreproc.failure_set:
                 self.stdout = e.out
diff --git a/elbepack/tests/test_xml.py b/elbepack/tests/test_xml.py
index 774534fecc..7efd62da99 100644
--- a/elbepack/tests/test_xml.py
+++ b/elbepack/tests/test_xml.py
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 
 import os
+import sys
 import unittest
 import tempfile
 
@@ -28,19 +29,19 @@ class TestSimpleXML(ElbeTestCase):
 
             try:
                 system(
-                    f'{elbe_exe} initvm submit "{self.param}" '
+                    f'{sys.executable} {elbe_exe} initvm submit "{self.param}" '
                     f'--output "{build_dir}" --keep-files '
                     f'--build-sdk --writeproject "{prj}"')
 
                 # Ensure project build is done
                 with open(prj, "r") as f:
                     uuid = f.read()
-                    system(f"{elbe_exe} control list_projects | "
+                    system(f"{sys.executable} {elbe_exe} control list_projects | "
                            f"grep {uuid} | grep build_done || false")
 
                 for cmd in ("cdrom", "img", "sdk", "rebuild"):
                     with self.subTest(f'check build {cmd}'):
-                        system(f'{elbe_exe} check-build {cmd} "{build_dir}"')
+                        system(f'{sys.executable} {elbe_exe} check-build {cmd} "{build_dir}"')
 
             # pylint: disable=try-except-raise
             except:
@@ -48,7 +49,7 @@ class TestSimpleXML(ElbeTestCase):
             else:
                 # This is a tear down of the project, it's okay if it fails
                 system(
-                    f'{elbe_exe} control del_project {uuid}', allow_fail=True)
+                    f'{sys.executable} {elbe_exe} control del_project {uuid}', allow_fail=True)
 
 @unittest.skipIf(ElbeTestCase.level < ElbeTestLevel.INITVM,
                  "Test level not set to INITVM")
@@ -67,7 +68,7 @@ class TestPbuilder(ElbeTestCase):
             uuid = None
 
             try:
-                system(f'{elbe_exe} pbuilder create --xmlfile "{self.param}" \
+                system(f'{sys.executable} {elbe_exe} pbuilder create --xmlfile "{self.param}" \
                                                     --writeproject "{prj}"')
                 system(f'cd "{build_dir}"; \
                          git clone https://github.com/Linutronix/libgpio.git')
@@ -75,11 +76,11 @@ class TestPbuilder(ElbeTestCase):
                 with open(prj, "r") as f:
                     uuid = f.read()
                     system(f'cd "{build_dir}/libgpio"; \
-                             {elbe_exe} pbuilder build --project {uuid}')
+                             {sys.executable} {elbe_exe} pbuilder build --project {uuid}')
             # pylint: disable=try-except-raise
             except:
                 raise
             else:
                 # This is a tearDown of the project, it's okay if it fails
                 system(
-                    f'{elbe_exe} control del_project {uuid}', allow_fail=True)
+                    f'{sys.executable} {elbe_exe} control del_project {uuid}', allow_fail=True)
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 680e7a361a..86a913b309 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -392,7 +392,7 @@ class PreprocessWrapper:
     def __enter__(self):
         self.outxml = NamedTemporaryFile(prefix='elbe', suffix='xml')
 
-        cmd = (f'{elbe_exe} preprocess {self.options} '
+        cmd = (f'{sys.executable} {elbe_exe} preprocess {self.options} '
                f'-o {self.outxml.name} {self.xmlfile}')
         ret, _, err = command_out_stderr(cmd)
         if ret != 0:
-- 
2.30.2



More information about the elbe-devel mailing list