[libcalamares] Refactor module-search path

- Refactor code that fills up the module search path from
   the *modules-search* configuration key.
 - Improve debug logging while here.
main
Adriaan de Groot 7 years ago
parent 540d27d0c3
commit e18e4e3d6f

@ -74,32 +74,15 @@ Settings::instance()
return s_instance; return s_instance;
} }
Settings::Settings( const QString& settingsFilePath, static void
bool debugMode, interpretModulesSearch( const bool debugMode, const QStringList& rawPaths, QStringList& output )
QObject* parent )
: QObject( parent )
, m_debug( debugMode )
, m_doChroot( true )
, m_promptInstall( false )
, m_disableCancel( false )
{ {
cDebug() << "Using Calamares settings file at" << settingsFilePath; for ( const auto& path : rawPaths )
QFile file( settingsFilePath );
if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) )
{ {
QByteArray ba = file.readAll(); if ( path == "local" )
try
{ {
YAML::Node config = YAML::Load( ba.constData() ); cDebug() << "module-search local";
Q_ASSERT( config.IsMap() );
QStringList rawPaths;
config[ "modules-search" ] >> rawPaths;
for ( int i = 0; i < rawPaths.length(); ++i )
{
if ( rawPaths[ i ] == "local" )
{
// If we're running in debug mode, we assume we might also be // If we're running in debug mode, we assume we might also be
// running from the build dir, so we add a maximum priority // running from the build dir, so we add a maximum priority
// module search path in the build dir. // module search path in the build dir.
@ -109,21 +92,49 @@ Settings::Settings( const QString& settingsFilePath,
QDir::separator() + "src" + QDir::separator() + "src" +
QDir::separator() + "modules"; QDir::separator() + "modules";
if ( QDir( buildDirModules ).exists() ) if ( QDir( buildDirModules ).exists() )
m_modulesSearchPaths.append( buildDirModules ); output.append( buildDirModules );
} }
// Install path is set in CalamaresAddPlugin.cmake // Install path is set in CalamaresAddPlugin.cmake
m_modulesSearchPaths.append( CalamaresUtils::systemLibDir().absolutePath() + output.append( CalamaresUtils::systemLibDir().absolutePath() +
QDir::separator() + "calamares" + QDir::separator() + "calamares" +
QDir::separator() + "modules" ); QDir::separator() + "modules" );
} }
else else
{ {
QDir path( rawPaths[ i ] ); QDir d( path );
if ( path.exists() && path.isReadable() ) if ( d.exists() && d.isReadable() )
m_modulesSearchPaths.append( path.absolutePath() ); {
cDebug() << "module-search exists" << d.absolutePath();
output.append( d.absolutePath() );
} }
else
cDebug() << "module-search non-existent" << path;
} }
}
}
Settings::Settings( const QString& settingsFilePath,
bool debugMode,
QObject* parent )
: QObject( parent )
, m_debug( debugMode )
, m_doChroot( true )
, m_promptInstall( false )
, m_disableCancel( false )
{
cDebug() << "Using Calamares settings file at" << settingsFilePath;
QFile file( settingsFilePath );
if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) )
{
QByteArray ba = file.readAll();
try
{
YAML::Node config = YAML::Load( ba.constData() );
Q_ASSERT( config.IsMap() );
interpretModulesSearch( debugMode, CalamaresUtils::yamlToStringList( config[ "modules-search" ] ), m_modulesSearchPaths );
// Parse the custom instances section // Parse the custom instances section
if ( config[ "instances" ] ) if ( config[ "instances" ] )

Loading…
Cancel
Save