From ec5a4cb4235c4cd06192bd4a1dbefe6a5ea965a9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Sep 2023 19:28:03 +0200 Subject: [PATCH] Python: support injected pre-script (for testing) --- src/libcalamares/python/PythonJob.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libcalamares/python/PythonJob.cpp b/src/libcalamares/python/PythonJob.cpp index 169a46ea4..49a4ad941 100644 --- a/src/libcalamares/python/PythonJob.cpp +++ b/src/libcalamares/python/PythonJob.cpp @@ -24,6 +24,8 @@ namespace py = pybind11; namespace { +static const char* s_preScript = nullptr; + QString asQString( const py::object& o ) { @@ -152,6 +154,10 @@ Job::exec() py::scoped_interpreter guard {}; auto scope = py::module_::import( "__main__" ).attr( "__dict__" ); + if ( s_preScript ) + { + py::exec( s_preScript ); + } py::eval_file( scriptFI.absoluteFilePath().toUtf8().constData(), scope ); m_d->description = getPrettyNameFromScope( scope ); @@ -226,6 +232,9 @@ Job::exec() void Job::setInjectedPreScript( const char* script ) { + s_preScript = script; + cDebug() << "Python pre-script set to string" << Logger::Pointer( script ) << "length" + << ( script ? strlen( script ) : 0 ); } } // namespace Python