2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2016-09-27 04:26:58 +02:00
|
|
|
*
|
|
|
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org> (original dummypython code)
|
|
|
|
* Copyright 2016, Kevin Kofler <kevin.kofler@chello.at>
|
2018-06-15 11:59:11 +02:00
|
|
|
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
2016-09-27 04:26:58 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DummyCppJob.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2019-08-09 16:34:53 +02:00
|
|
|
#include <QProcess>
|
2016-09-27 04:26:58 +02:00
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
#include "CalamaresVersion.h"
|
|
|
|
#include "GlobalStorage.h"
|
2019-08-09 16:34:53 +02:00
|
|
|
#include "JobQueue.h"
|
2016-09-27 04:26:58 +02:00
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
DummyCppJob::DummyCppJob( QObject* parent )
|
|
|
|
: Calamares::CppJob( parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-09 16:34:53 +02:00
|
|
|
DummyCppJob::~DummyCppJob() {}
|
2016-09-27 04:26:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2019-08-09 16:34:53 +02:00
|
|
|
if ( variant.type() == QVariant::Map )
|
2016-09-27 04:26:58 +02:00
|
|
|
{
|
|
|
|
return variantMapToString( variant.toMap() );
|
2019-08-09 16:34:53 +02:00
|
|
|
}
|
|
|
|
else if ( variant.type() == QVariant::Hash )
|
|
|
|
{
|
2016-09-27 04:26:58 +02:00
|
|
|
return variantHashToString( variant.toHash() );
|
2019-08-09 16:34:53 +02:00
|
|
|
}
|
|
|
|
else if ( ( variant.type() == QVariant::List ) || ( variant.type() == QVariant::StringList ) )
|
|
|
|
{
|
2016-09-27 04:26:58 +02:00
|
|
|
return variantListToString( variant.toList() );
|
2019-08-09 16:34:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-27 04:26:58 +02:00
|
|
|
return variant.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static QString
|
|
|
|
variantListToString( const QVariantList& variantList )
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
for ( const QVariant& variant : variantList )
|
2019-08-09 16:34:53 +02:00
|
|
|
{
|
2016-09-27 04:26:58 +02:00
|
|
|
result.append( variantToString( variant ) );
|
2019-08-09 16:34:53 +02:00
|
|
|
}
|
|
|
|
return '{' + result.join( ',' ) + '}';
|
2016-09-27 04:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static QString
|
|
|
|
variantMapToString( const QVariantMap& variantMap )
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
for ( auto it = variantMap.constBegin(); it != variantMap.constEnd(); ++it )
|
2019-08-09 16:34:53 +02:00
|
|
|
{
|
2016-09-27 04:26:58 +02:00
|
|
|
result.append( it.key() + '=' + variantToString( it.value() ) );
|
2019-08-09 16:34:53 +02:00
|
|
|
}
|
|
|
|
return '[' + result.join( ',' ) + ']';
|
2016-09-27 04:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static QString
|
|
|
|
variantHashToString( const QVariantHash& variantHash )
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
for ( auto it = variantHash.constBegin(); it != variantHash.constEnd(); ++it )
|
2019-08-09 16:34:53 +02:00
|
|
|
{
|
2016-09-27 04:26:58 +02:00
|
|
|
result.append( it.key() + '=' + variantToString( it.value() ) );
|
2019-08-09 16:34:53 +02:00
|
|
|
}
|
|
|
|
return '<' + result.join( ',' ) + '>';
|
2016-09-27 04:26:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Calamares::JobResult
|
|
|
|
DummyCppJob::exec()
|
|
|
|
{
|
|
|
|
// Ported from dummypython
|
2019-08-09 16:34:53 +02:00
|
|
|
QProcess::execute( "/bin/sh",
|
|
|
|
QStringList() << "-c"
|
|
|
|
<< "touch ~/calamares-dummycpp" );
|
2016-09-27 04:26:58 +02:00
|
|
|
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" );
|
2019-08-09 16:34:53 +02:00
|
|
|
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';
|
2016-09-27 04:26:58 +02:00
|
|
|
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" ) ) );
|
2019-08-09 16:34:53 +02:00
|
|
|
accumulator += QStringLiteral( "values: %1 %2 %3\n" )
|
|
|
|
.arg( globalStorage->value( "foo" ).toString(),
|
|
|
|
globalStorage->value( "item2" ).toString(),
|
|
|
|
globalStorage->value( "item3" ).toString() );
|
2016-09-27 04:26:58 +02:00
|
|
|
|
|
|
|
emit progress( 0.1 );
|
|
|
|
cDebug() << "[DUMMYCPP]: " << accumulator;
|
|
|
|
|
2018-01-24 15:28:46 +01:00
|
|
|
globalStorage->debugDump();
|
|
|
|
emit progress( 0.5 );
|
|
|
|
|
2016-09-27 04:26:58 +02:00
|
|
|
QThread::sleep( 3 );
|
|
|
|
|
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DummyCppJob::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
|
|
|
m_configurationMap = configurationMap;
|
|
|
|
}
|
|
|
|
|
2019-08-09 16:34:53 +02:00
|
|
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyCppJobFactory, registerPlugin< DummyCppJob >(); )
|