[libcalamares] Complete the generic module descriptor
- loads emergency, noconfig, requiredModules keys - warns (and marks descriptor invalid) if there are unused / unknown keys left over in the descriptor data.
This commit is contained in:
parent
e406ae1967
commit
c8b96c278b
@ -8,6 +8,7 @@
|
||||
#include "Descriptor.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
@ -57,9 +58,21 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
|
||||
|
||||
{
|
||||
bool typeOk = false;
|
||||
Type t = typeNames().find( moduleDesc.value( "type" ).toString(), typeOk );
|
||||
QString typeValue = moduleDesc.value( "type" ).toString();
|
||||
Type t = typeNames().find( typeValue, typeOk );
|
||||
if ( !typeOk )
|
||||
{
|
||||
cWarning() << "Module descriptor contains invalid *type*" << typeValue;
|
||||
}
|
||||
|
||||
bool interfaceOk = false;
|
||||
Interface i = interfaceNames().find( moduleDesc.value( "interface" ).toString(), interfaceOk );
|
||||
QString interfaceValue = moduleDesc.value( "interface" ).toString();
|
||||
Interface i = interfaceNames().find( interfaceValue, interfaceOk );
|
||||
if ( !interfaceOk )
|
||||
{
|
||||
cWarning() << "Module descriptor contains invalid *interface*" << interfaceValue;
|
||||
}
|
||||
|
||||
d.m_name = moduleDesc.value( "name" ).toString();
|
||||
if ( typeOk && interfaceOk && !d.m_name.isEmpty() )
|
||||
{
|
||||
@ -73,6 +86,26 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
|
||||
return d;
|
||||
}
|
||||
|
||||
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" );
|
||||
|
||||
QStringList consumedKeys { "type", "interface", "name", "emergency", "noconfig", "requiredModules" };
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
@ -78,14 +78,14 @@ public:
|
||||
Type type() const { return m_type; }
|
||||
Interface interface() const { return m_interface; }
|
||||
|
||||
bool isEmergency() const { return false; }
|
||||
bool hasConfig() const { return true; }
|
||||
bool isEmergency() const { return m_isEmergeny; }
|
||||
bool hasConfig() const { return m_hasConfig; }
|
||||
|
||||
/// @brief The directory where the module.desc lives
|
||||
QString directory() const { return m_directory; }
|
||||
void setDirectory( const QString& d ) { m_directory = d; }
|
||||
|
||||
QStringList requiredModules() const { return QStringList {}; }
|
||||
const QStringList& requiredModules() const { return m_requiredModules; }
|
||||
|
||||
/** @section C++ Modules
|
||||
*
|
||||
@ -121,9 +121,12 @@ public:
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_directory;
|
||||
QStringList m_requiredModules;
|
||||
Type m_type;
|
||||
Interface m_interface;
|
||||
bool m_isValid = false;
|
||||
bool m_isEmergeny = false;
|
||||
bool m_hasConfig = true;
|
||||
};
|
||||
|
||||
} // namespace ModuleSystem
|
||||
|
Loading…
Reference in New Issue
Block a user