mirror of
https://github.com/parchlinux/calamares.git
synced 2025-07-03 12:25:38 -04:00
[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.
This commit is contained in:
parent
f899bda81d
commit
ae7700f2d7
1 changed files with 20 additions and 33 deletions
|
@ -44,14 +44,6 @@
|
||||||
#include <QString>
|
#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";
|
static const char EMERGENCY[] = "emergency";
|
||||||
|
|
||||||
namespace Calamares
|
namespace Calamares
|
||||||
|
@ -144,34 +136,29 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static QStringList
|
||||||
|
moduleConfigurationCandidates( bool assumeBuildDir, const QString& moduleName, const QString& configFileName )
|
||||||
|
{
|
||||||
|
QStringList paths;
|
||||||
|
|
||||||
|
if ( CalamaresUtils::isAppDataDirOverridden() )
|
||||||
|
paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( assumeBuildDir )
|
||||||
|
paths << QDir().absoluteFilePath(QString( "src/modules/%1/%2" ).arg( moduleName ).arg( configFileName ) );
|
||||||
|
|
||||||
|
paths << QString( "/etc/calamares/modules/%1" ).arg( configFileName );
|
||||||
|
paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
|
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
|
||||||
{
|
{
|
||||||
QStringList configFilesByPriority;
|
foreach ( const QString& path, moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName ) )
|
||||||
|
|
||||||
if ( CalamaresUtils::isAppDataDirOverridden() )
|
|
||||||
{
|
|
||||||
configFilesByPriority.append(
|
|
||||||
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 ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
configFilesByPriority.append(
|
|
||||||
QString( "/etc/calamares/modules/%1" ).arg( configFileName ) );
|
|
||||||
configFilesByPriority.append(
|
|
||||||
CalamaresUtils::appDataDir().absoluteFilePath(
|
|
||||||
QString( "modules/%2" ).arg( configFileName ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( const QString& path, configFilesByPriority )
|
|
||||||
{
|
{
|
||||||
QFile configFile( path );
|
QFile configFile( path );
|
||||||
if ( configFile.exists() && configFile.open( QFile::ReadOnly | QFile::Text ) )
|
if ( configFile.exists() && configFile.open( QFile::ReadOnly | QFile::Text ) )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue