Merge branch 'wrangle-boost'

This commit is contained in:
Adriaan de Groot 2020-02-12 12:44:09 +01:00
commit 59ddda6225
11 changed files with 183 additions and 215 deletions

View File

@ -27,17 +27,6 @@
#include <QFile>
#include <QJsonDocument>
#ifdef WITH_PYTHON
#include "PythonHelper.h"
#undef slots
#include <boost/python/list.hpp>
#include <boost/python/str.hpp>
namespace bp = boost::python;
#endif
using CalamaresUtils::operator""_MiB;
namespace Calamares
@ -167,75 +156,3 @@ GlobalStorage::loadYaml( const QString& filename )
} // namespace Calamares
#ifdef WITH_PYTHON
namespace CalamaresPython
{
Calamares::GlobalStorage* GlobalStoragePythonWrapper::s_gs_instance = nullptr;
// The special handling for nullptr is only for the testing
// script for the python bindings, which passes in None;
// normal use will have a GlobalStorage from JobQueue::instance()
// passed in. Testing use will leak the allocated GlobalStorage
// object, but that's OK for testing.
GlobalStoragePythonWrapper::GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs )
: m_gs( gs ? gs : s_gs_instance )
{
if ( !m_gs )
{
s_gs_instance = new Calamares::GlobalStorage;
m_gs = s_gs_instance;
}
}
bool
GlobalStoragePythonWrapper::contains( const std::string& key ) const
{
return m_gs->contains( QString::fromStdString( key ) );
}
int
GlobalStoragePythonWrapper::count() const
{
return m_gs->count();
}
void
GlobalStoragePythonWrapper::insert( const std::string& key, const bp::object& value )
{
m_gs->insert( QString::fromStdString( key ), CalamaresPython::variantFromPyObject( value ) );
}
bp::list
GlobalStoragePythonWrapper::keys() const
{
bp::list pyList;
const auto keys = m_gs->keys();
for ( const QString& key : keys )
{
pyList.append( key.toStdString() );
}
return pyList;
}
int
GlobalStoragePythonWrapper::remove( const std::string& key )
{
return m_gs->remove( QString::fromStdString( key ) );
}
bp::object
GlobalStoragePythonWrapper::value( const std::string& key ) const
{
return CalamaresPython::variantToPyObject( m_gs->value( QString::fromStdString( key ) ) );
}
} // namespace CalamaresPython
#endif // WITH_PYTHON

View File

@ -26,20 +26,6 @@
#include <QString>
#include <QVariantMap>
#ifdef WITH_PYTHON
namespace boost
{
namespace python
{
namespace api
{
class object;
}
class list;
} // namespace python
} // namespace boost
#endif
namespace Calamares
{
@ -106,33 +92,4 @@ private:
} // namespace Calamares
#ifdef WITH_PYTHON
namespace CalamaresPython
{
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()
};
} // namespace CalamaresPython
#endif
#endif // CALAMARES_GLOBALSTORAGE_H

View File

@ -19,15 +19,11 @@
#include "JobQueue.h"
#include "CalamaresConfig.h"
#include "GlobalStorage.h"
#include "Job.h"
#include "utils/Logger.h"
#include "CalamaresConfig.h"
#ifdef WITH_PYTHON
#include "PythonHelper.h"
#endif
#include <QThread>
namespace Calamares

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2018, 2020, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,20 +19,13 @@
#include "PythonHelper.h"
#include "GlobalStorage.h"
#include "utils/Dirs.h"
#include "utils/Logger.h"
#include <QDir>
#include <QFileInfo>
#undef slots
#include "utils/boost-warnings.h"
#include <boost/python.hpp>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
namespace bp = boost::python;
namespace CalamaresPython
@ -398,5 +391,67 @@ Helper::handleLastError()
return QString( "<div>%1</div>" ).arg( msgList.join( "</div><div>" ) );
}
Calamares::GlobalStorage* GlobalStoragePythonWrapper::s_gs_instance = nullptr;
// The special handling for nullptr is only for the testing
// script for the python bindings, which passes in None;
// normal use will have a GlobalStorage from JobQueue::instance()
// passed in. Testing use will leak the allocated GlobalStorage
// object, but that's OK for testing.
GlobalStoragePythonWrapper::GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs )
: m_gs( gs ? gs : s_gs_instance )
{
if ( !m_gs )
{
s_gs_instance = new Calamares::GlobalStorage;
m_gs = s_gs_instance;
}
}
bool
GlobalStoragePythonWrapper::contains( const std::string& key ) const
{
return m_gs->contains( QString::fromStdString( key ) );
}
int
GlobalStoragePythonWrapper::count() const
{
return m_gs->count();
}
void
GlobalStoragePythonWrapper::insert( const std::string& key, const bp::object& value )
{
m_gs->insert( QString::fromStdString( key ), CalamaresPython::variantFromPyObject( value ) );
}
bp::list
GlobalStoragePythonWrapper::keys() const
{
bp::list pyList;
const auto keys = m_gs->keys();
for ( const QString& key : keys )
{
pyList.append( key.toStdString() );
}
return pyList;
}
int
GlobalStoragePythonWrapper::remove( const std::string& key )
{
return m_gs->remove( QString::fromStdString( key ) );
}
bp::object
GlobalStoragePythonWrapper::value( const std::string& key ) const
{
return CalamaresPython::variantToPyObject( m_gs->value( QString::fromStdString( key ) ) );
}
} // namespace CalamaresPython

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2018, Adriaan de Groot <groot@kde.org>
* Copyright 2018, 2020, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,19 +21,14 @@
#define CALAMARES_PYTHONJOBHELPER_H
#include "PythonJob.h"
#include "utils/BoostPython.h"
#include <QStringList>
#undef slots
#include "utils/boost-warnings.h"
#include <boost/python/dict.hpp>
#include <boost/python/list.hpp>
#include <boost/python/object.hpp>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
namespace Calamares
{
class GlobalStorage;
}
namespace CalamaresPython
{
@ -72,6 +67,28 @@ private:
QStringList m_pythonPaths;
};
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()
};
} // namespace CalamaresPython
#endif // CALAMARES_PYTHONJOBHELPER_H

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2018, Adriaan de Groot <groot@kde.org>
* Copyright 2018, 2020, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,22 +19,16 @@
#include "PythonJob.h"
#include "CalamaresVersion.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "PythonHelper.h"
#include "PythonJobApi.h"
#include "utils/BoostPython.h"
#include "utils/Logger.h"
#include <QDir>
#undef slots
#include "utils/boost-warnings.h"
#include <boost/python.hpp>
#include <boost/python/args.hpp>
#include "PythonJobApi.h"
namespace bp = boost::python;
BOOST_PYTHON_FUNCTION_OVERLOADS( mount_overloads, CalamaresPython::mount, 2, 4 );
@ -182,7 +176,7 @@ PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance,
, m_workingPath( workingPath )
, m_description()
, m_configurationMap( moduleConfiguration )
, m_weight( (instance.module() == QStringLiteral( "unpackfs" )) ? 12.0 : 1.0 )
, m_weight( ( instance.module() == QStringLiteral( "unpackfs" ) ) ? 12.0 : 1.0 )
{
}

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2020, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,7 +24,7 @@
#include "modulesystem/InstanceKey.h"
#include <QVariant>
#include <QVariantMap>
namespace CalamaresPython
{

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2020, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,26 +19,17 @@
#include "PythonJobApi.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "PythonHelper.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h"
#include "utils/String.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include <QCoreApplication>
#include <QDir>
#include <QStandardPaths>
#undef slots
#include "utils/boost-warnings.h"
#include <boost/python.hpp>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
namespace bp = boost::python;
static int

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2018, 2020, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,17 +20,14 @@
#ifndef PYTHONJOBAPI_H
#define PYTHONJOBAPI_H
#include "CalamaresVersion.h"
#include "qglobal.h" // For qreal
#include "PythonJob.h"
#include "utils/BoostPython.h"
#undef slots
#include "utils/boost-warnings.h"
#include <boost/python/dict.hpp>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
namespace Calamares
{
class PythonJob;
}
namespace CalamaresPython
{

View File

@ -0,0 +1,73 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* The Python and Boost::Python headers are not C++14 warning-proof, especially
* with picky compilers like Clang 8 and 9. Since we use Clang for the
* find-all-the-warnings case, switch those warnings off for
* the we-can't-change-them system headers.
*
* This convenience header handles including all the bits we need for
* Python support, while silencing warnings.
*/
#ifndef UTILS_BOOSTPYTHON_H
#define UTILS_BOOSTPYTHON_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
#pragma clang diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
#pragma clang diagnostic ignored "-Wundef"
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#pragma clang diagnostic ignored "-Wshadow-field-in-constructor"
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wmissing-noreturn"
#pragma clang diagnostic ignored "-Wcast-qual"
#pragma clang diagnostic ignored "-Wcast-align"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wdouble-promotion"
#pragma clang diagnostic ignored "-Wredundant-parens"
#pragma clang diagnostic ignored "-Wweak-vtables"
#pragma clang diagnostic ignored "-Wdeprecated"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
#pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wcomma"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wunused-template"
// Actually for Python headers
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#undef slots
#include <boost/python.hpp>
#include <boost/python/args.hpp>
#include <boost/python/dict.hpp>
#include <boost/python/list.hpp>
#include <boost/python/object.hpp>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif

View File

@ -1,30 +0,0 @@
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
#pragma clang diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
#pragma clang diagnostic ignored "-Wundef"
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#pragma clang diagnostic ignored "-Wshadow-field-in-constructor"
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wmissing-noreturn"
#pragma clang diagnostic ignored "-Wcast-qual"
#pragma clang diagnostic ignored "-Wcast-align"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wdouble-promotion"
#pragma clang diagnostic ignored "-Wredundant-parens"
#pragma clang diagnostic ignored "-Wweak-vtables"
#pragma clang diagnostic ignored "-Wdeprecated"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
#pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wcomma"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wunused-template"
// Actually for Python headers
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif