2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CALAMARES_PYTHONJOBHELPER_H
|
|
|
|
#define CALAMARES_PYTHONJOBHELPER_H
|
|
|
|
|
|
|
|
#include "PythonJob.h"
|
2020-02-12 11:02:38 +01:00
|
|
|
#include "utils/BoostPython.h"
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2014-07-17 17:52:02 +02:00
|
|
|
#include <QStringList>
|
|
|
|
|
2020-02-12 12:37:43 +01:00
|
|
|
namespace Calamares
|
|
|
|
{
|
|
|
|
class GlobalStorage;
|
|
|
|
}
|
|
|
|
|
2016-07-04 23:30:45 +02:00
|
|
|
namespace CalamaresPython
|
|
|
|
{
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
boost::python::object variantToPyObject( const QVariant& variant );
|
|
|
|
QVariant variantFromPyObject( const boost::python::object& pyObject );
|
2014-07-21 17:08:06 +02:00
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
boost::python::list variantListToPyList( const QVariantList& variantList );
|
|
|
|
QVariantList variantListFromPyList( const boost::python::list& pyList );
|
2014-07-21 17:08:06 +02:00
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
boost::python::dict variantMapToPyDict( const QVariantMap& variantMap );
|
|
|
|
QVariantMap variantMapFromPyDict( const boost::python::dict& pyDict );
|
2014-07-18 14:27:59 +02:00
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
boost::python::dict variantHashToPyDict( const QVariantHash& variantHash );
|
|
|
|
QVariantHash variantHashFromPyDict( const boost::python::dict& pyDict );
|
2016-07-04 23:30:45 +02:00
|
|
|
|
2014-07-18 14:27:59 +02:00
|
|
|
|
2014-07-18 11:59:12 +02:00
|
|
|
class Helper : public QObject
|
2014-07-16 16:07:32 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-12-01 22:42:56 +01:00
|
|
|
boost::python::dict createCleanNamespace();
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2014-07-17 17:52:02 +02:00
|
|
|
QString handleLastError();
|
|
|
|
|
2020-03-09 16:05:01 +01:00
|
|
|
static Helper* instance();
|
|
|
|
|
2014-07-16 16:07:32 +02:00
|
|
|
private:
|
2020-03-09 16:05:01 +01:00
|
|
|
virtual ~Helper();
|
|
|
|
explicit Helper();
|
2014-07-16 16:07:32 +02:00
|
|
|
|
|
|
|
boost::python::object m_mainModule;
|
|
|
|
boost::python::object m_mainNamespace;
|
2014-07-17 17:52:02 +02:00
|
|
|
|
|
|
|
QStringList m_pythonPaths;
|
2014-07-16 16:07:32 +02:00
|
|
|
};
|
|
|
|
|
2020-02-12 12:37:43 +01:00
|
|
|
class GlobalStoragePythonWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs );
|
|
|
|
|
|
|
|
bool contains( const std::string& key ) const;
|
|
|
|
int count() const;
|
|
|
|
void insert( const std::string& key, const boost::python::api::object& value );
|
|
|
|
boost::python::list keys() const;
|
|
|
|
int remove( const std::string& key );
|
|
|
|
boost::python::api::object value( const std::string& key ) const;
|
|
|
|
|
|
|
|
// This is a helper for scripts that do not go through
|
|
|
|
// the JobQueue (i.e. the module testpython script),
|
|
|
|
// which allocate their own (singleton) GlobalStorage.
|
|
|
|
static Calamares::GlobalStorage* globalStorageInstance() { return s_gs_instance; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Calamares::GlobalStorage* m_gs;
|
|
|
|
static Calamares::GlobalStorage* s_gs_instance; // See globalStorageInstance()
|
|
|
|
};
|
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
} // namespace CalamaresPython
|
2014-07-16 16:07:32 +02:00
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
#endif // CALAMARES_PYTHONJOBHELPER_H
|