Merge branch 'tighten-yaml-types'
This commit is contained in:
commit
c850408555
@ -89,7 +89,7 @@ yamlScalarToVariant( const YAML::Node& scalarNode )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariantList
|
||||||
yamlSequenceToVariant( const YAML::Node& sequenceNode )
|
yamlSequenceToVariant( const YAML::Node& sequenceNode )
|
||||||
{
|
{
|
||||||
QVariantList vl;
|
QVariantList vl;
|
||||||
@ -101,7 +101,7 @@ yamlSequenceToVariant( const YAML::Node& sequenceNode )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariantMap
|
||||||
yamlMapToVariant( const YAML::Node& mapNode )
|
yamlMapToVariant( const YAML::Node& mapNode )
|
||||||
{
|
{
|
||||||
QVariantMap vm;
|
QVariantMap vm;
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QVariantList>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
class QByteArray;
|
class QByteArray;
|
||||||
class QFileInfo;
|
class QFileInfo;
|
||||||
@ -60,8 +62,8 @@ QVariantMap loadYaml( const QFileInfo&, bool* ok = nullptr );
|
|||||||
|
|
||||||
QVariant yamlToVariant( const YAML::Node& node );
|
QVariant yamlToVariant( const YAML::Node& node );
|
||||||
QVariant yamlScalarToVariant( const YAML::Node& scalarNode );
|
QVariant yamlScalarToVariant( const YAML::Node& scalarNode );
|
||||||
QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode );
|
QVariantList yamlSequenceToVariant( const YAML::Node& sequenceNode );
|
||||||
QVariant yamlMapToVariant( const YAML::Node& mapNode );
|
QVariantMap yamlMapToVariant( const YAML::Node& mapNode );
|
||||||
|
|
||||||
/// @brief Returns all the elements of @p listNode in a StringList
|
/// @brief Returns all the elements of @p listNode in a StringList
|
||||||
QStringList yamlToStringList( const YAML::Node& listNode );
|
QStringList yamlToStringList( const YAML::Node& listNode );
|
||||||
|
@ -123,7 +123,7 @@ loadStrings( QMap< QString, QString >& map,
|
|||||||
throw YAML::Exception( YAML::Mark(), std::string( "Branding configuration is not a map: " ) + key );
|
throw YAML::Exception( YAML::Mark(), std::string( "Branding configuration is not a map: " ) + key );
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& config = CalamaresUtils::yamlMapToVariant( doc[ key ] ).toMap();
|
const auto& config = CalamaresUtils::yamlMapToVariant( doc[ key ] );
|
||||||
|
|
||||||
map.clear();
|
map.clear();
|
||||||
for ( auto it = config.constBegin(); it != config.constEnd(); ++it )
|
for ( auto it = config.constBegin(); it != config.constEnd(); ++it )
|
||||||
|
@ -237,7 +237,7 @@ void Module::loadConfigurationFile( const QString& configFileName ) //throws YA
|
|||||||
}
|
}
|
||||||
|
|
||||||
cDebug() << "Loaded module configuration" << path;
|
cDebug() << "Loaded module configuration" << path;
|
||||||
m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ).toMap();
|
m_configurationMap = CalamaresUtils::yamlMapToVariant( doc );
|
||||||
m_emergency = m_maybe_emergency && m_configurationMap.contains( EMERGENCY )
|
m_emergency = m_maybe_emergency && m_configurationMap.contains( EMERGENCY )
|
||||||
&& m_configurationMap[ EMERGENCY ].toBool();
|
&& m_configurationMap[ EMERGENCY ].toBool();
|
||||||
return;
|
return;
|
||||||
|
@ -79,14 +79,15 @@ ContextualProcessTests::testProcessListSampleConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContextualProcessJob job;
|
ContextualProcessJob job;
|
||||||
job.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc ).toMap() );
|
job.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc ) );
|
||||||
|
|
||||||
QCOMPARE( job.count(), 2 ); // Only "firmwareType" and "branding.shortVersion"
|
QCOMPARE( job.count(), 2 ); // Only "firmwareType" and "branding.shortVersion"
|
||||||
QCOMPARE( job.count( "firmwareType" ), 4 );
|
QCOMPARE( job.count( "firmwareType" ), 4 );
|
||||||
QCOMPARE( job.count( "branding.shortVersion" ), 2 ); // in the example config
|
QCOMPARE( job.count( "branding.shortVersion" ), 2 ); // in the example config
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextualProcessTests::testFetch()
|
void
|
||||||
|
ContextualProcessTests::testFetch()
|
||||||
{
|
{
|
||||||
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
||||||
|
|
||||||
@ -187,5 +188,4 @@ void ContextualProcessTests::testFetch()
|
|||||||
QCOMPARE( s, QString() );
|
QCOMPARE( s, QString() );
|
||||||
QVERIFY( s.isEmpty() );
|
QVERIFY( s.isEmpty() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ ShellProcessTests::testProcessListSampleConfig()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) );
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 3 );
|
QCOMPARE( cl.count(), 3 );
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ script:
|
|||||||
- "ls /nonexistent"
|
- "ls /nonexistent"
|
||||||
- "/bin/false"
|
- "/bin/false"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) );
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 3 );
|
QCOMPARE( cl.count(), 3 );
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ script:
|
|||||||
- false
|
- false
|
||||||
- "ls /nonexistent"
|
- "ls /nonexistent"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) );
|
||||||
QVERIFY( !cl1.isEmpty() );
|
QVERIFY( !cl1.isEmpty() );
|
||||||
QCOMPARE( cl1.count(), 2 ); // One element ignored
|
QCOMPARE( cl1.count(), 2 ); // One element ignored
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ ShellProcessTests::testProcessListFromString()
|
|||||||
YAML::Node doc = YAML::Load( R"(---
|
YAML::Node doc = YAML::Load( R"(---
|
||||||
script: "ls /tmp"
|
script: "ls /tmp"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) );
|
||||||
|
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 1 );
|
QCOMPARE( cl.count(), 1 );
|
||||||
@ -112,7 +112,7 @@ script: "ls /tmp"
|
|||||||
doc = YAML::Load( R"(---
|
doc = YAML::Load( R"(---
|
||||||
script: false
|
script: false
|
||||||
)" );
|
)" );
|
||||||
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) );
|
||||||
QVERIFY( cl1.isEmpty() );
|
QVERIFY( cl1.isEmpty() );
|
||||||
QCOMPARE( cl1.count(), 0 );
|
QCOMPARE( cl1.count(), 0 );
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ script:
|
|||||||
command: "ls /tmp"
|
command: "ls /tmp"
|
||||||
timeout: 20
|
timeout: 20
|
||||||
)" );
|
)" );
|
||||||
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) );
|
||||||
|
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 1 );
|
QCOMPARE( cl.count(), 1 );
|
||||||
@ -142,7 +142,7 @@ script:
|
|||||||
timeout: 12
|
timeout: 12
|
||||||
- "-/bin/false"
|
- "-/bin/false"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).value( "script" ) );
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 2 );
|
QCOMPARE( cl.count(), 2 );
|
||||||
QCOMPARE( cl.at( 0 ).timeout(), 12s );
|
QCOMPARE( cl.at( 0 ).timeout(), 12s );
|
||||||
@ -157,12 +157,11 @@ ShellProcessTests::testRootSubstitution()
|
|||||||
script:
|
script:
|
||||||
- "ls /tmp"
|
- "ls /tmp"
|
||||||
)" );
|
)" );
|
||||||
QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" );
|
QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).value( "script" );
|
||||||
QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
|
QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
|
||||||
script:
|
script:
|
||||||
- "ls @@ROOT@@"
|
- "ls @@ROOT@@"
|
||||||
)" ) )
|
)" ) )
|
||||||
.toMap()
|
|
||||||
.value( "script" );
|
.value( "script" );
|
||||||
QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
|
QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
|
||||||
script:
|
script:
|
||||||
@ -170,7 +169,6 @@ script:
|
|||||||
- "chown @@USER@@ @@ROOT@@/calatest*"
|
- "chown @@USER@@ @@ROOT@@/calatest*"
|
||||||
- rm -rf @@ROOT@@/calatest*
|
- rm -rf @@ROOT@@/calatest*
|
||||||
)" ) )
|
)" ) )
|
||||||
.toMap()
|
|
||||||
.value( "script" );
|
.value( "script" );
|
||||||
|
|
||||||
if ( !Calamares::JobQueue::instance() )
|
if ( !Calamares::JobQueue::instance() )
|
||||||
|
Loading…
Reference in New Issue
Block a user