Massive refactor of module loading, configuration, startup, management.

main
Teo Mrnjavac 9 years ago
parent c74c67805e
commit fb44fb97b6

@ -86,7 +86,7 @@ CalamaresApplication::init()
setWindowIcon( QIcon( Calamares::Branding::instance()->
imagePath( Calamares::Branding::ProductIcon ) ) );
initPlugins(); //also shows main window
initModuleManager(); //also shows main window
}
@ -133,13 +133,6 @@ CalamaresApplication::mainWindow()
}
void
CalamaresApplication::startPhase( Calamares::Phase phase )
{
m_moduleManager->loadModules( phase );
}
void
CalamaresApplication::initQmlPath()
{
@ -322,62 +315,40 @@ CalamaresApplication::initBranding()
void
CalamaresApplication::initPlugins()
CalamaresApplication::initModuleManager()
{
m_moduleManager = new Calamares::ModuleManager(
Calamares::Settings::instance()->modulesSearchPaths(), this );
connect( m_moduleManager, &Calamares::ModuleManager::initDone,
this, &CalamaresApplication::onPluginsReady );
this, &CalamaresApplication::initView );
m_moduleManager->init();
connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded,
this, [this]( Calamares::Phase phase )
{
if ( phase == Calamares::Prepare )
{
m_mainwindow->show();
ProgressTreeModel* m = new ProgressTreeModel( this );
ProgressTreeView::instance()->setModel( m );
Calamares::ViewManager::instance()->setUpInstallationStep();
}
else if ( phase == Calamares::Install )
{
Calamares::ViewManager* vm = Calamares::ViewManager::instance();
Calamares::JobQueue* queue = Calamares::JobQueue::instance();
for( const QString& name : Calamares::Settings::instance()->modules( Calamares::Install ) )
{
Calamares::Module* module = m_moduleManager->module( name );
queue->enqueue( module->jobs() );
}
connect( queue, &Calamares::JobQueue::failed,
vm, &Calamares::ViewManager::onInstallationFailed );
queue->start();
}
else if ( phase == Calamares::PostInstall )
{
Calamares::ViewManager::instance()->next();
}
});
}
void
CalamaresApplication::onPluginsReady()
CalamaresApplication::initView()
{
initJobQueue();
m_mainwindow = new CalamaresWindow(); //also creates ViewManager
connect( Calamares::ViewManager::instance(), &Calamares::ViewManager::phaseChangeRequested,
this, &CalamaresApplication::startPhase );
startPhase( Calamares::Prepare );
connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded,
this, &CalamaresApplication::initViewSteps );
m_moduleManager->loadModules();
m_mainwindow->move(
this->desktop()->availableGeometry().center() - m_mainwindow->rect().center()
);
this->desktop()->availableGeometry().center() -
m_mainwindow->rect().center() );
}
void
CalamaresApplication::initViewSteps()
{
m_mainwindow->show();
ProgressTreeModel* m = new ProgressTreeModel( this );
ProgressTreeView::instance()->setModel( m );
}

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, Teo Mrnjavac <teo@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
@ -47,16 +47,15 @@ public:
CalamaresWindow* mainWindow();
void startPhase( Calamares::Phase phase );
private slots:
void onPluginsReady();
void initView();
void initViewSteps();
private:
void initQmlPath();
void initSettings();
void initBranding();
void initPlugins();
void initModuleManager();
void initJobQueue();
CalamaresWindow* m_mainwindow;

@ -46,12 +46,6 @@ name: "foo" #the module name. must be unique and same as the parent di
interface: "qtplugin" #can be: qtplugin, python, process, ...
*/
void
operator>>( const YAML::Node& node, Calamares::Module* m )
{
m->m_name = QString::fromStdString( node[ "name" ].as< std::string >() );
}
namespace Calamares
{
@ -59,83 +53,76 @@ Module::~Module()
{}
Module*
Module::fromDescriptorFile( const QString& path )
Module::fromDescriptor( const QVariantMap& moduleDescriptor,
const QString& instanceId,
const QString& configFileName,
const QString& moduleDirectory )
{
Module* m = nullptr;
QFile descriptorFile( path );
if ( descriptorFile.exists() && descriptorFile.open( QFile::ReadOnly | QFile::Text ) )
{
QByteArray ba = descriptorFile.readAll();
cDebug() << "Loading module.desc for" << QFileInfo( descriptorFile ).dir().dirName();
try
{
YAML::Node doc = YAML::Load( ba.constData() );
if ( !doc.IsMap() )
{
cLog() << Q_FUNC_INFO << "bad module descriptor format"
<< path;
return nullptr;
}
if ( !doc[ "type" ] ||
!doc[ "interface" ] )
{
cLog() << Q_FUNC_INFO << "bad module descriptor format"
<< path;
return nullptr;
}
QString typeString = QString::fromStdString( doc[ "type" ].as< std::string >() );
QString intfString = QString::fromStdString( doc[ "interface" ].as< std::string >() );
QString typeString = moduleDescriptor.value( "type" ).toString();
QString intfString = moduleDescriptor.value( "interface" ).toString();
if ( typeString == "view" && intfString == "qtplugin" )
{
m = new ViewModule();
}
else if ( typeString == "job" )
{
if ( intfString == "process" )
{
m = new ProcessJobModule();
}
if ( typeString.isEmpty() ||
intfString.isEmpty() )
{
cLog() << Q_FUNC_INFO << "bad module descriptor format"
<< instanceId;
return nullptr;
}
if ( typeString == "view" && intfString == "qtplugin" )
{
m = new ViewModule();
}
else if ( typeString == "job" )
{
if ( intfString == "process" )
{
m = new ProcessJobModule();
}
#ifdef WITH_PYTHON
else if ( intfString == "python" )
{
m = new PythonJobModule();
}
else if ( intfString == "python" )
{
m = new PythonJobModule();
}
#endif
}
if ( !m )
{
cLog() << Q_FUNC_INFO << "bad module type or interface string"
<< path << typeString << intfString;
return nullptr;
}
}
if ( !m )
{
cLog() << Q_FUNC_INFO << "bad module type or interface string"
<< instanceId << typeString << intfString;
return nullptr;
}
QFileInfo mfi( path );
m->m_directory = mfi.absoluteDir().absolutePath();
QDir moduleDir( moduleDirectory );
if ( moduleDir.exists() && moduleDir.isReadable() )
m->m_directory = moduleDir.absolutePath();
else
{
cLog() << Q_FUNC_INFO << "bad module directory"
<< instanceId;
return nullptr;
}
m->initFrom( doc );
m->loadConfigurationFile();
m->m_instanceId = instanceId;
return m;
}
catch ( YAML::Exception& e )
{
cDebug() << "WARNING: YAML parser error " << e.what();
delete m;
return nullptr;
}
m->initFrom( moduleDescriptor );
try
{
m->loadConfigurationFile( configFileName );
}
return nullptr;
catch ( YAML::Exception& e )
{
cDebug() << "WARNING: YAML parser error " << e.what();
delete m;
return nullptr;
}
return m;
}
void
Module::loadConfigurationFile() //throws YAML::Exception
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
{
QStringList configFilesByPriority;
@ -143,7 +130,7 @@ Module::loadConfigurationFile() //throws YAML::Exception
{
configFilesByPriority.append(
CalamaresUtils::appDataDir().absoluteFilePath(
QString( "modules/%1.conf" ).arg( m_name ) ) );
QString( "modules/%1" ).arg( configFileName ) ) );
}
else
{
@ -151,14 +138,15 @@ Module::loadConfigurationFile() //throws YAML::Exception
{
configFilesByPriority.append(
QDir( QDir::currentPath() ).absoluteFilePath(
QString( "src/modules/%1/%1.conf" ).arg( m_name ) ) );
QString( "src/modules/%1/%2" ).arg( m_name )
.arg( configFileName ) ) );
}
configFilesByPriority.append(
QString( "/etc/calamares/modules/%1.conf" ).arg( m_name ) );
QString( "/etc/calamares/modules/%1" ).arg( configFileName ) );
configFilesByPriority.append(
CalamaresUtils::appDataDir().absoluteFilePath(
QString( "modules/%1.conf" ).arg( m_name ) ) );
QString( "modules/%2" ).arg( configFileName ) ) );
}
foreach ( const QString& path, configFilesByPriority )
@ -192,6 +180,21 @@ Module::name() const
}
QString
Module::instanceId() const
{
return m_instanceId;
}
QString
Module::instanceKey() const
{
return QString( "%1@%2" ).arg( m_name )
.arg( m_instanceId );
}
QStringList
Module::requiredModules() const
{
@ -226,9 +229,9 @@ Module::Module()
void
Module::initFrom( const YAML::Node& node )
Module::initFrom( const QVariantMap& moduleDescriptor )
{
node >> this;
m_name = moduleDescriptor.value( "name" ).toString();
}
} //ns

@ -27,17 +27,12 @@
#include <QVariant>
namespace YAML
{
class Node;
}
namespace Calamares
{
class Module;
}
void operator>>( const YAML::Node& node, Calamares::Module* m );
void operator>>( const QVariantMap& moduleDescriptor, Calamares::Module* m );
namespace Calamares
{
@ -59,11 +54,16 @@ public:
};
virtual ~Module();
static Module* fromDescriptorFile( const QString& path );
static Module* fromDescriptor( const QVariantMap& moduleDescriptor,
const QString& instanceId,
const QString& configFileName,
const QString& moduleDirectory );
virtual QString name() const;
virtual QString name() const final;
virtual QString instanceId() const final;
virtual QString instanceKey() const final;
virtual QStringList requiredModules() const;
virtual QString location() const;
virtual QString location() const final;
virtual Type type() const = 0;
virtual Interface interface() const = 0;
@ -77,17 +77,19 @@ public:
protected:
explicit Module();
virtual void initFrom( const YAML::Node& node );
virtual void initFrom( const QVariantMap& moduleDescriptor );
bool m_loaded;
QVariantMap m_configurationMap;
private:
void loadConfigurationFile(); //throws YAML::Exception
void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception
QString m_name;
QStringList m_requiredModules;
QString m_directory;
QString m_instanceId;
friend void ::operator>>( const YAML::Node& node, Calamares::Module* m );
friend void ::operator>>( const QVariantMap& moduleDescriptor,
Calamares::Module* m );
};
}

@ -18,8 +18,12 @@
#include "ModuleManager.h"
#include "ExecutionViewStep.h"
#include "Module.h"
#include "utils/Logger.h"
#include "utils/YamlUtils.h"
#include "Settings.h"
#include "ViewManager.h"
#include <yaml-cpp/yaml.h>
@ -46,19 +50,14 @@ ModuleManager::instance()
ModuleManager::ModuleManager( const QStringList& paths, QObject* parent )
: QObject( parent )
, m_paths( paths )
, m_lastPhaseLoaded( Phase_NULL )
{
Q_ASSERT( !s_instance );
s_instance = this;
}
ModuleManager::~ModuleManager()
{
foreach ( Module* m, m_availableModules )
{
delete m;
}
}
{}
void
@ -68,70 +67,6 @@ ModuleManager::init()
}
QStringList
ModuleManager::availableModules()
{
return m_availableModules.keys();
}
Module*
ModuleManager::module( const QString& name )
{
return m_availableModules.value( name );
}
Phase
ModuleManager::currentPhase()
{
return m_lastPhaseLoaded;
}
void
ModuleManager::loadModules( Phase phase )
{
//FIXME: When we depend on Qt 5.4 this ugly hack should be replaced with
// QTimer::singleShot.
QTimer* timer = new QTimer();
timer->setSingleShot( true );
connect( timer, &QTimer::timeout,
this, [ this, timer, phase ]()
{
foreach ( const QString& moduleName, Settings::instance()->modules( phase ) )
{
if ( !m_availableModules.contains( moduleName ) ||
!m_availableModules.value( moduleName ) )
{
cDebug() << "Module" << moduleName << "not found in module search paths."
<< "\nCalamares will now quit.";
qApp->exit( 1 );
return;
}
Module* thisModule = m_availableModules.value( moduleName );
if ( thisModule && thisModule->isLoaded() )
{
cDebug() << "Module" << moduleName << "already loaded.";
continue;
}
doLoad( moduleName );
}
emit modulesLoaded( phase );
m_lastPhaseLoaded = phase;
// Loading sequence:
// 1) deps are already fine. check if we have all the modules needed by the roster
// 2) ask ModuleManager to load them from the list provided by Settings
// 3) MM must load them asyncly but one at a time, by calling Module::loadSelf
// 4) Module must have subclasses that reimplement loadSelf for various module types
timer->deleteLater();
});
timer->start( 0 );
}
void
ModuleManager::doInit()
{
@ -154,25 +89,47 @@ ModuleManager::doInit()
bool success = currentDir.cd( subdir );
if ( success )
{
QFileInfo metadataFileInfo( currentDir.absoluteFilePath( MODULE_CONFIG_FILENAME ) );
if ( ! ( metadataFileInfo.exists() && metadataFileInfo.isReadable() ) )
QFileInfo descriptorFileInfo( currentDir.absoluteFilePath( MODULE_CONFIG_FILENAME ) );
if ( ! ( descriptorFileInfo.exists() && descriptorFileInfo.isReadable() ) )
{
cDebug() << Q_FUNC_INFO << "unreadable file: "
<< metadataFileInfo.absoluteFilePath();
<< descriptorFileInfo.absoluteFilePath();
continue;
}
Module* moduleInfo = Module::fromDescriptorFile( metadataFileInfo.absoluteFilePath() );
if ( moduleInfo &&
( moduleInfo->name() == currentDir.dirName() ) &&
( !m_availableModules.contains( moduleInfo->name() ) ) )
QFile descriptorFile( descriptorFileInfo.absoluteFilePath() );
QVariant moduleDescriptor;
if ( descriptorFile.exists() && descriptorFile.open( QFile::ReadOnly | QFile::Text ) )
{
m_availableModules.insert( moduleInfo->name(), moduleInfo );
QByteArray ba = descriptorFile.readAll();
try
{
YAML::Node doc = YAML::Load( ba.constData() );
moduleDescriptor = CalamaresUtils::yamlToVariant( doc );
}
catch ( YAML::Exception& e )
{
cDebug() << "WARNING: YAML parser error " << e.what();
continue;
}
}
else
if ( moduleDescriptor.isValid() &&
!moduleDescriptor.isNull() &&
moduleDescriptor.type() == QVariant::Map )
{
delete moduleInfo;
QVariantMap moduleDescriptorMap = moduleDescriptor.toMap();
if ( moduleDescriptorMap.value( "name" ) == currentDir.dirName() &&
!m_availableDescriptorsByModuleName.contains( moduleDescriptorMap.value( "name" ).toString() ) )
{
m_availableDescriptorsByModuleName.insert( moduleDescriptorMap.value( "name" ).toString(),
moduleDescriptorMap );
m_moduleDirectoriesByModuleName.insert( moduleDescriptorMap.value( "name" ).toString(),
descriptorFileInfo.absoluteDir().absolutePath() );
}
}
}
else
@ -194,19 +151,169 @@ ModuleManager::doInit()
}
QStringList
ModuleManager::loadedInstanceKeys()
{
return m_loadedModulesByInstanceKey.keys();
}
QVariantMap
ModuleManager::moduleDescriptor( const QString& name )
{
return m_availableDescriptorsByModuleName.value( name );
}
Module*
ModuleManager::moduleInstance( const QString& instanceKey )
{
return m_loadedModulesByInstanceKey.value( instanceKey );
}
void
ModuleManager::doLoad( const QString& moduleName )
ModuleManager::loadModules()
{
Module* thisModule = m_availableModules.value( moduleName );
if ( !thisModule )
QTimer::singleShot( 0, this, [ this ]()
{
cDebug() << "Module" << moduleName << "loading IMPOSSIBLE, module does not exist";
return;
}
QList< QMap< QString, QString > > customInstances =
Settings::instance()->customModuleInstances();
for ( const QPair< ModuleAction, QStringList >& modulePhase :
Settings::instance()->modulesSequence() )
{
ModuleAction currentAction = modulePhase.first;
foreach ( const QString& moduleEntry,
modulePhase.second )
{
QStringList moduleEntrySplit = moduleEntry.split( '@' );
QString moduleName;
QString instanceId;
QString configFileName;
if ( moduleEntrySplit.length() < 1 ||
moduleEntrySplit.length() > 2 )
{
cDebug() << "Wrong module entry format for module" << moduleEntry << "."
<< "\nCalamares will now quit.";
qApp->exit( 1 );
return;
}
moduleName = moduleEntrySplit.first();
instanceId = moduleEntrySplit.last();
configFileName = QString( "%1.conf" ).arg( moduleName );
if ( !m_availableDescriptorsByModuleName.contains( moduleName ) ||
m_availableDescriptorsByModuleName.value( moduleName ).isEmpty() )
{
cDebug() << "Module" << moduleName << "not found in module search paths."
<< "\nCalamares will now quit.";
qApp->exit( 1 );
return;
}
auto findCustomInstance =
[ customInstances ]( const QString& moduleName,
const QString& instanceId ) -> int
{
for ( int i = 0; i < customInstances.count(); ++i )
{
auto thisInstance = customInstances[ i ];
if ( thisInstance.value( "module" ) == moduleName &&
thisInstance.value( "id" ) == instanceId )
return i;
}
return -1;
};
if ( moduleName != instanceId ) //means this is a custom instance
{
if ( findCustomInstance( moduleName, instanceId ) > -1 )
{
configFileName = customInstances[ findCustomInstance( moduleName, instanceId ) ].value( "config" );
}
else //ought to be a custom instance, but cannot find instance entry
{
cDebug() << "Custom instance" << moduleEntry << "not found in custom instances section."
<< "\nCalamares will now quit.";
qApp->exit( 1 );
return;
}
}
thisModule->loadSelf();
if ( !thisModule->isLoaded() )
cDebug() << "Module" << moduleName << "loading FAILED";
// So now we can assume that the module entry is at least valid,
// that we have a descriptor on hand (and therefore that the
// module exists), and that the instance is either default or
// defined in the custom instances section.
// We still don't know whether the config file for the entry
// exists and is valid, but that's the only thing that could fail
// from this point on. -- Teo 8/2015
QString instanceKey = QString( "%1@%2" )
.arg( moduleName )
.arg( instanceId );
Module* thisModule =
m_loadedModulesByInstanceKey.value( instanceKey, nullptr );
if ( thisModule && !thisModule->isLoaded() )
{
cDebug() << "Module" << instanceKey << "exists but not loaded."
<< "\nCalamares will now quit.";
qApp->exit( 1 );
return;
}
if ( thisModule && thisModule->isLoaded() )
{
cDebug() << "Module" << instanceKey << "already loaded.";
}
else
{
thisModule =
Module::fromDescriptor( m_availableDescriptorsByModuleName.value( moduleName ),
instanceId,
configFileName,
m_moduleDirectoriesByModuleName.value( moduleName ) );
if ( !thisModule )
{
cDebug() << "Module" << instanceKey << "cannot be created from descriptor.";
Q_ASSERT( thisModule );
continue;
}
// If it's a ViewModule, it also appends the ViewStep to the ViewManager.
thisModule->loadSelf();
m_loadedModulesByInstanceKey.insert( instanceKey, thisModule );
Q_ASSERT( thisModule->isLoaded() );
if ( !thisModule->isLoaded() )
{
cDebug() << "Module" << moduleName << "loading FAILED";
continue;
}
}
// At this point we most certainly have a pointer to a loaded module in
// thisModule. We now need to enqueue jobs info into an EVS.
if ( currentAction == Calamares::Exec )
{
ExecutionViewStep* evs =
qobject_cast< ExecutionViewStep* >(
Calamares::ViewManager::instance()->viewSteps().last() );
if ( !evs ) // If the last step is not an EVS, we must create it.
{
evs = new ExecutionViewStep( ViewManager::instance() );
ViewManager::instance()->addViewStep( evs );
}
else
{
cDebug() << "LAST VS IS EVS!";
}
evs->appendJobModuleInstanceKey( instanceKey );
}
}
}
emit modulesLoaded();
} );
}
@ -218,15 +325,16 @@ ModuleManager::checkDependencies()
bool somethingWasRemovedBecauseOfUnmetDependencies = false;
forever
{
for ( auto it = m_availableModules.begin();
it != m_availableModules.end(); ++it )
for ( auto it = m_availableDescriptorsByModuleName.begin();
it != m_availableDescriptorsByModuleName.end(); ++it )
{
foreach ( QString depName, (*it)->requiredModules() )
foreach ( const QString& depName,
(*it).value( "requiredModules" ).toStringList() )
{
if ( !m_availableModules.contains( depName ) )
if ( !m_availableDescriptorsByModuleName.contains( depName ) )
{
somethingWasRemovedBecauseOfUnmetDependencies = true;
m_availableModules.erase( it );
m_availableDescriptorsByModuleName.erase( it );
break;
}
}

@ -19,12 +19,11 @@
#ifndef MODULELOADER_H
#define MODULELOADER_H
#include "Module.h"
#include "Typedefs.h"
#include <QMap>
#include <QObject>
#include <QStringList>
#include <QVariantMap>
namespace Calamares
{
@ -47,27 +46,27 @@ public:
*/
void init();
QStringList availableModules();
Module* module( const QString& name );
QStringList loadedInstanceKeys();
QVariantMap moduleDescriptor( const QString& name );
Phase currentPhase();
Module* moduleInstance( const QString& instanceKey );
void loadModules( Phase phase );
void loadModules();
signals:
void initDone();
void modulesLoaded( Phase );
void modulesLoaded();
private slots:
void doInit();
private:
void doLoad( const QString& moduleName );
void checkDependencies();
QMap< QString, Module* > m_availableModules;
QMap< QString, QVariantMap > m_availableDescriptorsByModuleName;
QMap< QString, QString > m_moduleDirectoriesByModuleName;
QMap< QString, Module* > m_loadedModulesByInstanceKey;
QStringList m_paths;
Phase m_lastPhaseLoaded;
static ModuleManager* s_instance;
};

@ -22,8 +22,6 @@
#include <QDir>
#include <yaml-cpp/yaml.h>
namespace Calamares {
@ -47,10 +45,10 @@ ProcessJobModule::loadSelf()
if ( m_loaded )
return;
m_job = Calamares::job_ptr( new ProcessJob( m_command,
m_workingPath,
m_runInChroot,
m_secondsTimeout ) );
m_job = job_ptr( new ProcessJob( m_command,
m_workingPath,
m_runInChroot,
m_secondsTimeout ) );
m_loaded = true;
}
@ -63,27 +61,29 @@ ProcessJobModule::jobs() const
void
ProcessJobModule::initFrom( const YAML::Node& node )
ProcessJobModule::initFrom( const QVariantMap& moduleDescriptor )
{
Module::initFrom( node );
Module::initFrom( moduleDescriptor );
QDir directory( location() );
m_workingPath = directory.absolutePath();
if ( node[ "command" ] )
if ( !moduleDescriptor.value( "command" ).toString().isEmpty() )
{
m_command = QString::fromStdString( node[ "command" ].as< std::string >() );
m_command = moduleDescriptor.value( "command" ).toString();
}
m_secondsTimeout = 30;
if ( node[ "timeout" ] )
if ( moduleDescriptor.contains( "timeout" ) &&
!moduleDescriptor.value( "timeout" ).isNull() )
{
m_secondsTimeout = node[ "timeout" ].as< int >();
m_secondsTimeout = moduleDescriptor.value( "timeout" ).toInt();
}
m_runInChroot = false;
if ( node[ "chroot" ] )
if ( moduleDescriptor.contains( "chroot" )&&
!moduleDescriptor.value( "chroot" ).isNull() )
{
m_runInChroot = node[ "chroot" ].as< bool >();
m_runInChroot = moduleDescriptor.value( "chroot" ).toBool();
}
}

@ -35,7 +35,7 @@ public:
QList< job_ptr > jobs() const override;
protected:
void initFrom( const YAML::Node& node ) override;
void initFrom( const QVariantMap& moduleDescriptor ) override;
private:
friend class Module;

@ -20,8 +20,6 @@
#include "PythonJob.h"
#include <yaml-cpp/yaml.h>
#include <QDir>
@ -63,15 +61,15 @@ PythonJobModule::jobs() const
void
PythonJobModule::initFrom( const YAML::Node& node )
PythonJobModule::initFrom( const QVariantMap& moduleDescriptor )
{
Module::initFrom( node );
Module::initFrom( moduleDescriptor );
QDir directory( location() );
m_workingPath = directory.absolutePath();
if ( node[ "script" ] )
if ( !moduleDescriptor.value( "script" ).toString().isEmpty() )
{
m_scriptFileName = QString::fromStdString( node[ "script" ].as< std::string >() );
m_scriptFileName = moduleDescriptor.value( "script" ).toString();
}
}

@ -35,7 +35,7 @@ public:
QList< job_ptr > jobs() const override;
protected:
void initFrom( const YAML::Node& node ) override;
void initFrom( const QVariantMap& moduleDescriptor ) override;
private:
friend class Module;

@ -18,12 +18,11 @@
#include "ViewModule.h"
#include "utils/PluginFactory.h"
#include "utils/Logger.h"
#include "viewpages/ViewStep.h"
#include "ViewManager.h"
#include <yaml-cpp/yaml.h>
#include <QDir>
#include <QPluginLoader>
@ -49,12 +48,25 @@ ViewModule::loadSelf()
{
if ( m_loader )
{
m_viewStep = qobject_cast< ViewStep* >( m_loader->instance() );
PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() );
if ( !pf )
{
cDebug() << Q_FUNC_INFO << m_loader->errorString();
return;
}
m_viewStep = pf->create< Calamares::ViewStep >();
if ( !m_viewStep )
{
cLog() << Q_FUNC_INFO << m_loader->errorString();
cDebug() << Q_FUNC_INFO << m_loader->errorString();
return;
}
cDebug() << "ViewModule loading self for instance" << instanceKey()
<< "\nViewModule at address" << this
<< "\nCalamares::PluginFactory at address" << pf
<< "\nViewStep at address" << m_viewStep;
m_viewStep->setModuleInstanceKey( instanceKey() );
m_viewStep->setConfigurationMap( m_configurationMap );
ViewManager::instance()->addViewStep( m_viewStep );
m_loaded = true;
@ -70,14 +82,14 @@ ViewModule::jobs() const
void
ViewModule::initFrom( const YAML::Node& node )
ViewModule::initFrom( const QVariantMap& moduleDescriptor )
{
Module::initFrom( node );
Module::initFrom( moduleDescriptor );
QDir directory( location() );
QString load;
if ( node[ "load" ] )
if ( !moduleDescriptor.value( "load" ).toString().isEmpty() )
{
load = QString::fromStdString( node[ "load" ].as< std::string >() );
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.

@ -38,7 +38,7 @@ public:
QList< job_ptr > jobs() const override;
protected:
void initFrom( const YAML::Node& node ) override;
void initFrom( const QVariantMap& moduleDescriptor ) override;
private:
friend class Module; //so only the superclass can instantiate

Loading…
Cancel
Save