[libcalamares] Report preset mis-configurations
- warn about fields applied twice (program error) - warn about fields not used (configuration error) - add operator<< for "clean" looking preset application
This commit is contained in:
parent
d8dff3dc65
commit
2e90a8d829
@ -64,6 +64,28 @@ Config::ApplyPresets::ApplyPresets( Calamares::ModuleSystem::Config& c, const QV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Config::ApplyPresets::~ApplyPresets()
|
||||||
|
{
|
||||||
|
m_c.m_unlocked = false;
|
||||||
|
|
||||||
|
// Check that there's no **settings** (from the configuration map)
|
||||||
|
// that have not been consumed by apply() -- if they are there,
|
||||||
|
// that means the configuration map specifies things that the
|
||||||
|
// Config object does not expect.
|
||||||
|
bool haveWarned = false;
|
||||||
|
for ( const auto& k : m_map.keys() )
|
||||||
|
{
|
||||||
|
if ( !m_c.d->m_presets->find( k ).isValid() )
|
||||||
|
{
|
||||||
|
if ( !haveWarned )
|
||||||
|
{
|
||||||
|
cWarning() << "Preset configuration contains unused keys";
|
||||||
|
haveWarned = true;
|
||||||
|
}
|
||||||
|
cDebug() << Logger::SubEntry << "Unused key" << k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Config::ApplyPresets&
|
Config::ApplyPresets&
|
||||||
Config::ApplyPresets::apply( const char* fieldName )
|
Config::ApplyPresets::apply( const char* fieldName )
|
||||||
@ -76,7 +98,11 @@ Config::ApplyPresets::apply( const char* fieldName )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const QString key( fieldName );
|
const QString key( fieldName );
|
||||||
if ( !key.isEmpty() && m_map.contains( key ) )
|
if ( !key.isEmpty() && m_c.d->m_presets->find( key ).isValid() )
|
||||||
|
{
|
||||||
|
cWarning() << "Applying duplicate property" << fieldName;
|
||||||
|
}
|
||||||
|
else if ( !key.isEmpty() && m_map.contains( key ) )
|
||||||
{
|
{
|
||||||
QVariantMap m = CalamaresUtils::getSubMap( m_map, key, m_bogus );
|
QVariantMap m = CalamaresUtils::getSubMap( m_map, key, m_bogus );
|
||||||
QVariant value = m[ "value" ];
|
QVariant value = m[ "value" ];
|
||||||
|
@ -70,10 +70,25 @@ protected:
|
|||||||
class ApplyPresets
|
class ApplyPresets
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** @brief Create a preset-applier for this config
|
||||||
|
*
|
||||||
|
* The @p configurationMap should be the one passed in to
|
||||||
|
* setConfigurationMap() . Presets are extracted from the
|
||||||
|
* standard key *presets* and can be applied to the configuration
|
||||||
|
* with apply() or operator<<.
|
||||||
|
*/
|
||||||
ApplyPresets( Config& c, const QVariantMap& configurationMap );
|
ApplyPresets( Config& c, const QVariantMap& configurationMap );
|
||||||
~ApplyPresets() { m_c.m_unlocked = false; }
|
~ApplyPresets();
|
||||||
|
|
||||||
|
/** @brief Add a preset for the given @p fieldName
|
||||||
|
*
|
||||||
|
* This checks for preset-entries in the configuration map that was
|
||||||
|
* passed in to the constructor.
|
||||||
|
*/
|
||||||
ApplyPresets& apply( const char* fieldName );
|
ApplyPresets& apply( const char* fieldName );
|
||||||
|
/** @brief Alternate way of writing apply()
|
||||||
|
*/
|
||||||
|
ApplyPresets& operator<<( const char* fieldName ) { return apply( fieldName ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config& m_c;
|
Config& m_c;
|
||||||
|
@ -38,8 +38,6 @@ namespace Calamares
|
|||||||
namespace ModuleSystem
|
namespace ModuleSystem
|
||||||
{
|
{
|
||||||
Presets::Presets( const QVariantMap& configurationMap )
|
Presets::Presets( const QVariantMap& configurationMap )
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
reserve( configurationMap.count() );
|
reserve( configurationMap.count() );
|
||||||
loadPresets( *this, configurationMap, []( const QString& ) { return true; } );
|
loadPresets( *this, configurationMap, []( const QString& ) { return true; } );
|
||||||
@ -66,6 +64,19 @@ Presets::isEditable( const QString& fieldName ) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PresetField
|
||||||
|
Presets::find( const QString& fieldName ) const
|
||||||
|
{
|
||||||
|
for ( const auto& p : *this )
|
||||||
|
{
|
||||||
|
if ( p.fieldName == fieldName )
|
||||||
|
{
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PresetField();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ModuleSystem
|
} // namespace ModuleSystem
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -78,6 +78,12 @@ public:
|
|||||||
* returns @c true.
|
* returns @c true.
|
||||||
*/
|
*/
|
||||||
bool isEditable( const QString& fieldName ) const;
|
bool isEditable( const QString& fieldName ) const;
|
||||||
|
|
||||||
|
/** @brief Finds the settings for a field @p fieldName
|
||||||
|
*
|
||||||
|
* If there is no such field, returns an invalid PresetField.
|
||||||
|
*/
|
||||||
|
PresetField find( const QString& fieldName ) const;
|
||||||
};
|
};
|
||||||
} // namespace ModuleSystem
|
} // namespace ModuleSystem
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -842,7 +842,8 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
updateGSAutoLogin( doAutoLogin(), loginName() );
|
updateGSAutoLogin( doAutoLogin(), loginName() );
|
||||||
checkReady();
|
checkReady();
|
||||||
|
|
||||||
ApplyPresets( *this, configurationMap ).apply( "fullName" ).apply( "loginName" );
|
ApplyPresets( *this, configurationMap ) << "fullName"
|
||||||
|
<< "loginName";
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user