[calamares] Load and execute the modules
This runs dummyprocess, at least, but the other three dummies coredump.
This commit is contained in:
parent
308f508c7e
commit
48771f968a
@ -27,6 +27,7 @@
|
|||||||
#include "modulesystem/Module.h"
|
#include "modulesystem/Module.h"
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "Job.h"
|
||||||
|
|
||||||
#include <QCommandLineOption>
|
#include <QCommandLineOption>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
@ -35,7 +36,16 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
static QString
|
struct ModuleConfig : public QPair< QString, QString >
|
||||||
|
{
|
||||||
|
ModuleConfig( const QString& a, const QString& b ) : QPair< QString, QString >(a, b) { }
|
||||||
|
ModuleConfig() : QPair< QString, QString >( QString(), QString() ) { }
|
||||||
|
|
||||||
|
QString moduleName() const { return first; }
|
||||||
|
QString configFile() const { return second; }
|
||||||
|
} ;
|
||||||
|
|
||||||
|
static ModuleConfig
|
||||||
handle_args( QCoreApplication& a )
|
handle_args( QCoreApplication& a )
|
||||||
{
|
{
|
||||||
QCommandLineOption debugLevelOption( QStringLiteral("D"),
|
QCommandLineOption debugLevelOption( QStringLiteral("D"),
|
||||||
@ -68,22 +78,23 @@ handle_args( QCoreApplication& a )
|
|||||||
{
|
{
|
||||||
cError() << "Missing <module> path.\n";
|
cError() << "Missing <module> path.\n";
|
||||||
parser.showHelp();
|
parser.showHelp();
|
||||||
return QString(); // NOTREACHED
|
return ModuleConfig(); // NOTREACHED
|
||||||
}
|
}
|
||||||
if ( args.size() > 1 )
|
if ( args.size() > 2 )
|
||||||
{
|
{
|
||||||
cError() << "More than one <module> path.\n";
|
cError() << "More than one <module> path.\n";
|
||||||
parser.showHelp();
|
parser.showHelp();
|
||||||
return QString(); // NOTREACHED
|
return ModuleConfig(); // NOTREACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
return args.first();
|
return ModuleConfig( args.first(), args.size() == 2 ? args.at(1) : QString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Calamares::Module*
|
static Calamares::Module*
|
||||||
load_module( const QString& moduleName )
|
load_module( const ModuleConfig& moduleConfig )
|
||||||
{
|
{
|
||||||
|
QString moduleName = moduleConfig.moduleName();
|
||||||
QFileInfo fi;
|
QFileInfo fi;
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
@ -123,7 +134,10 @@ load_module( const QString& moduleName )
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString moduleDirectory = fi.absolutePath();
|
QString moduleDirectory = fi.absolutePath();
|
||||||
QString configFile = moduleDirectory + '/' + name + ".conf";
|
QString configFile(
|
||||||
|
moduleConfig.configFile().isEmpty()
|
||||||
|
? moduleDirectory + '/' + name + ".conf"
|
||||||
|
: moduleConfig.configFile() );
|
||||||
|
|
||||||
Calamares::Module* module = Calamares::Module::fromDescriptor(
|
Calamares::Module* module = Calamares::Module::fromDescriptor(
|
||||||
descriptor, name, configFile, moduleDirectory );
|
descriptor, name, configFile, moduleDirectory );
|
||||||
@ -136,18 +150,40 @@ main( int argc, char* argv[] )
|
|||||||
{
|
{
|
||||||
QCoreApplication a( argc, argv );
|
QCoreApplication a( argc, argv );
|
||||||
|
|
||||||
QString module = handle_args( a );
|
ModuleConfig module = handle_args( a );
|
||||||
if ( module.isEmpty() )
|
if ( module.moduleName().isEmpty() )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) );
|
std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) );
|
||||||
cDebug() << "Calamares test module-loader" << module;
|
cDebug() << "Calamares test module-loader" << module.moduleName();
|
||||||
Calamares::Module* m = load_module( module );
|
Calamares::Module* m = load_module( module );
|
||||||
if ( !m )
|
if ( !m )
|
||||||
{
|
{
|
||||||
cError() << "No module.desc data found in" << module;
|
cError() << "No module.desc data found in" << module.moduleName();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !m->isLoaded() )
|
||||||
|
m->loadSelf();
|
||||||
|
|
||||||
|
if ( !m->isLoaded() )
|
||||||
|
{
|
||||||
|
cError() << "Module" << module.moduleName() << "could not be loaded.";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cDebug() << "Module" << m->name() << m->typeString() << m->interfaceString();
|
||||||
|
|
||||||
|
Calamares::JobList jobList = m->jobs();
|
||||||
|
unsigned int count = 1;
|
||||||
|
for ( const auto& p : jobList )
|
||||||
|
{
|
||||||
|
cDebug() << count << p->prettyName();
|
||||||
|
Calamares::JobResult r = p->exec();
|
||||||
|
if ( !r )
|
||||||
|
cDebug() << count << ".. failed" << r;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user