mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 19:05:46 -05:00
Python: add new Python job implementation
The implementation is quite incomplete: it does not actually run any Python code.
This commit is contained in:
parent
1eba9c828c
commit
61f0100cd9
6 changed files with 154 additions and 2 deletions
|
@ -64,4 +64,9 @@ if(BUILD_TESTING)
|
||||||
|
|
||||||
add_executable(test_conf test_conf.cpp)
|
add_executable(test_conf test_conf.cpp)
|
||||||
target_link_libraries(test_conf PUBLIC yamlcpp::yamlcpp ${qtname}::Core)
|
target_link_libraries(test_conf PUBLIC yamlcpp::yamlcpp ${qtname}::Core)
|
||||||
|
|
||||||
|
if(WITH_PYBIND11)
|
||||||
|
target_compile_definitions(loadmodule PRIVATE WITH_PYBIND11=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -29,11 +29,16 @@
|
||||||
#include "viewpages/ExecutionViewStep.h"
|
#include "viewpages/ExecutionViewStep.h"
|
||||||
|
|
||||||
// Optional features of Calamares
|
// Optional features of Calamares
|
||||||
// - Python support
|
// - Python support with pybind11
|
||||||
|
// - Python support with older Boost implementation
|
||||||
// - QML support
|
// - QML support
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
|
#if WITH_PYBIND11
|
||||||
|
#include "python/PythonJob.h"
|
||||||
|
#else
|
||||||
#include "PythonJob.h"
|
#include "PythonJob.h"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef WITH_QML
|
#ifdef WITH_QML
|
||||||
#include "utils/Qml.h"
|
#include "utils/Qml.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -472,7 +477,12 @@ main( int argc, char* argv[] )
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
if ( module.m_pythonInjection )
|
if ( module.m_pythonInjection )
|
||||||
{
|
{
|
||||||
|
#if WITH_PYBIND11
|
||||||
|
Calamares::Python::Job::setInjectedPreScript( pythonPreScript );
|
||||||
|
#else
|
||||||
|
// Old Boost approach
|
||||||
Calamares::PythonJob::setInjectedPreScript( pythonPreScript );
|
Calamares::PythonJob::setInjectedPreScript( pythonPreScript );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_QML
|
#ifdef WITH_QML
|
||||||
|
|
64
src/libcalamares/python/PythonJob.cpp
Normal file
64
src/libcalamares/python/PythonJob.cpp
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2023 Adriaan de Groot <groot@kde.org>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* Calamares is Free Software: see the License-Identifier above.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "python/PythonJob.h"
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
namespace Python
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Job::Private
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
Job::Job( const QString& scriptFile,
|
||||||
|
const QString& workingPath,
|
||||||
|
const QVariantMap& moduleConfiguration,
|
||||||
|
QObject* parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Job::~Job() {}
|
||||||
|
|
||||||
|
QString
|
||||||
|
Job::prettyName() const
|
||||||
|
{
|
||||||
|
return QStringLiteral( "Python Pretty" );
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
Job::prettyStatusMessage() const
|
||||||
|
{
|
||||||
|
return QStringLiteral( "Python Status" );
|
||||||
|
}
|
||||||
|
|
||||||
|
JobResult
|
||||||
|
Job::exec()
|
||||||
|
{
|
||||||
|
return JobResult::ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Sets the pre-run Python code for all PythonJobs
|
||||||
|
*
|
||||||
|
* A PythonJob runs the code from the scriptFile parameter to
|
||||||
|
* the constructor; the pre-run code is **also** run, before
|
||||||
|
* even the scriptFile code. Use this in testing mode
|
||||||
|
* to modify Python internals.
|
||||||
|
*
|
||||||
|
* No ownership of @p script is taken: pass in a pointer to
|
||||||
|
* a character literal or something that lives longer than the
|
||||||
|
* job. Pass in @c nullptr to switch off pre-run code.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Job::setInjectedPreScript( const char* script )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Python
|
||||||
|
} // namespace Calamares
|
61
src/libcalamares/python/PythonJob.h
Normal file
61
src/libcalamares/python/PythonJob.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2023 Adriaan de Groot <groot@kde.org>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* Calamares is Free Software: see the License-Identifier above.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CALAMARES_PYTHON_PYTHONJOB_H
|
||||||
|
#define CALAMARES_PYTHON_PYTHONJOB_H
|
||||||
|
|
||||||
|
// This file is called PythonJob.h because it would otherwise
|
||||||
|
// clashwith the Job.h in libcalamares proper.
|
||||||
|
|
||||||
|
#include "Job.h"
|
||||||
|
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
namespace Python
|
||||||
|
{
|
||||||
|
|
||||||
|
class Job : public ::Calamares::Job
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Job( const QString& scriptFile,
|
||||||
|
const QString& workingPath,
|
||||||
|
const QVariantMap& moduleConfiguration = QVariantMap(),
|
||||||
|
QObject* parent = nullptr );
|
||||||
|
~Job() override;
|
||||||
|
|
||||||
|
QString prettyName() const override;
|
||||||
|
QString prettyStatusMessage() const override;
|
||||||
|
::Calamares::JobResult exec() override;
|
||||||
|
|
||||||
|
/** @brief Sets the pre-run Python code for all PythonJobs
|
||||||
|
*
|
||||||
|
* A PythonJob runs the code from the scriptFile parameter to
|
||||||
|
* the constructor; the pre-run code is **also** run, before
|
||||||
|
* even the scriptFile code. Use this in testing mode
|
||||||
|
* to modify Python internals.
|
||||||
|
*
|
||||||
|
* No ownership of @p script is taken: pass in a pointer to
|
||||||
|
* a character literal or something that lives longer than the
|
||||||
|
* job. Pass in @c nullptr to switch off pre-run code.
|
||||||
|
*/
|
||||||
|
static void setInjectedPreScript( const char* script );
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Private;
|
||||||
|
std::unique_ptr< Private > m_d;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Python
|
||||||
|
} // namespace Calamares
|
||||||
|
#endif
|
|
@ -64,6 +64,10 @@ if(WITH_QML)
|
||||||
target_link_libraries(calamaresui PUBLIC ${qtname}::QuickWidgets)
|
target_link_libraries(calamaresui PUBLIC ${qtname}::QuickWidgets)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(WITH_PYBIND11)
|
||||||
|
target_compile_definitions(calamaresui PRIVATE WITH_PYBIND11=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(Calamares::calamaresui ALIAS calamaresui)
|
add_library(Calamares::calamaresui ALIAS calamaresui)
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||||
*
|
*
|
||||||
* SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
|
* SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
|
||||||
|
* SPDX-FileCopyrightText: 2023 Adriaan de Groot <groot@kde.org>
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* Calamares is Free Software: see the License-Identifier above.
|
* Calamares is Free Software: see the License-Identifier above.
|
||||||
|
@ -9,7 +10,14 @@
|
||||||
|
|
||||||
#include "PythonJobModule.h"
|
#include "PythonJobModule.h"
|
||||||
|
|
||||||
|
#if WITH_PYBIND11
|
||||||
|
#include "python/PythonJob.h"
|
||||||
|
using JobType = Calamares::Python::Job;
|
||||||
|
#else
|
||||||
|
// Old Boost::Python version
|
||||||
#include "PythonJob.h"
|
#include "PythonJob.h"
|
||||||
|
using JobType = Calamares::PythonJob;
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
@ -40,7 +48,7 @@ PythonJobModule::loadSelf()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_job = Calamares::job_ptr( new PythonJob( m_scriptFileName, m_workingPath, m_configurationMap ) );
|
m_job = Calamares::job_ptr( new JobType( m_scriptFileName, m_workingPath, m_configurationMap ) );
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue