[calamares] Allow disabling the Python pre-script

The test-application injects a script into Python code
to render harmless functions in the subprocess module
(eg to avoid Python code from running the package manager
for real). There are cases, though, where that injection
should be skipped (eg because the whole point of test-
loading some Python is to check commands that are run).

Add a -P option to the test-application to do that.
main
Adriaan de Groot 4 years ago
parent a86ffd105a
commit 5d54a08581

@ -62,6 +62,7 @@ struct ModuleConfig
QString m_language;
QString m_branding;
bool m_ui;
bool m_pythonInjection;
};
static ModuleConfig
@ -86,7 +87,6 @@ handle_args( QCoreApplication& a )
QStringLiteral( "Enable UI" ) );
QCommandLineOption slideshowOption( QStringList() << QStringLiteral( "s" ) << QStringLiteral( "slideshow" ),
QStringLiteral( "Run slideshow module" ) );
QCommandLineParser parser;
parser.setApplicationDescription( "Calamares module tester" );
parser.addHelpOption();
@ -99,6 +99,12 @@ handle_args( QCoreApplication& a )
parser.addOption( brandOption );
parser.addOption( uiOption );
parser.addOption( slideshowOption );
#ifdef WITH_PYTHON
QCommandLineOption pythonOption( QStringList() << QStringLiteral( "P" ) << QStringLiteral( "no-injected-python" ),
QStringLiteral( "Do not disable potentially-harmful Python commands" ) );
parser.addOption( pythonOption );
#endif
parser.addPositionalArgument( "module", "Path or name of module to run." );
parser.addPositionalArgument( "job.yaml", "Path of job settings document to use.", "[job.yaml]" );
@ -123,12 +129,21 @@ handle_args( QCoreApplication& a )
jobSettings = args.at( 1 );
}
bool pythonInjection = true;
#ifdef WITH_PYTHON
if ( parser.isSet( pythonOption ) )
{
pythonInjection = false;
}
#endif
return ModuleConfig { parser.isSet( slideshowOption ) ? QStringLiteral( "-" ) : args.first(),
jobSettings,
parser.value( globalOption ),
parser.value( langOption ),
parser.value( brandOption ),
parser.isSet( slideshowOption ) || parser.isSet( uiOption ) };
parser.isSet( slideshowOption ) || parser.isSet( uiOption ),
pythonInjection
};
}
}
@ -430,7 +445,10 @@ main( int argc, char* argv[] )
}
#ifdef WITH_PYTHON
Calamares::PythonJob::setInjectedPreScript(pythonPreScript);
if ( module.m_pythonInjection )
{
Calamares::PythonJob::setInjectedPreScript(pythonPreScript);
}
#endif
#ifdef WITH_QML
CalamaresUtils::initQmlModulesDir(); // don't care if failed

Loading…
Cancel
Save