mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-27 01:15:38 -04:00
[contextualprocess] Apply current coding style
This commit is contained in:
parent
a0430f76b7
commit
8186d5730a
3 changed files with 36 additions and 23 deletions
|
@ -18,22 +18,22 @@
|
||||||
|
|
||||||
#include "ContextualProcessJob.h"
|
#include "ContextualProcessJob.h"
|
||||||
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QProcess>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#include "CalamaresVersion.h"
|
#include "CalamaresVersion.h"
|
||||||
#include "JobQueue.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "utils/CommandList.h"
|
#include "utils/CommandList.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
struct ValueCheck : public QPair<QString, CalamaresUtils::CommandList*>
|
struct ValueCheck : public QPair< QString, CalamaresUtils::CommandList* >
|
||||||
{
|
{
|
||||||
ValueCheck( const QString& value, CalamaresUtils::CommandList* commands )
|
ValueCheck( const QString& value, CalamaresUtils::CommandList* commands )
|
||||||
: QPair<QString, CalamaresUtils::CommandList*>(value, commands)
|
: QPair< QString, CalamaresUtils::CommandList* >( value, commands )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ struct ValueCheck : public QPair<QString, CalamaresUtils::CommandList*>
|
||||||
|
|
||||||
QString value() const { return first; }
|
QString value() const { return first; }
|
||||||
CalamaresUtils::CommandList* commands() const { return second; }
|
CalamaresUtils::CommandList* commands() const { return second; }
|
||||||
} ;
|
};
|
||||||
|
|
||||||
struct ContextualProcessBinding
|
struct ContextualProcessBinding
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,9 @@ struct ContextualProcessBinding
|
||||||
{
|
{
|
||||||
checks.append( ValueCheck( value, commands ) );
|
checks.append( ValueCheck( value, commands ) );
|
||||||
if ( value == QString( "*" ) )
|
if ( value == QString( "*" ) )
|
||||||
|
{
|
||||||
wildcard = commands;
|
wildcard = commands;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Calamares::JobResult run( const QString& value ) const
|
Calamares::JobResult run( const QString& value ) const
|
||||||
|
@ -75,19 +77,23 @@ struct ContextualProcessBinding
|
||||||
for ( const auto& c : checks )
|
for ( const auto& c : checks )
|
||||||
{
|
{
|
||||||
if ( value == c.value() )
|
if ( value == c.value() )
|
||||||
|
{
|
||||||
return c.commands()->run();
|
return c.commands()->run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( wildcard )
|
if ( wildcard )
|
||||||
|
{
|
||||||
return wildcard->run();
|
return wildcard->run();
|
||||||
|
}
|
||||||
|
|
||||||
return Calamares::JobResult::ok();
|
return Calamares::JobResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString variable;
|
QString variable;
|
||||||
QList<ValueCheck> checks;
|
QList< ValueCheck > checks;
|
||||||
CalamaresUtils::CommandList* wildcard{ nullptr };
|
CalamaresUtils::CommandList* wildcard { nullptr };
|
||||||
} ;
|
};
|
||||||
|
|
||||||
|
|
||||||
ContextualProcessBinding::~ContextualProcessBinding()
|
ContextualProcessBinding::~ContextualProcessBinding()
|
||||||
|
@ -129,10 +135,14 @@ ContextualProcessJob::exec()
|
||||||
{
|
{
|
||||||
Calamares::JobResult r = binding->run( gs->value( binding->variable ).toString() );
|
Calamares::JobResult r = binding->run( gs->value( binding->variable ).toString() );
|
||||||
if ( !r )
|
if ( !r )
|
||||||
|
{
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cWarning() << "ContextualProcess checks for unknown variable" << binding->variable;
|
cWarning() << "ContextualProcess checks for unknown variable" << binding->variable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Calamares::JobResult::ok();
|
return Calamares::JobResult::ok();
|
||||||
}
|
}
|
||||||
|
@ -144,13 +154,17 @@ ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
bool dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
bool dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
||||||
int timeout = CalamaresUtils::getInteger( configurationMap, "timeout", 10 );
|
int timeout = CalamaresUtils::getInteger( configurationMap, "timeout", 10 );
|
||||||
if ( timeout < 1 )
|
if ( timeout < 1 )
|
||||||
|
{
|
||||||
timeout = 10;
|
timeout = 10;
|
||||||
|
}
|
||||||
|
|
||||||
for ( QVariantMap::const_iterator iter = configurationMap.cbegin(); iter != configurationMap.cend(); ++iter )
|
for ( QVariantMap::const_iterator iter = configurationMap.cbegin(); iter != configurationMap.cend(); ++iter )
|
||||||
{
|
{
|
||||||
QString variableName = iter.key();
|
QString variableName = iter.key();
|
||||||
if ( variableName.isEmpty() || ( variableName == "dontChroot" ) || ( variableName == "timeout" ) )
|
if ( variableName.isEmpty() || ( variableName == "dontChroot" ) || ( variableName == "timeout" ) )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ( iter.value().type() != QVariant::Map )
|
if ( iter.value().type() != QVariant::Map )
|
||||||
{
|
{
|
||||||
|
@ -166,11 +180,13 @@ ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
QString valueString = valueiter.key();
|
QString valueString = valueiter.key();
|
||||||
if ( variableName.isEmpty() )
|
if ( variableName.isEmpty() )
|
||||||
{
|
{
|
||||||
cWarning() << moduleInstanceKey() << "variable" << variableName << "unrecognized value" << valueiter.key();
|
cWarning() << moduleInstanceKey() << "variable" << variableName << "unrecognized value"
|
||||||
|
<< valueiter.key();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalamaresUtils::CommandList* commands = new CalamaresUtils::CommandList( valueiter.value(), !dontChroot, std::chrono::seconds( timeout ) );
|
CalamaresUtils::CommandList* commands
|
||||||
|
= new CalamaresUtils::CommandList( valueiter.value(), !dontChroot, std::chrono::seconds( timeout ) );
|
||||||
|
|
||||||
binding->append( valueString, commands );
|
binding->append( valueString, commands );
|
||||||
}
|
}
|
||||||
|
@ -184,12 +200,14 @@ ContextualProcessJob::count()
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ContextualProcessJob::count(const QString& variableName)
|
ContextualProcessJob::count( const QString& variableName )
|
||||||
{
|
{
|
||||||
for ( const ContextualProcessBinding* binding : m_commands )
|
for ( const ContextualProcessBinding* binding : m_commands )
|
||||||
if ( binding->variable == variableName )
|
if ( binding->variable == variableName )
|
||||||
|
{
|
||||||
return binding->checks.count();
|
return binding->checks.count();
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( ContextualProcessJobFactory, registerPlugin<ContextualProcessJob>(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( ContextualProcessJobFactory, registerPlugin< ContextualProcessJob >(); )
|
||||||
|
|
|
@ -49,9 +49,9 @@ public:
|
||||||
int count( const QString& variableName );
|
int count( const QString& variableName );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ContextualProcessBinding*> m_commands;
|
QList< ContextualProcessBinding* > m_commands;
|
||||||
};
|
};
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( ContextualProcessJobFactory )
|
CALAMARES_PLUGIN_FACTORY_DECLARATION( ContextualProcessJobFactory )
|
||||||
|
|
||||||
#endif // CONTEXTUALPROCESSJOB_H
|
#endif // CONTEXTUALPROCESSJOB_H
|
||||||
|
|
|
@ -31,13 +31,9 @@ QTEST_GUILESS_MAIN( ContextualProcessTests )
|
||||||
|
|
||||||
using CommandList = CalamaresUtils::CommandList;
|
using CommandList = CalamaresUtils::CommandList;
|
||||||
|
|
||||||
ContextualProcessTests::ContextualProcessTests()
|
ContextualProcessTests::ContextualProcessTests() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ContextualProcessTests::~ContextualProcessTests()
|
ContextualProcessTests::~ContextualProcessTests() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ContextualProcessTests::initTestCase()
|
ContextualProcessTests::initTestCase()
|
||||||
|
@ -63,7 +59,6 @@ ContextualProcessTests::testProcessListSampleConfig()
|
||||||
ContextualProcessJob job;
|
ContextualProcessJob job;
|
||||||
job.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc ).toMap() );
|
job.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc ).toMap() );
|
||||||
|
|
||||||
QCOMPARE(job.count(), 1); // Only "firmwareType"
|
QCOMPARE( job.count(), 1 ); // Only "firmwareType"
|
||||||
QCOMPARE(job.count("firmwareType"), 4);
|
QCOMPARE( job.count( "firmwareType" ), 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue