[libcalamares] Refactor searching for module configurations

- Similar to the refactorings in Calamares proper, just split out
   collecting the search paths into a static function. This makes
   it a little easier to find places that will need expansion for
   more-than-one-config-directory.
main
Adriaan de Groot 7 years ago
parent f899bda81d
commit ae7700f2d7

@ -44,14 +44,6 @@
#include <QString>
// Example module.desc
/*
---
type: "view" #job or view
name: "foo" #the module name. must be unique and same as the parent directory
interface: "qtplugin" #can be: qtplugin, python, process, ...
*/
static const char EMERGENCY[] = "emergency";
namespace Calamares
@ -144,34 +136,29 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
}
void
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
static QStringList
moduleConfigurationCandidates( bool assumeBuildDir, const QString& moduleName, const QString& configFileName )
{
QStringList configFilesByPriority;
QStringList paths;
if ( CalamaresUtils::isAppDataDirOverridden() )
{
configFilesByPriority.append(
CalamaresUtils::appDataDir().absoluteFilePath(
QString( "modules/%1" ).arg( configFileName ) ) );
}
paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) );
else
{
if ( Settings::instance()->debugMode() )
{
configFilesByPriority.append(
QDir( QDir::currentPath() ).absoluteFilePath(
QString( "src/modules/%1/%2" ).arg( m_name ).arg( configFileName ) ) );
}
if ( assumeBuildDir )
paths << QDir().absoluteFilePath(QString( "src/modules/%1/%2" ).arg( moduleName ).arg( configFileName ) );
configFilesByPriority.append(
QString( "/etc/calamares/modules/%1" ).arg( configFileName ) );
configFilesByPriority.append(
CalamaresUtils::appDataDir().absoluteFilePath(
QString( "modules/%2" ).arg( configFileName ) ) );
paths << QString( "/etc/calamares/modules/%1" ).arg( configFileName );
paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) );
}
foreach ( const QString& path, configFilesByPriority )
return paths;
}
void
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
{
foreach ( const QString& path, moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName ) )
{
QFile configFile( path );
if ( configFile.exists() && configFile.open( QFile::ReadOnly | QFile::Text ) )

Loading…
Cancel
Save