[elbe-devel] [PATCH 3/7] Call elbe with prepended python executable
Bastian Germann
bage at linutronix.de
Wed Nov 2 19:28:15 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 | 51 +++++++++++++-------------------
elbepack/pbuilderaction.py | 43 +++++++++++----------------
elbepack/tests/test_preproc.py | 3 +-
elbepack/tests/test_xml.py | 19 ++++++------
elbepack/xmlpreprocess.py | 5 +---
6 files changed, 52 insertions(+), 71 deletions(-)
diff --git a/elbepack/commands/check-build.py b/elbepack/commands/check-build.py
index e619f31396..1be00c366a 100644
--- a/elbepack/commands/check-build.py
+++ b/elbepack/commands/check-build.py
@@ -618,4 +618,4 @@ exit 1
class CheckRebuild(CheckBase):
def run(self):
- do("%s initvm submit --skip-build-source bin-cdrom.iso" % elbe_exe)
+ 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 6cc3e74d2c..66bd5343e4 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('%s initvm start' % elbe_exe)
+ 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('%s control list_projects' % elbe_exe)[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("%s repodir failed" % elbe_exe, 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(
- '%s control create_project' % (elbe_exe))
+ 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 = '%s control set_xml %s %s' % (elbe_exe, 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)
@@ -319,8 +319,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
print("Uploading CDROM. This might take a while")
try:
system(
- '%s control set_cdrom "%s" "%s"' %
- (elbe_exe, prjdir, cdrom))
+ 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)
@@ -338,8 +337,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
try:
system(
- '%s control build "%s" %s' %
- (elbe_exe, prjdir, build_opts))
+ 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)
@@ -348,7 +346,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
print("Build started, waiting till it finishes")
try:
- system('%s control wait_busy "%s"' % (elbe_exe, 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)
@@ -356,9 +354,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
file=sys.stderr)
print('The files, that have been built, can be downloaded using:',
file=sys.stderr)
- print('%s control get_files --output "%s" "%s"' % (elbe_exe,
- opt.outdir,
- prjdir),
+ print(f'{elbe_exe} control get_files --output "{opt.outdir}" "{prjdir}"',
file=sys.stderr)
print("", file=sys.stderr)
print('The project can then be removed using:',
@@ -375,8 +371,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
if opt.build_sdk:
try:
system(
- '%s control build_sdk "%s" %s' %
- (elbe_exe, prjdir, build_opts))
+ 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)
@@ -385,7 +380,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
print("SDK Build started, waiting till it finishes")
try:
- system('%s control wait_busy "%s"' % (elbe_exe, 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)
@@ -412,8 +407,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
try:
system(
- '%s control dump_file "%s" validation.txt' %
- (elbe_exe, prjdir))
+ f'{sys.executable} {elbe_exe} control dump_file "{prjdir}" validation.txt')
except CommandError:
print(
"Project failed to generate validation.txt",
@@ -421,8 +415,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
print("Getting log.txt", file=sys.stderr)
try:
system(
- '%s control dump_file "%s" log.txt' %
- (elbe_exe, prjdir))
+ f'{sys.executable} {elbe_exe} control dump_file "{prjdir}" log.txt')
except CommandError:
print("Failed to dump log.txt", file=sys.stderr)
@@ -434,7 +427,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
print("Listing available files:")
print("")
try:
- system('%s control get_files "%s"' % (elbe_exe, 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)
@@ -452,8 +445,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
ensure_outdir(opt)
try:
- system('%s control get_files --output "%s" "%s"' % (
- elbe_exe, opt.outdir, prjdir))
+ system(f'{sys.executable} {elbe_exe} control get_files --output "{opt.outdir}" "{prjdir}"')
except CommandError:
print("elbe control get_files Failed", file=sys.stderr)
print("Giving up", file=sys.stderr)
@@ -461,8 +453,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
if not opt.keep_files:
try:
- system('%s control del_project "%s"' % (
- elbe_exe, prjdir))
+ system(f'{sys.executable} {elbe_exe} control del_project "{prjdir}"')
except CommandError:
print("remove project from initvm failed",
file=sys.stderr)
@@ -600,12 +591,10 @@ class CreateAction(InitVMAction):
with PreprocessWrapper(xmlfile, opt) as ppw:
if cdrom:
- system('%s init %s --directory "%s" --cdrom "%s" "%s"' %
- (elbe_exe, init_opts, initvmdir, cdrom, ppw.preproc))
+ system(f'{sys.executable} {elbe_exe} init {init_opts} --directory "{initvmdir}" --cdrom "{cdrom}" "{ppw.preproc}"')
else:
system(
- '%s init %s --directory "%s" "%s"' %
- (elbe_exe, init_opts, initvmdir, ppw.preproc))
+ f'{sys.executable} {elbe_exe} init {init_opts} --directory "{initvmdir}" "{ppw.preproc}"')
except CommandError:
print("'elbe init' Failed", file=sys.stderr)
@@ -634,7 +623,7 @@ class CreateAction(InitVMAction):
sys.exit(20)
try:
- system('%s initvm start' % elbe_exe)
+ system(f'{sys.executable} {elbe_exe} initvm start')
except CommandError:
print("Starting the initvm Failed", file=sys.stderr)
print("Giving up", file=sys.stderr)
@@ -670,7 +659,7 @@ class SubmitAction(InitVMAction):
def execute(self, _initvmdir, opt, args):
try:
- system('%s initvm ensure' % elbe_exe)
+ 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 ea6ac583c6..dc3860d92c 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(
- '%s control create_project' % (elbe_exe))
+ f'{sys.executable} {elbe_exe} control create_project')
if ret != 0:
print("elbe control create_project failed.",
file=sys.stderr)
@@ -88,8 +88,7 @@ class CreateAction(PBuilderAction):
prjdir = prjdir.strip()
ret, _, err = command_out_stderr(
- '%s control set_xml "%s" "%s"' %
- (elbe_exe, 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)
@@ -117,15 +116,14 @@ class CreateAction(PBuilderAction):
print("Creating pbuilder")
try:
- system('%s control build_pbuilder "%s" %s %s %s' % (
- elbe_exe, 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('%s control wait_busy "%s"' % (elbe_exe, 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)
@@ -157,7 +155,7 @@ class UpdateAction(PBuilderAction):
print("Updating pbuilder")
try:
- system('%s control update_pbuilder "%s"' % (elbe_exe, 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)
@@ -190,8 +188,7 @@ class BuildAction(PBuilderAction):
if opt.xmlfile:
ret, prjdir, err = command_out_stderr(
- '%s control create_project --retries 60 "%s"' %
- (elbe_exe, 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)
@@ -201,14 +198,14 @@ class BuildAction(PBuilderAction):
prjdir = prjdir.strip()
try:
- system('%s control build_pbuilder "%s"' % (elbe_exe, 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('%s control wait_busy "%s"' % (elbe_exe, 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)
@@ -219,7 +216,7 @@ class BuildAction(PBuilderAction):
print("")
elif opt.project:
prjdir = opt.project
- system('%s control rm_log %s' % (elbe_exe, prjdir))
+ system(f'{sys.executable} {elbe_exe} control rm_log {prjdir}')
else:
print(
"you need to specify --project or --xmlfile option",
@@ -242,8 +239,7 @@ class BuildAction(PBuilderAction):
print("")
try:
system(
- '%s control set_orig "%s" "%s"' %
- (elbe_exe, prjdir, of))
+ 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)
@@ -254,16 +250,16 @@ class BuildAction(PBuilderAction):
print("")
try:
- system('%s control set_pdebuild --cpuset "%d" --profile "%s" %s '
+ system('%s %s control set_pdebuild --cpuset "%d" --profile "%s" %s '
'"%s" "%s"' %
- (elbe_exe, opt.cpuset, opt.profile, crossopt,
+ (sys.executable, elbe_exe, opt.cpuset, opt.profile, crossopt,
prjdir, tmp.fname("pdebuild.tar.gz")))
except CommandError:
print("elbe control set_pdebuild Failed", file=sys.stderr)
print("Giving up", file=sys.stderr)
sys.exit(20)
try:
- system('%s control wait_busy "%s"' % (elbe_exe, 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)
@@ -278,16 +274,14 @@ class BuildAction(PBuilderAction):
print("")
try:
system(
- '%s control --pbuilder-only get_files "%s"' %
- (elbe_exe, 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('%s control dump_file "%s" log.txt' % (
- elbe_exe, prjdir))
+ 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)
@@ -308,16 +302,15 @@ class BuildAction(PBuilderAction):
try:
system(
- '%s control --pbuilder-only get_files --output "%s" "%s"' %
- (elbe_exe, opt.outdir, prjdir))
+ '%s %s control --pbuilder-only get_files --output "%s" "%s"' %
+ (sys.executable, elbe_exe, opt.outdir, prjdir))
except CommandError:
print("elbe control get_files Failed", file=sys.stderr)
print("", file=sys.stderr)
print("dumping logfile", file=sys.stderr)
try:
- system('%s control dump_file "%s" log.txt' % (
- elbe_exe, prjdir))
+ 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 f1695b4970..9526571021 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 b7162e5e41..f2a2a5e2ea 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
@@ -27,27 +28,27 @@ class TestSimpleXML(ElbeTestCase):
uuid = None
try:
- system('%s initvm submit "%s" --output "%s" --keep-files '
+ system('%s %s initvm submit "%s" --output "%s" --keep-files '
'--build-sdk --writeproject "%s"' %
- (elbe_exe, self.param, build_dir, prj))
+ (sys.executable, elbe_exe, self.param, build_dir, prj))
# Ensure project build is done
with open(prj, "r") as f:
uuid = f.read()
- system("%s control list_projects | "
+ system("%s %s control list_projects | "
"grep %s | grep build_done || false" %
- (elbe_exe, uuid))
+ (sys.executable, elbe_exe, uuid))
for cmd in ("cdrom", "img", "sdk", "rebuild"):
with self.subTest(f'check build {cmd}'):
- system('%s check-build %s "%s"' % (elbe_exe, cmd, build_dir))
+ system(f'{sys.executable} {elbe_exe} check-build {cmd} "{build_dir}"')
# pylint: disable=try-except-raise
except:
raise
else:
# This is a tear down of the project, it's okay if it fails
- system('%s control del_project %s' % (elbe_exe, uuid),
+ system(f'{sys.executable} {elbe_exe} control del_project {uuid}',
allow_fail=True)
@unittest.skipIf(ElbeTestCase.level < ElbeTestLevel.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('%s control del_project %s' % (elbe_exe, uuid),
+ system(f'{sys.executable} {elbe_exe} control del_project {uuid}',
allow_fail=True)
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 719ab45103..843e56d3e3 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -393,10 +393,7 @@ class PreprocessWrapper:
def __enter__(self):
self.outxml = NamedTemporaryFile(prefix='elbe', suffix='xml')
- cmd = '%s preprocess %s -o %s %s' % (elbe_exe,
- self.options,
- self.outxml.name,
- self.xmlfile)
+ cmd = f'{sys.executable} {elbe_exe} preprocess {self.options} -o {self.outxml.name} {self.xmlfile}'
ret, _, err = command_out_stderr(cmd)
if ret != 0:
print("elbe preprocess failed.", file=sys.stderr)
--
2.30.2
More information about the elbe-devel
mailing list