[calamares] Refactor Settings initialization
- add a Settings::init() to do actual work - remove the same kind of code from CalamaresApplication - make constructor of Settings private - initialize settings before the application
This commit is contained in:
parent
68e8b0695d
commit
4525060c26
@ -76,7 +76,11 @@ CalamaresApplication::init()
|
|||||||
cDebug() << "Calamares version:" << CALAMARES_VERSION;
|
cDebug() << "Calamares version:" << CALAMARES_VERSION;
|
||||||
cDebug() << " languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).replace( ";", ", " );
|
cDebug() << " languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).replace( ";", ", " );
|
||||||
|
|
||||||
initSettings();
|
if ( !Calamares::Settings::instance() )
|
||||||
|
{
|
||||||
|
cError() << "Must create Calamares::Settings before the application.";
|
||||||
|
::exit( 1 );
|
||||||
|
}
|
||||||
initQmlPath();
|
initQmlPath();
|
||||||
initBranding();
|
initBranding();
|
||||||
|
|
||||||
@ -142,35 +146,6 @@ qmlDirCandidates( bool assumeBuilddir )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static QStringList
|
|
||||||
settingsFileCandidates( bool assumeBuilddir )
|
|
||||||
{
|
|
||||||
static const char settings[] = "settings.conf";
|
|
||||||
|
|
||||||
QStringList settingsPaths;
|
|
||||||
if ( CalamaresUtils::isAppDataDirOverridden() )
|
|
||||||
{
|
|
||||||
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( assumeBuilddir )
|
|
||||||
{
|
|
||||||
settingsPaths << QDir::current().absoluteFilePath( settings );
|
|
||||||
}
|
|
||||||
if ( CalamaresUtils::haveExtraDirs() )
|
|
||||||
for ( auto s : CalamaresUtils::extraConfigDirs() )
|
|
||||||
{
|
|
||||||
settingsPaths << ( s + settings );
|
|
||||||
}
|
|
||||||
settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat
|
|
||||||
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
|
|
||||||
}
|
|
||||||
|
|
||||||
return settingsPaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static QStringList
|
static QStringList
|
||||||
brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename )
|
brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename )
|
||||||
{
|
{
|
||||||
@ -236,49 +211,6 @@ CalamaresApplication::initQmlPath()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
CalamaresApplication::initSettings()
|
|
||||||
{
|
|
||||||
QStringList settingsFileCandidatesByPriority = settingsFileCandidates( isDebug() );
|
|
||||||
|
|
||||||
QFileInfo settingsFile;
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
foreach ( const QString& path, settingsFileCandidatesByPriority )
|
|
||||||
{
|
|
||||||
QFileInfo pathFi( path );
|
|
||||||
if ( pathFi.exists() && pathFi.isReadable() )
|
|
||||||
{
|
|
||||||
settingsFile = pathFi;
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !found || !settingsFile.exists() || !settingsFile.isReadable() )
|
|
||||||
{
|
|
||||||
cError() << "Cowardly refusing to continue startup without settings."
|
|
||||||
<< Logger::DebugList( settingsFileCandidatesByPriority );
|
|
||||||
if ( CalamaresUtils::isAppDataDirOverridden() )
|
|
||||||
{
|
|
||||||
cError() << "FATAL: explicitly configured application data directory is missing settings.conf";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cError() << "FATAL: none of the expected configuration file paths exist.";
|
|
||||||
}
|
|
||||||
::exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* settings = new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this ); // Creates singleton
|
|
||||||
if ( settings->modulesSequence().count() < 1 )
|
|
||||||
{
|
|
||||||
cError() << "FATAL: no sequence set.";
|
|
||||||
::exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CalamaresApplication::initBranding()
|
CalamaresApplication::initBranding()
|
||||||
{
|
{
|
||||||
|
@ -61,7 +61,6 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Initialization steps happen in this order
|
// Initialization steps happen in this order
|
||||||
void initSettings();
|
|
||||||
void initQmlPath();
|
void initQmlPath();
|
||||||
void initBranding();
|
void initBranding();
|
||||||
void initModuleManager();
|
void initModuleManager();
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "CalamaresApplication.h"
|
#include "CalamaresApplication.h"
|
||||||
|
|
||||||
#include "CalamaresConfig.h"
|
#include "Settings.h"
|
||||||
#include "utils/Dirs.h"
|
#include "utils/Dirs.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
@ -83,6 +83,7 @@ handle_args( CalamaresApplication& a )
|
|||||||
CalamaresUtils::setXdgDirs();
|
CalamaresUtils::setXdgDirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Calamares::Settings::init( parser.isSet( debugOption ) );
|
||||||
a.init();
|
a.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ main( int argc, char* argv[] )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) );
|
std::unique_ptr< Calamares::Settings > settings_p( Calamares::Settings::init( QString() ) );
|
||||||
std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) );
|
std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) );
|
||||||
QMainWindow* mw = nullptr;
|
QMainWindow* mw = nullptr;
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#include "CalamaresConfig.h"
|
||||||
#include "utils/Dirs.h"
|
#include "utils/Dirs.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Yaml.h"
|
#include "utils/Yaml.h"
|
||||||
@ -193,8 +194,8 @@ interpretSequence( const YAML::Node& node, Settings::ModuleSequence& moduleSeque
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::Settings( const QString& settingsFilePath, bool debugMode, QObject* parent )
|
Settings::Settings( const QString& settingsFilePath, bool debugMode )
|
||||||
: QObject( parent )
|
: QObject()
|
||||||
, m_debug( debugMode )
|
, m_debug( debugMode )
|
||||||
, m_doChroot( true )
|
, m_doChroot( true )
|
||||||
, m_promptInstall( false )
|
, m_promptInstall( false )
|
||||||
@ -265,4 +266,93 @@ Settings::brandingComponentName() const
|
|||||||
return m_brandingComponentName;
|
return m_brandingComponentName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QStringList
|
||||||
|
settingsFileCandidates( bool assumeBuilddir )
|
||||||
|
{
|
||||||
|
static const char settings[] = "settings.conf";
|
||||||
|
|
||||||
|
QStringList settingsPaths;
|
||||||
|
if ( CalamaresUtils::isAppDataDirOverridden() )
|
||||||
|
{
|
||||||
|
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( assumeBuilddir )
|
||||||
|
{
|
||||||
|
settingsPaths << QDir::current().absoluteFilePath( settings );
|
||||||
|
}
|
||||||
|
if ( CalamaresUtils::haveExtraDirs() )
|
||||||
|
for ( auto s : CalamaresUtils::extraConfigDirs() )
|
||||||
|
{
|
||||||
|
settingsPaths << ( s + settings );
|
||||||
|
}
|
||||||
|
settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat
|
||||||
|
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
|
||||||
|
}
|
||||||
|
|
||||||
|
return settingsPaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings*
|
||||||
|
Settings::init( bool debugMode )
|
||||||
|
{
|
||||||
|
if ( s_instance )
|
||||||
|
{
|
||||||
|
cWarning() << "Calamares::Settings already created";
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList settingsFileCandidatesByPriority = settingsFileCandidates( debugMode );
|
||||||
|
|
||||||
|
QFileInfo settingsFile;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
foreach ( const QString& path, settingsFileCandidatesByPriority )
|
||||||
|
{
|
||||||
|
QFileInfo pathFi( path );
|
||||||
|
if ( pathFi.exists() && pathFi.isReadable() )
|
||||||
|
{
|
||||||
|
settingsFile = pathFi;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !found || !settingsFile.exists() || !settingsFile.isReadable() )
|
||||||
|
{
|
||||||
|
cError() << "Cowardly refusing to continue startup without settings."
|
||||||
|
<< Logger::DebugList( settingsFileCandidatesByPriority );
|
||||||
|
if ( CalamaresUtils::isAppDataDirOverridden() )
|
||||||
|
{
|
||||||
|
cError() << "FATAL: explicitly configured application data directory is missing settings.conf";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cError() << "FATAL: none of the expected configuration file paths exist.";
|
||||||
|
}
|
||||||
|
::exit( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* settings = new Calamares::Settings( settingsFile.absoluteFilePath(), debugMode ); // Creates singleton
|
||||||
|
if ( settings->modulesSequence().count() < 1 )
|
||||||
|
{
|
||||||
|
cError() << "FATAL: no sequence set.";
|
||||||
|
::exit( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings*
|
||||||
|
Settings::init( const QString& path )
|
||||||
|
{
|
||||||
|
if ( s_instance )
|
||||||
|
{
|
||||||
|
cWarning() << "Calamares::Settings already created";
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
return new Calamares::Settings( path, true );
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -35,10 +35,13 @@ namespace Calamares
|
|||||||
class DLLEXPORT Settings : public QObject
|
class DLLEXPORT Settings : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
explicit Settings( const QString& settingsFilePath, bool debugMode );
|
||||||
public:
|
public:
|
||||||
explicit Settings( const QString& settingsFilePath, bool debugMode, QObject* parent = nullptr );
|
|
||||||
|
|
||||||
static Settings* instance();
|
static Settings* instance();
|
||||||
|
/// @brief Find a settings.conf, following @p debugMode
|
||||||
|
static Settings* init( bool debugMode );
|
||||||
|
/// @brief Explicif filename, debug is always true (for testing)
|
||||||
|
static Settings* init( const QString& filename );
|
||||||
|
|
||||||
QStringList modulesSearchPaths() const;
|
QStringList modulesSearchPaths() const;
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ script:
|
|||||||
if ( !Calamares::JobQueue::instance() )
|
if ( !Calamares::JobQueue::instance() )
|
||||||
(void)new Calamares::JobQueue( nullptr );
|
(void)new Calamares::JobQueue( nullptr );
|
||||||
if ( !Calamares::Settings::instance() )
|
if ( !Calamares::Settings::instance() )
|
||||||
(void)new Calamares::Settings( QString(), true );
|
(void)Calamares::Settings::init( QString() );
|
||||||
|
|
||||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
QVERIFY( gs != nullptr );
|
QVERIFY( gs != nullptr );
|
||||||
|
Loading…
Reference in New Issue
Block a user