mirror of https://github.com/cutefishos/calamares
Merge branch 'issue-1176' into calamares
This doesn't actually implement the job-weight work, but lays important groundwork in module instances and descriptors. SEE #1176 FIXES #1473 FIXES #1474main
commit
e2f6817536
@ -0,0 +1,137 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Descriptor.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Descriptor::Descriptor() {}
|
||||
|
||||
Descriptor
|
||||
Descriptor::fromDescriptorData( const QVariantMap& moduleDesc )
|
||||
{
|
||||
Descriptor d;
|
||||
|
||||
{
|
||||
bool typeOk = false;
|
||||
QString typeValue = moduleDesc.value( "type" ).toString();
|
||||
Type t = typeNames().find( typeValue, typeOk );
|
||||
if ( !typeOk )
|
||||
{
|
||||
cWarning() << "Module descriptor contains invalid *type*" << typeValue;
|
||||
}
|
||||
|
||||
bool interfaceOk = false;
|
||||
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() )
|
||||
{
|
||||
d.m_type = t;
|
||||
d.m_interface = i;
|
||||
d.m_isValid = true;
|
||||
}
|
||||
}
|
||||
if ( !d.m_isValid )
|
||||
{
|
||||
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" };
|
||||
|
||||
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" );
|
||||
consumedKeys << "script";
|
||||
break;
|
||||
case Interface::Process:
|
||||
d.m_script = CalamaresUtils::getString( moduleDesc, "command" );
|
||||
d.m_processTimeout = CalamaresUtils::getInteger( moduleDesc, "timeout", 30 );
|
||||
d.m_processChroot = CalamaresUtils::getBool( moduleDesc, "chroot", false );
|
||||
consumedKeys << "command"
|
||||
<< "timeout"
|
||||
<< "chroot";
|
||||
|
||||
if ( d.m_processTimeout < 0 )
|
||||
{
|
||||
d.m_processTimeout = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace ModuleSystem
|
||||
} // namespace Calamares
|
@ -1,22 +0,0 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* License-Filename: LICENSE
|
||||
*
|
||||
*/
|
||||
#include "Requirement.h"
|
Loading…
Reference in New Issue