From 0ae41dd286d70286e36ff8e98a23043baecaa935 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Tue, 27 Sep 2016 04:26:58 +0200 Subject: [PATCH] New dummycpp C++ job module (ported from dummypython). --- settings.conf | 1 + src/modules/dummycpp/CMakeLists.txt | 9 ++ src/modules/dummycpp/DummyCppJob.cpp | 144 +++++++++++++++++++++++++++ src/modules/dummycpp/DummyCppJob.h | 51 ++++++++++ src/modules/dummycpp/dummycpp.conf | 18 ++++ src/modules/dummycpp/module.desc | 7 ++ 6 files changed, 230 insertions(+) create mode 100644 src/modules/dummycpp/CMakeLists.txt create mode 100644 src/modules/dummycpp/DummyCppJob.cpp create mode 100644 src/modules/dummycpp/DummyCppJob.h create mode 100644 src/modules/dummycpp/dummycpp.conf create mode 100644 src/modules/dummycpp/module.desc diff --git a/settings.conf b/settings.conf index 4da88a8dd..1818fd918 100644 --- a/settings.conf +++ b/settings.conf @@ -67,6 +67,7 @@ sequence: - users - summary - exec: +# - dummycpp # - dummyprocess # - dummypython - partition diff --git a/src/modules/dummycpp/CMakeLists.txt b/src/modules/dummycpp/CMakeLists.txt new file mode 100644 index 000000000..5b865b59d --- /dev/null +++ b/src/modules/dummycpp/CMakeLists.txt @@ -0,0 +1,9 @@ +calamares_add_plugin( dummycpp + TYPE job + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + DummyCppJob.cpp + LINK_LIBRARIES + calamares + SHARED_LIB +) diff --git a/src/modules/dummycpp/DummyCppJob.cpp b/src/modules/dummycpp/DummyCppJob.cpp new file mode 100644 index 000000000..15433392f --- /dev/null +++ b/src/modules/dummycpp/DummyCppJob.cpp @@ -0,0 +1,144 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac (original dummypython code) + * Copyright 2016, Kevin Kofler + * + * 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 . + */ + +#include "DummyCppJob.h" + +#include +#include +#include + +#include "CalamaresVersion.h" +#include "JobQueue.h" +#include "GlobalStorage.h" + +#include "utils/Logger.h" + +DummyCppJob::DummyCppJob( QObject* parent ) + : Calamares::CppJob( parent ) +{ +} + + +DummyCppJob::~DummyCppJob() +{ +} + + +QString +DummyCppJob::prettyName() const +{ + return tr( "Dummy C++ Job" ); +} + + +static QString variantListToString( const QVariantList& variantList ); +static QString variantMapToString( const QVariantMap& variantMap ); +static QString variantHashToString( const QVariantHash& variantHash ); + + +static QString +variantToString( const QVariant& variant ) +{ + switch ( variant.type() ) + { + case QVariant::Map: + return variantMapToString( variant.toMap() ); + + case QVariant::Hash: + return variantHashToString( variant.toHash() ); + + case QVariant::List: + case QVariant::StringList: + return variantListToString( variant.toList() ); + + default: + return variant.toString(); + } +} + + +static QString +variantListToString( const QVariantList& variantList ) +{ + QStringList result; + for ( const QVariant& variant : variantList ) + result.append( variantToString( variant ) ); + return '{' + result.join(',') + '}'; +} + + +static QString +variantMapToString( const QVariantMap& variantMap ) +{ + QStringList result; + for ( auto it = variantMap.constBegin(); it != variantMap.constEnd(); ++it ) + result.append( it.key() + '=' + variantToString( it.value() ) ); + return '[' + result.join(',') + ']'; +} + + +static QString +variantHashToString( const QVariantHash& variantHash ) +{ + QStringList result; + for ( auto it = variantHash.constBegin(); it != variantHash.constEnd(); ++it ) + result.append( it.key() + '=' + variantToString( it.value() ) ); + return '<' + result.join(',') + '>'; +} + + +Calamares::JobResult +DummyCppJob::exec() +{ + // Ported from dummypython + QProcess::execute( "/bin/sh", QStringList() << "-c" << "touch ~/calamares-dummycpp" ); + QString accumulator = QDateTime::currentDateTimeUtc().toString( Qt::ISODate ) + '\n'; + accumulator += QStringLiteral( "Calamares version: " ) + CALAMARES_VERSION_SHORT + '\n'; + accumulator += QStringLiteral( "This job's name: " ) + prettyName() + '\n'; + accumulator += QStringLiteral( "Configuration map: %1\n" ).arg( variantMapToString( m_configurationMap ) ); + accumulator += QStringLiteral( " *** globalstorage test ***\n" ); + Calamares::GlobalStorage *globalStorage = Calamares::JobQueue::instance()->globalStorage(); + accumulator += QStringLiteral( "lala: " ) + (globalStorage->contains( "lala" ) ? QStringLiteral( "true" ) : QStringLiteral( "false" )) + '\n'; + accumulator += QStringLiteral( "foo: " ) + (globalStorage->contains( "foo" ) ? QStringLiteral( "true" ) : QStringLiteral( "false" )) + '\n'; + accumulator += QStringLiteral( "count: " ) + QString::number( globalStorage->count() ) + '\n'; + globalStorage->insert( "item2", "value2" ); + globalStorage->insert( "item3", 3 ); + accumulator += QStringLiteral( "keys: %1\n" ).arg( globalStorage->keys().join( ',' ) ); + accumulator += QStringLiteral( "remove: %1\n" ).arg( QString::number( globalStorage->remove( "item2" ) ) ); + accumulator += QStringLiteral( "values: %1 %2 %3\n" ).arg( + globalStorage->value( "foo" ).toString(), + globalStorage->value( "item2" ).toString(), + globalStorage->value( "item3" ).toString() ); + + emit progress( 0.1 ); + cDebug() << "[DUMMYCPP]: " << accumulator; + + QThread::sleep( 3 ); + + return Calamares::JobResult::ok(); +} + + +void +DummyCppJob::setConfigurationMap( const QVariantMap& configurationMap ) +{ + m_configurationMap = configurationMap; +} + +CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyCppJobFactory, registerPlugin(); ) diff --git a/src/modules/dummycpp/DummyCppJob.h b/src/modules/dummycpp/DummyCppJob.h new file mode 100644 index 000000000..2b2a51a75 --- /dev/null +++ b/src/modules/dummycpp/DummyCppJob.h @@ -0,0 +1,51 @@ +/* === This file is part of Calamares - === + * + * Copyright 2016, Kevin Kofler + * + * 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 . + */ + +#ifndef DUMMYCPPJOB_H +#define DUMMYCPPJOB_H + +#include +#include + +#include + +#include + +#include + +class PLUGINDLLEXPORT DummyCppJob : public Calamares::CppJob +{ + Q_OBJECT + +public: + explicit DummyCppJob( QObject* parent = nullptr ); + virtual ~DummyCppJob(); + + QString prettyName() const override; + + Calamares::JobResult exec() override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +private: + QVariantMap m_configurationMap; +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( DummyCppJobFactory ) + +#endif // DUMMYCPPJOB_H diff --git a/src/modules/dummycpp/dummycpp.conf b/src/modules/dummycpp/dummycpp.conf new file mode 100644 index 000000000..c90b6f3b9 --- /dev/null +++ b/src/modules/dummycpp/dummycpp.conf @@ -0,0 +1,18 @@ +--- +syntax: "YAML map of anything" +example: + whats_this: "module-specific configuration" + from_where: "dummycpp.conf" +a_list: + - "item1" + - "item2" + - "item3" + - "item4" +a_list_of_maps: + - name: "an Item" + contents: + - "an element" + - "another element" + - name: "another item" + contents: + - "not much" \ No newline at end of file diff --git a/src/modules/dummycpp/module.desc b/src/modules/dummycpp/module.desc new file mode 100644 index 000000000..7f29e512e --- /dev/null +++ b/src/modules/dummycpp/module.desc @@ -0,0 +1,7 @@ +# Module metadata file for dummycpp job +# Syntax is YAML 1.2 +--- +type: "job" +name: "dummycpp" +interface: "qtplugin" +load: "libcalamares_job_dummycpp.so"