[libcalamaresui] Chase the change in Module descriptor

- most of the code becomes **simpler** because the requirement
  to handle unstructured data is now in the descriptor itself,
  rather than in consumers.
main
Adriaan de Groot 4 years ago
parent ee834a7abb
commit 3c6e53ecb9

@ -84,13 +84,12 @@ CppJobModule::jobs() const
void
CppJobModule::initFrom( const QVariantMap& moduleDescriptor )
CppJobModule::initFrom( const ModuleSystem::Descriptor& moduleDescriptor )
{
QDir directory( location() );
QString load;
if ( !moduleDescriptor.value( "load" ).toString().isEmpty() )
QString load = moduleDescriptor.load();
if ( !load.isEmpty() )
{
load = moduleDescriptor.value( "load" ).toString();
load = directory.absoluteFilePath( load );
}
// If a load path is not specified, we look for a plugin to load in the directory.

@ -39,7 +39,7 @@ public:
JobList jobs() const override;
protected:
void initFrom( const QVariantMap& moduleDescriptor ) override;
void initFrom( const ModuleSystem::Descriptor& moduleDescriptor ) override;
private:
explicit CppJobModule();

@ -52,23 +52,22 @@ moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescripto
const QString& configFileName,
const QString& moduleDirectory )
{
std::unique_ptr< Module > m;
using Type = Calamares::ModuleSystem::Type;
using Interface = Calamares::ModuleSystem::Interface;
QString typeString = moduleDescriptor.value( "type" ).toString();
QString intfString = moduleDescriptor.value( "interface" ).toString();
std::unique_ptr< Module > m;
if ( typeString.isEmpty() || intfString.isEmpty() )
{
if ( !moduleDescriptor.isValid() ) {
cError() << "Bad module descriptor format" << instanceId;
return nullptr;
}
if ( ( typeString == "view" ) || ( typeString == "viewmodule" ) )
if ( moduleDescriptor.type() == Type::View )
{
if ( intfString == "qtplugin" )
if ( moduleDescriptor.interface() == Interface::QtPlugin )
{
m.reset( new ViewModule() );
}
else if ( intfString == "pythonqt" )
else if ( moduleDescriptor.interface() == Interface::PythonQt )
{
#ifdef WITH_PYTHONQT
m.reset( new PythonQtViewModule() );
@ -78,20 +77,20 @@ moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescripto
}
else
{
cError() << "Bad interface" << intfString << "for module type" << typeString;
cError() << "Bad interface" << Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() ) << "for module type" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() );
}
}
else if ( typeString == "job" )
else if ( moduleDescriptor.type() == Type::Job )
{
if ( intfString == "qtplugin" )
if ( moduleDescriptor.interface() == Interface::QtPlugin )
{
m.reset( new CppJobModule() );
}
else if ( intfString == "process" )
else if ( moduleDescriptor.interface() == Interface::Process )
{
m.reset( new ProcessJobModule() );
}
else if ( intfString == "python" )
else if ( moduleDescriptor.interface() == Interface::Python )
{
#ifdef WITH_PYTHON
m.reset( new PythonJobModule() );
@ -101,17 +100,17 @@ moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescripto
}
else
{
cError() << "Bad interface" << intfString << "for module type" << typeString;
cError() << "Bad interface" << Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() ) << "for module type" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() );
}
}
else
{
cError() << "Bad module type" << typeString;
cError() << "Bad module type" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() );
}
if ( !m )
{
cError() << "Bad module type (" << typeString << ") or interface string (" << intfString << ") for module "
cError() << "Bad module type (" << Calamares::ModuleSystem::typeNames().find( moduleDescriptor.type() ) << ") or interface string (" << Calamares::ModuleSystem::interfaceNames().find( moduleDescriptor.interface() ) << ") for module "
<< instanceId;
return nullptr;
}

@ -114,9 +114,9 @@ ModuleManager::doInit()
if ( ok && !moduleName.isEmpty() && ( moduleName == currentDir.dirName() )
&& !m_availableDescriptorsByModuleName.contains( moduleName ) )
{
m_availableDescriptorsByModuleName.insert( moduleName, moduleDescriptorMap );
m_moduleDirectoriesByModuleName.insert( moduleName,
descriptorFileInfo.absoluteDir().absolutePath() );
auto descriptor = Calamares::ModuleSystem::Descriptor::fromDescriptorData( moduleDescriptorMap );
descriptor.setDirectory(descriptorFileInfo.absoluteDir().absolutePath() );
m_availableDescriptorsByModuleName.insert( moduleName, descriptor );
}
}
else
@ -132,8 +132,7 @@ ModuleManager::doInit()
}
// At this point m_availableDescriptorsByModuleName is filled with
// the modules that were found in the search paths.
cDebug() << "Found" << m_availableDescriptorsByModuleName.count() << "modules"
<< m_moduleDirectoriesByModuleName.count() << "names";
cDebug() << "Found" << m_availableDescriptorsByModuleName.count() << "modules";
emit initDone();
}
@ -169,7 +168,7 @@ getConfigFileName( const Settings::InstanceDescriptionList& descriptorList,
const ModuleSystem::InstanceKey& instanceKey,
const ModuleSystem::Descriptor& descriptor )
{
if ( descriptor.value( "noconfig", false ).toBool() )
if ( !descriptor.hasConfig() )
{
// Explicitly set to no-configuration. This doesn't apply
// to custom instances (above) since the only reason to
@ -217,7 +216,7 @@ ModuleManager::loadModules()
ModuleSystem::Descriptor descriptor
= m_availableDescriptorsByModuleName.value( instanceKey.module(), ModuleSystem::Descriptor() );
if ( descriptor.isEmpty() )
if ( !descriptor.isValid() )
{
cError() << "Module" << instanceKey.toString() << "not found in module search paths."
<< Logger::DebugList( m_paths );
@ -258,7 +257,7 @@ ModuleManager::loadModules()
= Calamares::moduleFromDescriptor( descriptor,
instanceKey.id(),
configFileName,
m_moduleDirectoriesByModuleName.value( instanceKey.module() ) );
descriptor.directory() );
if ( !thisModule )
{
cError() << "Module" << instanceKey.toString() << "cannot be created from descriptor"
@ -358,7 +357,7 @@ ModuleManager::checkRequirements()
}
static QStringList
missingRequiredModules( const QStringList& required, const QMap< QString, QVariantMap >& available )
missingRequiredModules( const QStringList& required, const QMap< QString, ModuleSystem::Descriptor >& available )
{
QStringList l;
for ( const QString& depName : required )
@ -386,12 +385,12 @@ ModuleManager::checkDependencies()
for ( auto it = m_availableDescriptorsByModuleName.begin(); it != m_availableDescriptorsByModuleName.end();
++it )
{
QStringList unmet = missingRequiredModules( it->value( "requiredModules" ).toStringList(),
QStringList unmet = missingRequiredModules( it->requiredModules(),
m_availableDescriptorsByModuleName );
if ( unmet.count() > 0 )
{
QString moduleName = it->value( "name" ).toString();
QString moduleName = it->name();
somethingWasRemovedBecauseOfUnmetDependencies = true;
m_availableDescriptorsByModuleName.erase( it );
numberRemoved++;
@ -415,7 +414,7 @@ ModuleManager::checkModuleDependencies( const Module& m )
bool allRequirementsFound = true;
QStringList requiredModules
= m_availableDescriptorsByModuleName[ m.name() ].value( "requiredModules" ).toStringList();
= m_availableDescriptorsByModuleName[ m.name() ].requiredModules();
for ( const QString& required : requiredModules )
{

@ -162,7 +162,6 @@ private:
bool checkModuleDependencies( const Module& );
QMap< QString, ModuleSystem::Descriptor > m_availableDescriptorsByModuleName;
QMap< QString, QString > m_moduleDirectoriesByModuleName;
QMap< ModuleSystem::InstanceKey, Module* > m_loadedModulesByInstanceKey;
const QStringList m_paths;
RequirementsModel* m_requirementsModel;

@ -61,32 +61,14 @@ ProcessJobModule::jobs() const
void
ProcessJobModule::initFrom( const QVariantMap& moduleDescriptor )
ProcessJobModule::initFrom( const ModuleSystem::Descriptor& moduleDescriptor )
{
QDir directory( location() );
m_workingPath = directory.absolutePath();
if ( !moduleDescriptor.value( "command" ).toString().isEmpty() )
{
m_command = moduleDescriptor.value( "command" ).toString();
}
m_secondsTimeout = std::chrono::seconds( 30 );
if ( moduleDescriptor.contains( "timeout" ) && !moduleDescriptor.value( "timeout" ).isNull() )
{
int sec = moduleDescriptor.value( "timeout" ).toInt();
if ( sec < 0 )
{
sec = 0;
}
m_secondsTimeout = std::chrono::seconds( sec );
}
m_runInChroot = false;
if ( moduleDescriptor.contains( "chroot" ) && !moduleDescriptor.value( "chroot" ).isNull() )
{
m_runInChroot = moduleDescriptor.value( "chroot" ).toBool();
}
m_command = moduleDescriptor.command();
m_secondsTimeout = std::chrono::seconds( moduleDescriptor.timeout() );
m_runInChroot = moduleDescriptor.chroot();
}

@ -38,7 +38,7 @@ public:
JobList jobs() const override;
protected:
void initFrom( const QVariantMap& moduleDescriptor ) override;
void initFrom( const ModuleSystem::Descriptor& moduleDescriptor ) override;
private:
explicit ProcessJobModule();

@ -62,15 +62,11 @@ PythonJobModule::jobs() const
void
PythonJobModule::initFrom( const QVariantMap& moduleDescriptor )
PythonJobModule::initFrom( const ModuleSystem::Descriptor& moduleDescriptor )
{
QDir directory( location() );
m_workingPath = directory.absolutePath();
if ( !moduleDescriptor.value( "script" ).toString().isEmpty() )
{
m_scriptFileName = moduleDescriptor.value( "script" ).toString();
}
m_scriptFileName = moduleDescriptor.script();
}

@ -35,7 +35,7 @@ public:
JobList jobs() const override;
protected:
void initFrom( const QVariantMap& moduleDescriptor ) override;
void initFrom( const ModuleSystem::Descriptor& moduleDescriptor ) override;
private:
explicit PythonJobModule();

@ -89,13 +89,12 @@ ViewModule::jobs() const
void
ViewModule::initFrom( const QVariantMap& moduleDescriptor )
ViewModule::initFrom( const ModuleSystem::Descriptor& moduleDescriptor )
{
QDir directory( location() );
QString load;
if ( !moduleDescriptor.value( "load" ).toString().isEmpty() )
QString load = moduleDescriptor.load();
if ( !load.isEmpty() )
{
load = moduleDescriptor.value( "load" ).toString();
load = directory.absoluteFilePath( load );
}
// If a load path is not specified, we look for a plugin to load in the directory.

@ -42,7 +42,7 @@ public:
RequirementsList checkRequirements() override;
protected:
void initFrom( const QVariantMap& moduleDescriptor ) override;
void initFrom( const ModuleSystem::Descriptor& moduleDescriptor ) override;
private:
explicit ViewModule();

Loading…
Cancel
Save