2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-08-12 16:03:25 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014-2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2018-2020 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2020-08-25 16:05:56 +02:00
|
|
|
*
|
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
2014-07-16 16:07:32 +02:00
|
|
|
*/
|
|
|
|
#include "PythonJob.h"
|
|
|
|
|
2020-02-12 10:48:19 +01:00
|
|
|
#include "CalamaresVersion.h"
|
2014-07-21 17:08:06 +02:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2019-08-04 22:24:55 +02:00
|
|
|
#include "PythonHelper.h"
|
2020-02-12 11:02:38 +01:00
|
|
|
#include "PythonJobApi.h"
|
|
|
|
#include "utils/BoostPython.h"
|
2019-08-04 22:24:55 +02:00
|
|
|
#include "utils/Logger.h"
|
2014-07-16 16:07:32 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
2021-06-15 21:50:59 +02:00
|
|
|
static const char* s_preScript = nullptr;
|
|
|
|
|
2014-07-16 16:07:32 +02:00
|
|
|
namespace bp = boost::python;
|
2014-07-17 17:52:02 +02:00
|
|
|
|
2021-12-07 14:48:14 +01:00
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
|
|
|
|
#endif
|
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( mount_overloads, CalamaresPython::mount, 2, 4 );
|
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_str_overloads, CalamaresPython::target_env_call, 1, 3 );
|
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_list_overloads, CalamaresPython::target_env_call, 1, 3 );
|
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_str_overloads, CalamaresPython::check_target_env_call, 1, 3 );
|
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_list_overloads, CalamaresPython::check_target_env_call, 1, 3 );
|
2015-08-06 11:57:01 +02:00
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_str_overloads,
|
|
|
|
CalamaresPython::check_target_env_output,
|
2019-08-04 22:24:55 +02:00
|
|
|
1,
|
|
|
|
3 );
|
2015-08-06 11:57:01 +02:00
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_list_overloads,
|
|
|
|
CalamaresPython::check_target_env_output,
|
2019-08-04 22:24:55 +02:00
|
|
|
1,
|
|
|
|
3 );
|
2021-11-03 13:45:15 +01:00
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_process_output_overloads,
|
|
|
|
CalamaresPython::target_env_process_output,
|
|
|
|
1,
|
|
|
|
4 );
|
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS( host_env_process_output_overloads, CalamaresPython::host_env_process_output, 1, 4 );
|
2021-07-27 16:13:49 +02:00
|
|
|
|
2021-12-07 14:48:14 +01:00
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2014-07-17 17:52:02 +02:00
|
|
|
BOOST_PYTHON_MODULE( libcalamares )
|
|
|
|
{
|
2014-08-04 17:04:36 +02:00
|
|
|
bp::object package = bp::scope();
|
|
|
|
package.attr( "__path__" ) = "libcalamares";
|
|
|
|
|
2014-07-29 13:16:46 +02:00
|
|
|
bp::scope().attr( "ORGANIZATION_NAME" ) = CALAMARES_ORGANIZATION_NAME;
|
|
|
|
bp::scope().attr( "ORGANIZATION_DOMAIN" ) = CALAMARES_ORGANIZATION_DOMAIN;
|
|
|
|
bp::scope().attr( "APPLICATION_NAME" ) = CALAMARES_APPLICATION_NAME;
|
|
|
|
bp::scope().attr( "VERSION" ) = CALAMARES_VERSION;
|
|
|
|
bp::scope().attr( "VERSION_SHORT" ) = CALAMARES_VERSION_SHORT;
|
2014-07-17 17:52:02 +02:00
|
|
|
|
2014-07-23 13:02:42 +02:00
|
|
|
bp::class_< CalamaresPython::PythonJobInterface >( "Job", bp::init< Calamares::PythonJob* >() )
|
2019-08-04 22:24:55 +02:00
|
|
|
.def_readonly( "module_name", &CalamaresPython::PythonJobInterface::moduleName )
|
|
|
|
.def_readonly( "pretty_name", &CalamaresPython::PythonJobInterface::prettyName )
|
|
|
|
.def_readonly( "working_path", &CalamaresPython::PythonJobInterface::workingPath )
|
2014-07-22 18:05:58 +02:00
|
|
|
.def_readonly( "configuration", &CalamaresPython::PythonJobInterface::configuration )
|
2019-08-04 22:24:55 +02:00
|
|
|
.def( "setprogress",
|
|
|
|
&CalamaresPython::PythonJobInterface::setprogress,
|
|
|
|
bp::args( "progress" ),
|
|
|
|
"Reports the progress status of this job to Calamares, "
|
2021-11-03 11:53:44 +01:00
|
|
|
"as a real number between 0 and 1." );
|
2019-08-04 22:24:55 +02:00
|
|
|
|
|
|
|
bp::class_< CalamaresPython::GlobalStoragePythonWrapper >( "GlobalStorage",
|
|
|
|
bp::init< Calamares::GlobalStorage* >() )
|
|
|
|
.def( "contains", &CalamaresPython::GlobalStoragePythonWrapper::contains )
|
|
|
|
.def( "count", &CalamaresPython::GlobalStoragePythonWrapper::count )
|
|
|
|
.def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert )
|
|
|
|
.def( "keys", &CalamaresPython::GlobalStoragePythonWrapper::keys )
|
|
|
|
.def( "remove", &CalamaresPython::GlobalStoragePythonWrapper::remove )
|
|
|
|
.def( "value", &CalamaresPython::GlobalStoragePythonWrapper::value );
|
2014-07-29 20:18:02 +02:00
|
|
|
|
|
|
|
// libcalamares.utils submodule starts here
|
2014-08-04 17:06:16 +02:00
|
|
|
bp::object utilsModule( bp::handle<>( bp::borrowed( PyImport_AddModule( "libcalamares.utils" ) ) ) );
|
|
|
|
bp::scope().attr( "utils" ) = utilsModule;
|
|
|
|
bp::scope utilsScope = utilsModule;
|
2019-04-17 11:57:46 +02:00
|
|
|
Q_UNUSED( utilsScope )
|
2014-07-29 20:18:02 +02:00
|
|
|
|
2021-11-29 12:46:12 +01:00
|
|
|
// .. Logging functions
|
2014-08-05 13:23:04 +02:00
|
|
|
bp::def(
|
2019-08-04 22:24:55 +02:00
|
|
|
"debug", &CalamaresPython::debug, bp::args( "s" ), "Writes the given string to the Calamares debug stream." );
|
|
|
|
bp::def( "warning",
|
|
|
|
&CalamaresPython::warning,
|
|
|
|
bp::args( "s" ),
|
|
|
|
"Writes the given string to the Calamares warning stream." );
|
2021-11-29 12:26:07 +01:00
|
|
|
bp::def( "warn",
|
|
|
|
&CalamaresPython::warning,
|
|
|
|
bp::args( "s" ),
|
|
|
|
"Writes the given string to the Calamares warning stream." );
|
|
|
|
bp::def(
|
2022-01-17 13:47:47 +01:00
|
|
|
"error", &CalamaresPython::error, bp::args( "s" ), "Writes the given string to the Calamares error stream." );
|
2019-08-04 22:24:55 +02:00
|
|
|
|
2021-11-29 12:46:12 +01:00
|
|
|
|
|
|
|
// .. YAML functions
|
|
|
|
bp::def( "load_yaml", &CalamaresPython::load_yaml, bp::args( "path" ), "Loads YAML from a file." );
|
|
|
|
|
|
|
|
// .. Filesystem functions
|
2019-08-04 22:24:55 +02:00
|
|
|
bp::def( "mount",
|
|
|
|
&CalamaresPython::mount,
|
|
|
|
mount_overloads( bp::args( "device_path", "mount_point", "filesystem_name", "options" ),
|
|
|
|
"Runs the mount utility with the specified parameters.\n"
|
|
|
|
"Returns the program's exit code, or:\n"
|
|
|
|
"-1 = QProcess crash\n"
|
|
|
|
"-2 = QProcess cannot start\n"
|
|
|
|
"-3 = bad arguments" ) );
|
2021-11-29 12:46:12 +01:00
|
|
|
|
|
|
|
// .. Process functions
|
2014-08-04 16:03:33 +02:00
|
|
|
bp::def(
|
2015-08-06 11:57:01 +02:00
|
|
|
"target_env_call",
|
2019-08-04 22:24:55 +02:00
|
|
|
static_cast< int ( * )( const std::string&, const std::string&, int ) >( &CalamaresPython::target_env_call ),
|
|
|
|
target_env_call_str_overloads( bp::args( "command", "stdin", "timeout" ),
|
|
|
|
"Runs the specified command in the chroot of the target system.\n"
|
|
|
|
"Returns the program's exit code, or:\n"
|
|
|
|
"-1 = QProcess crash\n"
|
|
|
|
"-2 = QProcess cannot start\n"
|
|
|
|
"-3 = bad arguments\n"
|
|
|
|
"-4 = QProcess timeout" ) );
|
|
|
|
bp::def( "target_env_call",
|
|
|
|
static_cast< int ( * )( const bp::list&, const std::string&, int ) >( &CalamaresPython::target_env_call ),
|
|
|
|
target_env_call_list_overloads( bp::args( "args", "stdin", "timeout" ),
|
|
|
|
"Runs the specified command in the chroot of the target system.\n"
|
|
|
|
"Returns the program's exit code, or:\n"
|
|
|
|
"-1 = QProcess crash\n"
|
|
|
|
"-2 = QProcess cannot start\n"
|
|
|
|
"-3 = bad arguments\n"
|
|
|
|
"-4 = QProcess timeout" ) );
|
|
|
|
|
|
|
|
bp::def( "check_target_env_call",
|
|
|
|
static_cast< int ( * )( const std::string&, const std::string&, int ) >(
|
|
|
|
&CalamaresPython::check_target_env_call ),
|
|
|
|
check_target_env_call_str_overloads( bp::args( "command", "stdin", "timeout" ),
|
|
|
|
"Runs the specified command in the chroot of the target system.\n"
|
|
|
|
"Returns 0, which is program's exit code if the program exited "
|
|
|
|
"successfully, or raises a subprocess.CalledProcessError." ) );
|
2014-08-04 16:03:33 +02:00
|
|
|
bp::def(
|
2015-08-06 11:57:01 +02:00
|
|
|
"check_target_env_call",
|
2019-08-04 22:24:55 +02:00
|
|
|
static_cast< int ( * )( const bp::list&, const std::string&, int ) >( &CalamaresPython::check_target_env_call ),
|
|
|
|
check_target_env_call_list_overloads( bp::args( "args", "stdin", "timeout" ),
|
|
|
|
"Runs the specified command in the chroot of the target system.\n"
|
|
|
|
"Returns 0, which is program's exit code if the program exited "
|
|
|
|
"successfully, or raises a subprocess.CalledProcessError." ) );
|
|
|
|
|
|
|
|
bp::def( "check_target_env_output",
|
|
|
|
static_cast< std::string ( * )( const std::string&, const std::string&, int ) >(
|
|
|
|
&CalamaresPython::check_target_env_output ),
|
|
|
|
check_target_env_output_str_overloads( bp::args( "command", "stdin", "timeout" ),
|
|
|
|
"Runs the specified command in the chroot of the target system.\n"
|
|
|
|
"Returns the program's standard output, and raises a "
|
|
|
|
"subprocess.CalledProcessError if something went wrong." ) );
|
|
|
|
bp::def( "check_target_env_output",
|
|
|
|
static_cast< std::string ( * )( const bp::list&, const std::string&, int ) >(
|
|
|
|
&CalamaresPython::check_target_env_output ),
|
|
|
|
check_target_env_output_list_overloads( bp::args( "args", "stdin", "timeout" ),
|
|
|
|
"Runs the specified command in the chroot of the target system.\n"
|
|
|
|
"Returns the program's standard output, and raises a "
|
|
|
|
"subprocess.CalledProcessError if something went wrong." ) );
|
2021-11-03 11:53:44 +01:00
|
|
|
bp::def( "target_env_process_output",
|
2021-11-03 12:23:39 +01:00
|
|
|
&CalamaresPython::target_env_process_output,
|
2021-11-03 13:45:15 +01:00
|
|
|
target_env_process_output_overloads( bp::args( "command", "callback", "stdin", "timeout" ),
|
|
|
|
"Runs the specified @p command in the target system." ) );
|
2021-11-03 12:23:39 +01:00
|
|
|
bp::def( "host_env_process_output",
|
|
|
|
&CalamaresPython::host_env_process_output,
|
2021-11-03 13:45:15 +01:00
|
|
|
host_env_process_output_overloads( bp::args( "command", "callback", "stdin", "timeout" ),
|
|
|
|
"Runs the specified command in the host system." ) );
|
2021-11-03 11:53:44 +01:00
|
|
|
|
2021-11-29 12:46:12 +01:00
|
|
|
// .. String functions
|
2019-08-04 22:24:55 +02:00
|
|
|
bp::def( "obscure",
|
|
|
|
&CalamaresPython::obscure,
|
|
|
|
bp::args( "s" ),
|
|
|
|
"Simple string obfuscation function based on KStringHandler::obscure.\n"
|
|
|
|
"Returns a string, generated using a simple symmetric encryption.\n"
|
|
|
|
"Applying the function to a string obscured by this function will result "
|
|
|
|
"in the original string." );
|
|
|
|
|
2021-11-29 12:46:12 +01:00
|
|
|
// .. Translation functions
|
2019-08-04 22:24:55 +02:00
|
|
|
bp::def( "gettext_languages",
|
|
|
|
&CalamaresPython::gettext_languages,
|
|
|
|
"Returns list of languages (most to least-specific) for gettext." );
|
|
|
|
|
|
|
|
bp::def( "gettext_path", &CalamaresPython::gettext_path, "Returns path for gettext search." );
|
2014-07-17 17:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
namespace Calamares
|
|
|
|
{
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2020-03-09 16:32:41 +01:00
|
|
|
struct PythonJob::Private
|
|
|
|
{
|
|
|
|
bp::object m_prettyStatusMessage;
|
|
|
|
};
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2020-09-22 21:54:10 +02:00
|
|
|
PythonJob::PythonJob( const QString& scriptFile,
|
2014-07-16 16:07:32 +02:00
|
|
|
const QString& workingPath,
|
2014-07-18 14:27:59 +02:00
|
|
|
const QVariantMap& moduleConfiguration,
|
2014-07-16 16:07:32 +02:00
|
|
|
QObject* parent )
|
|
|
|
: Job( parent )
|
2020-03-09 16:32:41 +01:00
|
|
|
, m_d( std::make_unique< Private >() )
|
2014-07-16 16:07:32 +02:00
|
|
|
, m_scriptFile( scriptFile )
|
|
|
|
, m_workingPath( workingPath )
|
2017-07-05 12:28:32 +02:00
|
|
|
, m_description()
|
2014-07-18 14:27:59 +02:00
|
|
|
, m_configurationMap( moduleConfiguration )
|
2014-07-16 16:07:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
PythonJob::~PythonJob() {}
|
2014-07-16 16:07:32 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
PythonJob::prettyName() const
|
|
|
|
{
|
2015-06-13 01:16:11 +02:00
|
|
|
return QDir( m_workingPath ).dirName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
2015-06-13 02:23:11 +02:00
|
|
|
PythonJob::prettyStatusMessage() const
|
2015-06-13 01:16:11 +02:00
|
|
|
{
|
2020-03-09 21:39:35 +01:00
|
|
|
// The description is updated when progress is reported, see emitProgress()
|
2017-07-05 12:44:09 +02:00
|
|
|
if ( m_description.isEmpty() )
|
2019-08-04 23:00:03 +02:00
|
|
|
{
|
2023-10-15 13:39:17 +02:00
|
|
|
return tr( "Running %1 operation…", "@status" ).arg( QDir( m_workingPath ).dirName() );
|
2019-08-04 23:00:03 +02:00
|
|
|
}
|
2017-07-05 12:44:09 +02:00
|
|
|
else
|
2019-08-04 22:24:55 +02:00
|
|
|
{
|
2017-07-05 12:44:09 +02:00
|
|
|
return m_description;
|
2019-08-04 22:24:55 +02:00
|
|
|
}
|
2014-07-16 16:07:32 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 21:01:07 +01:00
|
|
|
static QString
|
|
|
|
pythonStringMethod( bp::dict& script, const char* funcName )
|
|
|
|
{
|
|
|
|
bp::object func = script.get( funcName, bp::object() );
|
|
|
|
if ( !func.is_none() )
|
|
|
|
{
|
|
|
|
bp::extract< std::string > result( func() );
|
|
|
|
return result.check() ? QString::fromStdString( result() ).trimmed() : QString();
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2014-07-16 16:07:32 +02:00
|
|
|
|
|
|
|
JobResult
|
|
|
|
PythonJob::exec()
|
|
|
|
{
|
|
|
|
// We assume m_scriptFile to be relative to m_workingPath.
|
|
|
|
QDir workingDir( m_workingPath );
|
2019-08-04 22:24:55 +02:00
|
|
|
if ( !workingDir.exists() || !workingDir.isReadable() )
|
2014-07-16 16:07:32 +02:00
|
|
|
{
|
2023-11-07 23:43:09 +01:00
|
|
|
return JobResult::error( tr( "Bad working directory path", "@error" ),
|
|
|
|
tr( "Working directory %1 for python job %2 is not readable.", "@error" )
|
|
|
|
.arg( m_workingPath )
|
|
|
|
.arg( prettyName() ) );
|
2014-07-16 16:07:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo scriptFI( workingDir.absoluteFilePath( m_scriptFile ) );
|
2019-08-04 22:24:55 +02:00
|
|
|
if ( !scriptFI.exists() || !scriptFI.isFile() || !scriptFI.isReadable() )
|
2014-07-16 16:07:32 +02:00
|
|
|
{
|
2023-10-15 13:39:17 +02:00
|
|
|
return JobResult::error( tr( "Bad main script file", "@error" ),
|
|
|
|
tr( "Main script file %1 for python job %2 is not readable.", "@error" )
|
2019-08-04 22:24:55 +02:00
|
|
|
.arg( scriptFI.absoluteFilePath() )
|
|
|
|
.arg( prettyName() ) );
|
2014-07-16 16:07:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-03-09 16:05:01 +01:00
|
|
|
bp::dict scriptNamespace = CalamaresPython::Helper::instance()->createCleanNamespace();
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2014-07-17 17:52:02 +02:00
|
|
|
bp::object calamaresModule = bp::import( "libcalamares" );
|
|
|
|
bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) );
|
|
|
|
|
2014-07-18 11:59:12 +02:00
|
|
|
calamaresNamespace[ "job" ] = CalamaresPython::PythonJobInterface( this );
|
2019-08-04 22:24:55 +02:00
|
|
|
calamaresNamespace[ "globalstorage" ]
|
|
|
|
= CalamaresPython::GlobalStoragePythonWrapper( JobQueue::instance()->globalStorage() );
|
2014-07-17 17:52:02 +02:00
|
|
|
|
2021-06-15 21:50:59 +02:00
|
|
|
if ( s_preScript )
|
|
|
|
{
|
|
|
|
bp::exec( s_preScript, scriptNamespace, scriptNamespace );
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:01:07 +01:00
|
|
|
cDebug() << "Job file" << scriptFI.absoluteFilePath();
|
2019-08-04 22:24:55 +02:00
|
|
|
bp::object execResult
|
|
|
|
= bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace );
|
2014-07-25 16:41:21 +02:00
|
|
|
bp::object entryPoint = scriptNamespace[ "run" ];
|
2017-08-10 16:43:49 +02:00
|
|
|
|
2020-03-09 21:39:35 +01:00
|
|
|
m_d->m_prettyStatusMessage = scriptNamespace.get( "pretty_status_message", bp::object() );
|
2020-03-09 21:01:07 +01:00
|
|
|
m_description = pythonStringMethod( scriptNamespace, "pretty_name" );
|
2017-08-10 16:43:49 +02:00
|
|
|
if ( m_description.isEmpty() )
|
|
|
|
{
|
2019-08-04 22:24:55 +02:00
|
|
|
bp::extract< std::string > entryPoint_doc_attr( entryPoint.attr( "__doc__" ) );
|
2017-08-10 16:43:49 +02:00
|
|
|
|
|
|
|
if ( entryPoint_doc_attr.check() )
|
|
|
|
{
|
|
|
|
m_description = QString::fromStdString( entryPoint_doc_attr() ).trimmed();
|
2019-08-04 22:24:55 +02:00
|
|
|
auto i_newline = m_description.indexOf( '\n' );
|
2017-08-10 16:43:49 +02:00
|
|
|
if ( i_newline > 0 )
|
2019-08-04 22:24:55 +02:00
|
|
|
{
|
2017-08-10 16:43:49 +02:00
|
|
|
m_description.truncate( i_newline );
|
2019-08-04 22:24:55 +02:00
|
|
|
}
|
2021-01-22 14:49:20 +01:00
|
|
|
cDebug() << Logger::SubEntry << "Job description from __doc__" << prettyName() << '=' << m_description;
|
2017-08-10 16:43:49 +02:00
|
|
|
}
|
2017-07-05 12:55:35 +02:00
|
|
|
}
|
2020-03-09 21:01:07 +01:00
|
|
|
else
|
|
|
|
{
|
2021-01-22 14:49:20 +01:00
|
|
|
cDebug() << Logger::SubEntry << "Job description from pretty_name" << prettyName() << '=' << m_description;
|
2020-03-09 21:01:07 +01:00
|
|
|
}
|
|
|
|
emit progress( 0 );
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2014-07-28 15:17:28 +02:00
|
|
|
bp::object runResult = entryPoint();
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2014-07-28 15:17:28 +02:00
|
|
|
if ( runResult.is_none() )
|
|
|
|
{
|
|
|
|
return JobResult::ok();
|
|
|
|
}
|
2019-08-04 22:24:55 +02:00
|
|
|
else // Something happened in the Python job
|
2014-07-28 15:17:28 +02:00
|
|
|
{
|
|
|
|
bp::tuple resultTuple = bp::extract< bp::tuple >( runResult );
|
|
|
|
QString message = QString::fromStdString( bp::extract< std::string >( resultTuple[ 0 ] ) );
|
|
|
|
QString description = QString::fromStdString( bp::extract< std::string >( resultTuple[ 1 ] ) );
|
2014-08-01 09:56:40 +02:00
|
|
|
return JobResult::error( message, description );
|
2014-07-28 15:17:28 +02:00
|
|
|
}
|
2014-07-16 16:07:32 +02:00
|
|
|
}
|
2020-10-24 13:19:42 +02:00
|
|
|
catch ( bp::error_already_set& )
|
2014-07-16 16:07:32 +02:00
|
|
|
{
|
2014-07-17 17:52:02 +02:00
|
|
|
QString msg;
|
|
|
|
if ( PyErr_Occurred() )
|
|
|
|
{
|
2020-03-09 16:05:01 +01:00
|
|
|
msg = CalamaresPython::Helper::instance()->handleLastError();
|
2014-07-17 17:52:02 +02:00
|
|
|
}
|
|
|
|
bp::handle_exception();
|
|
|
|
PyErr_Clear();
|
2023-11-07 23:43:09 +01:00
|
|
|
return JobResult::internalError( tr( "Boost.Python error in job \"%1\"", "@error" ).arg( prettyName() ),
|
|
|
|
msg,
|
|
|
|
JobResult::PythonUncaughtException );
|
2014-07-16 16:07:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-22 18:05:58 +02:00
|
|
|
void
|
2014-07-23 12:54:53 +02:00
|
|
|
PythonJob::emitProgress( qreal progressValue )
|
2014-07-22 18:05:58 +02:00
|
|
|
{
|
2020-03-09 21:39:35 +01:00
|
|
|
// This is called from the JobApi (and only from there) from the Job thread,
|
|
|
|
// so it is safe to call into the Python interpreter. Update the description
|
|
|
|
// as needed (don't call this from prettyStatusMessage(), which can be
|
|
|
|
// called from other threads as well).
|
|
|
|
if ( m_d && !m_d->m_prettyStatusMessage.is_none() )
|
|
|
|
{
|
|
|
|
QString r;
|
|
|
|
bp::extract< std::string > result( m_d->m_prettyStatusMessage() );
|
|
|
|
r = result.check() ? QString::fromStdString( result() ).trimmed() : QString();
|
|
|
|
if ( !r.isEmpty() )
|
|
|
|
{
|
|
|
|
m_description = r;
|
|
|
|
}
|
|
|
|
}
|
2014-07-23 12:54:53 +02:00
|
|
|
emit progress( progressValue );
|
2014-07-22 18:05:58 +02:00
|
|
|
}
|
|
|
|
|
2021-06-15 21:50:59 +02:00
|
|
|
void
|
|
|
|
PythonJob::setInjectedPreScript( const char* preScript )
|
|
|
|
{
|
|
|
|
s_preScript = preScript;
|
2021-09-27 13:18:12 +02:00
|
|
|
cDebug() << "Python pre-script set to string" << Logger::Pointer( preScript ) << "length"
|
|
|
|
<< ( preScript ? strlen( preScript ) : 0 );
|
2021-06-15 21:50:59 +02:00
|
|
|
}
|
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
} // namespace Calamares
|