[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;
}
Settings::Settings( const QString& settingsFilePath,
bool debugMode,
QObject* parent )
: QObject( parent )
, m_debug( debugMode )
, m_doChroot( true )
, m_promptInstall( false )
, m_disableCancel( false )
static void
interpretModulesSearch( const bool debugMode, const QStringList& rawPaths, QStringList& output )
{
cDebug() << "Using Calamares settings file at" << settingsFilePath;
QFile file( settingsFilePath );
if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) )
for ( const auto& path : rawPaths )
{
QByteArray ba = file.readAll();
try
if ( path == "local" )
{
YAML::Node config = YAML::Load( ba.constData() );
Q_ASSERT( config.IsMap() );
cDebug() << "module-search local";
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
// running from the build dir, so we add a maximum priority
// module search path in the build dir.
@ -109,21 +92,49 @@ Settings::Settings( const QString& settingsFilePath,
QDir::separator() + "src" +
QDir::separator() + "modules";
if ( QDir( buildDirModules ).exists() )
m_modulesSearchPaths.append( buildDirModules );
output.append( buildDirModules );
}
// Install path is set in CalamaresAddPlugin.cmake
m_modulesSearchPaths.append( CalamaresUtils::systemLibDir().absolutePath() +
output.append( CalamaresUtils::systemLibDir().absolutePath() +
QDir::separator() + "calamares" +
QDir::separator() + "modules" );
}
else
{
QDir path( rawPaths[ i ] );
if ( path.exists() && path.isReadable() )
m_modulesSearchPaths.append( path.absolutePath() );
QDir d( path );
if ( d.exists() && d.isReadable() )
{
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
if ( config[ "instances" ] )

Loading…
Cancel
Save