mirror of
https://github.com/parchlinux/calamares.git
synced 2025-07-03 04:15:37 -04:00
[calamares] Inject a pre-script when testing Python modules
Co-opt the subprocess module and replace call and check_call functions with something that logs the call and does nothing.
This commit is contained in:
parent
629fc83f21
commit
cc0e39db56
1 changed files with 23 additions and 0 deletions
|
@ -18,6 +18,7 @@
|
|||
#include "GlobalStorage.h"
|
||||
#include "Job.h"
|
||||
#include "JobQueue.h"
|
||||
#include "PythonJob.h"
|
||||
#include "Settings.h"
|
||||
#include "ViewManager.h"
|
||||
#include "modulesystem/Module.h"
|
||||
|
@ -365,6 +366,27 @@ createApplication( int& argc, char* argv[] )
|
|||
return new QCoreApplication( argc, argv );
|
||||
}
|
||||
|
||||
static const char pythonPreScript[] = R"(
|
||||
# This is Python code executed by Python modules *before* the
|
||||
# script file (e.g. main.py) is executed. Beware " before )
|
||||
# because it's a C++ raw-string.
|
||||
_calamares_subprocess = __import__("subprocess", globals(), locals(), [], 0)
|
||||
import sys
|
||||
import libcalamares
|
||||
class fake_subprocess(object):
|
||||
@staticmethod
|
||||
def call(*args, **kwargs):
|
||||
libcalamares.utils.debug("subprocess.call(%r,%r) X run normally" % (args, kwargs))
|
||||
return 0
|
||||
@staticmethod
|
||||
def check_call(*args, **kwargs):
|
||||
libcalamares.utils.debug("subprocess.check_call(%r,%r) X subverted to call" % (args, kwargs))
|
||||
return 0
|
||||
sys.modules["subprocess"] = fake_subprocess
|
||||
libcalamares.utils.debug('pre-script for testing purposes injected')
|
||||
|
||||
)";
|
||||
|
||||
int
|
||||
main( int argc, char* argv[] )
|
||||
{
|
||||
|
@ -397,6 +419,7 @@ main( int argc, char* argv[] )
|
|||
#ifdef WITH_QML
|
||||
CalamaresUtils::initQmlModulesDir(); // don't care if failed
|
||||
#endif
|
||||
Calamares::PythonJob::setInjectedPreScript(pythonPreScript);
|
||||
|
||||
cDebug() << "Calamares module-loader testing" << module.moduleName();
|
||||
Calamares::Module* m = load_module( module );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue