2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-08-11 20:15:14 +02:00
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Descriptor.h"
|
|
|
|
|
2020-08-11 22:08:34 +02:00
|
|
|
#include "utils/Logger.h"
|
2020-08-12 08:42:52 +02:00
|
|
|
#include "utils/Variant.h"
|
2020-08-11 22:08:34 +02:00
|
|
|
|
2020-08-11 20:15:14 +02:00
|
|
|
namespace Calamares
|
|
|
|
{
|
|
|
|
namespace ModuleSystem
|
|
|
|
{
|
|
|
|
|
|
|
|
const NamedEnumTable< Type >&
|
|
|
|
typeNames()
|
|
|
|
{
|
|
|
|
// *INDENT-OFF*
|
|
|
|
// clang-format off
|
|
|
|
static const NamedEnumTable< Type > table{
|
|
|
|
{ QStringLiteral( "job" ), Type::Job },
|
|
|
|
{ QStringLiteral( "view" ), Type::View },
|
|
|
|
{ QStringLiteral( "viewmodule" ), Type::View },
|
|
|
|
{ QStringLiteral( "jobmodule" ), Type::Job }
|
|
|
|
};
|
|
|
|
// *INDENT-ON*
|
|
|
|
// clang-format on
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NamedEnumTable< Interface >&
|
|
|
|
interfaceNames()
|
|
|
|
{
|
|
|
|
// *INDENT-OFF*
|
|
|
|
// clang-format off
|
|
|
|
static const NamedEnumTable< Interface > table {
|
|
|
|
{ QStringLiteral("process"), Interface::Process },
|
|
|
|
{ QStringLiteral("qtplugin"), Interface::QtPlugin },
|
|
|
|
{ QStringLiteral("python"), Interface::Python },
|
|
|
|
{ QStringLiteral("pythonqt"), Interface::PythonQt }
|
|
|
|
};
|
|
|
|
// *INDENT-ON*
|
|
|
|
// clang-format on
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:08:34 +02:00
|
|
|
Descriptor::Descriptor() {}
|
|
|
|
|
|
|
|
Descriptor
|
|
|
|
Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
|
|
|
|
{
|
|
|
|
Descriptor d;
|
|
|
|
|
2020-08-12 00:33:08 +02:00
|
|
|
{
|
|
|
|
bool typeOk = false;
|
2020-08-12 08:42:52 +02:00
|
|
|
QString typeValue = moduleDesc.value( "type" ).toString();
|
|
|
|
Type t = typeNames().find( typeValue, typeOk );
|
|
|
|
if ( !typeOk )
|
|
|
|
{
|
|
|
|
cWarning() << "Module descriptor contains invalid *type*" << typeValue;
|
|
|
|
}
|
|
|
|
|
2020-08-12 00:33:08 +02:00
|
|
|
bool interfaceOk = false;
|
2020-08-12 08:42:52 +02:00
|
|
|
QString interfaceValue = moduleDesc.value( "interface" ).toString();
|
|
|
|
Interface i = interfaceNames().find( interfaceValue, interfaceOk );
|
|
|
|
if ( !interfaceOk )
|
|
|
|
{
|
|
|
|
cWarning() << "Module descriptor contains invalid *interface*" << interfaceValue;
|
|
|
|
}
|
|
|
|
|
2020-08-12 00:52:54 +02:00
|
|
|
d.m_name = moduleDesc.value( "name" ).toString();
|
|
|
|
if ( typeOk && interfaceOk && !d.m_name.isEmpty() )
|
2020-08-12 00:33:08 +02:00
|
|
|
{
|
|
|
|
d.m_type = t;
|
|
|
|
d.m_interface = i;
|
|
|
|
d.m_isValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !d.m_isValid )
|
|
|
|
{
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2020-08-12 08:42:52 +02:00
|
|
|
d.m_isEmergeny = CalamaresUtils::getBool( moduleDesc, "emergency", false );
|
|
|
|
d.m_hasConfig = !CalamaresUtils::getBool( moduleDesc, "noconfig", false ); // Inverted logic during load
|
|
|
|
d.m_requiredModules = CalamaresUtils::getStringList( moduleDesc, "requiredModules" );
|
2020-08-12 15:59:42 +02:00
|
|
|
d.m_weight = int( CalamaresUtils::getInteger( moduleDesc, "weight", -1 ) );
|
2020-08-12 08:42:52 +02:00
|
|
|
|
2020-08-12 15:59:42 +02:00
|
|
|
QStringList consumedKeys { "type", "interface", "name", "emergency", "noconfig", "requiredModules", "weight" };
|
2020-08-12 08:42:52 +02:00
|
|
|
|
2020-08-12 09:06:47 +02:00
|
|
|
switch ( d.interface() )
|
|
|
|
{
|
|
|
|
case Interface::QtPlugin:
|
|
|
|
d.m_script = CalamaresUtils::getString( moduleDesc, "load" );
|
|
|
|
consumedKeys << "load";
|
|
|
|
break;
|
|
|
|
case Interface::Python:
|
|
|
|
case Interface::PythonQt:
|
|
|
|
d.m_script = CalamaresUtils::getString( moduleDesc, "script" );
|
2020-08-12 15:59:42 +02:00
|
|
|
if ( d.m_script.isEmpty() )
|
|
|
|
{
|
|
|
|
cWarning() << "Module descriptor contains no *script*" << d.name();
|
|
|
|
d.m_isValid = false;
|
|
|
|
}
|
2020-08-12 09:06:47 +02:00
|
|
|
consumedKeys << "script";
|
|
|
|
break;
|
|
|
|
case Interface::Process:
|
|
|
|
d.m_script = CalamaresUtils::getString( moduleDesc, "command" );
|
2020-08-12 15:59:42 +02:00
|
|
|
d.m_processTimeout = int( CalamaresUtils::getInteger( moduleDesc, "timeout", 30 ) );
|
2020-08-12 09:06:47 +02:00
|
|
|
d.m_processChroot = CalamaresUtils::getBool( moduleDesc, "chroot", false );
|
|
|
|
if ( d.m_processTimeout < 0 )
|
|
|
|
{
|
|
|
|
d.m_processTimeout = 0;
|
|
|
|
}
|
2020-08-12 15:59:42 +02:00
|
|
|
if ( d.m_script.isEmpty() )
|
|
|
|
{
|
|
|
|
cWarning() << "Module descriptor contains no *script*" << d.name();
|
|
|
|
d.m_isValid = false;
|
|
|
|
}
|
|
|
|
consumedKeys << "command"
|
|
|
|
<< "timeout"
|
|
|
|
<< "chroot";
|
2020-08-12 09:06:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:59:42 +02:00
|
|
|
if ( !d.m_isValid )
|
|
|
|
{
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2020-08-12 08:42:52 +02:00
|
|
|
QStringList superfluousKeys;
|
|
|
|
for ( auto kv = moduleDesc.keyBegin(); kv != moduleDesc.keyEnd(); ++kv )
|
|
|
|
{
|
|
|
|
if ( !consumedKeys.contains( *kv ) )
|
|
|
|
{
|
|
|
|
superfluousKeys << *kv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !superfluousKeys.isEmpty() )
|
|
|
|
{
|
|
|
|
cWarning() << "Module descriptor contains extra keys:" << Logger::DebugList( superfluousKeys );
|
|
|
|
d.m_isValid = false;
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:08:34 +02:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:15:14 +02:00
|
|
|
} // namespace ModuleSystem
|
|
|
|
} // namespace Calamares
|