From f118fd73bce05f6ca38c1185b18b23f4a19458ce Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 28 Jun 2018 06:29:55 -0400 Subject: [PATCH 1/6] [calamares] More info when Cala is already running - If Calamares is already running, print some information about which instances there are so that it is possible to unstick them. --- src/calamares/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index d4bd2743d..9893e6792 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -108,7 +108,14 @@ main( int argc, char* argv[] ) returnCode = a.exec(); } else + { + auto instancelist = guard.instances(); qDebug() << "Calamares is already running, shutting down."; + if ( instancelist.count() > 0 ) + qDebug() << "Other running Calamares instances:"; + for ( const auto& i : instancelist ) + qDebug() << " " << i.isValid() << i.pid() << i.arguments(); + } return returnCode; } From 3329f2ea5574a08241106eb40e9bc4fbcf933b82 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Jun 2018 09:33:56 -0400 Subject: [PATCH 2/6] [calamares] Refactor searching for QML dir - Split collecting the search paths into separate function - Don't fall back on the current directory --- src/calamares/CalamaresApplication.cpp | 85 ++++++++++++-------------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index e41516c60..893e76c9b 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -133,60 +133,55 @@ CalamaresApplication::mainWindow() } +static QStringList +qmlDirCandidates( bool assumeBuilddir ) +{ + static const char QML[] = "qml"; + + QStringList qmlDirs; + if ( CalamaresUtils::isAppDataDirOverridden() ) + qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); + else + { + if ( assumeBuilddir ) + qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir + qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); + } + + return qmlDirs; +} + + void CalamaresApplication::initQmlPath() { - QDir importPath; + QDir importPath; // Right now, current-dir + QStringList qmlDirCandidatesByPriority = qmlDirCandidates( isDebug() ); + bool found = false; - QString subpath( "qml" ); - - if ( CalamaresUtils::isAppDataDirOverridden() ) + foreach ( const QString& path, qmlDirCandidatesByPriority ) { - importPath = QDir( CalamaresUtils::appDataDir() - .absoluteFilePath( subpath ) ); - if ( !importPath.exists() || !importPath.isReadable() ) + QDir dir( path ); + if ( dir.exists() && dir.isReadable() ) { - cError() << "FATAL: explicitly configured application data directory" - << CalamaresUtils::appDataDir().absolutePath() - << "does not contain a valid QML modules directory at" - << importPath.absolutePath() - << "\nCowardly refusing to continue startup without the QML directory."; - ::exit( EXIT_FAILURE ); - } - } - else - { - QStringList qmlDirCandidatesByPriority; - if ( isDebug() ) - { - qmlDirCandidatesByPriority.append( - QDir::current().absoluteFilePath( - QString( "src/%1" ) - .arg( subpath ) ) ); - } - qmlDirCandidatesByPriority.append( CalamaresUtils::appDataDir() - .absoluteFilePath( subpath ) ); - - foreach ( const QString& path, qmlDirCandidatesByPriority ) - { - QDir dir( path ); - if ( dir.exists() && dir.isReadable() ) - { - importPath = dir; - break; - } - } - - if ( !importPath.exists() || !importPath.isReadable() ) - { - cError() << "FATAL: none of the expected QML paths (" - << qmlDirCandidatesByPriority.join( ", " ) - << ") exist." - << "\nCowardly refusing to continue startup without the QML directory."; - ::exit( EXIT_FAILURE ); + importPath = dir; + found = true; + break; } } + if ( !found || !importPath.exists() || !importPath.isReadable() ) + { + cError() << "Cowardly refusing to continue startup without a QML directory." + << Logger::DebugList( qmlDirCandidatesByPriority ); + if ( CalamaresUtils::isAppDataDirOverridden() ) + cError() << "FATAL: explicitly configured application data directory is missing qml/"; + else + cError() << "FATAL: none of the expected QML paths exist."; + ::exit( EXIT_FAILURE ); + } + + cDebug() << "Using Calamares QML directory" << importPath.absolutePath(); CalamaresUtils::setQmlModulesDir( importPath ); } From 22ee24a5ad8a39cdefab205ec3053eb42e147cb7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Jun 2018 10:15:43 -0400 Subject: [PATCH 3/6] [calamares] Refactor searching for settings.conf - Split the collection of paths off from the search itself. --- src/calamares/CalamaresApplication.cpp | 78 +++++++++++++------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 893e76c9b..29e04cb67 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -152,6 +152,26 @@ 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 ); + settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat + settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); + } + + return settingsPaths; +} + + void CalamaresApplication::initQmlPath() { @@ -189,51 +209,31 @@ CalamaresApplication::initQmlPath() void CalamaresApplication::initSettings() { + QStringList settingsFileCandidatesByPriority = settingsFileCandidates( isDebug() ); + QFileInfo settingsFile; - if ( CalamaresUtils::isAppDataDirOverridden() ) + bool found = false; + + foreach ( const QString& path, settingsFileCandidatesByPriority ) { - settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) ); - if ( !settingsFile.exists() || !settingsFile.isReadable() ) + QFileInfo pathFi( path ); + if ( pathFi.exists() && pathFi.isReadable() ) { - cError() << "FATAL: explicitly configured application data directory" - << CalamaresUtils::appDataDir().absolutePath() - << "does not contain a valid settings.conf file." - << "\nCowardly refusing to continue startup without settings."; - ::exit( EXIT_FAILURE ); + settingsFile = pathFi; + found = true; + break; } } - else + + if ( !found || !settingsFile.exists() || !settingsFile.isReadable() ) { - QStringList settingsFileCandidatesByPriority; - if ( isDebug() ) - { - settingsFileCandidatesByPriority.append( - QDir::currentPath() + - QDir::separator() + - "settings.conf" ); - } - settingsFileCandidatesByPriority.append( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf" ); - settingsFileCandidatesByPriority.append( CalamaresUtils::appDataDir() - .absoluteFilePath( "settings.conf" ) ); - - foreach ( const QString& path, settingsFileCandidatesByPriority ) - { - QFileInfo pathFi( path ); - if ( pathFi.exists() && pathFi.isReadable() ) - { - settingsFile = pathFi; - break; - } - } - - if ( !settingsFile.exists() || !settingsFile.isReadable() ) - { - cError() << "FATAL: none of the expected configuration file paths (" - << settingsFileCandidatesByPriority.join( ", " ) - << ") contain a valid settings.conf file." - << "\nCowardly refusing to continue startup without settings."; - ::exit( EXIT_FAILURE ); - } + 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 ); } new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this ); From b0e55c059a3bd1de32dfc83821b2cb9bb0dab820 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 29 Jun 2018 10:52:12 -0400 Subject: [PATCH 4/6] [calamares] Refactor searching for branding descriptor --- src/calamares/CalamaresApplication.cpp | 86 ++++++++++++-------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 29e04cb67..ef6c37912 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -172,6 +172,27 @@ settingsFileCandidates( bool assumeBuilddir ) } +static QStringList +brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename ) +{ + QStringList brandingPaths; + if ( CalamaresUtils::isAppDataDirOverridden() ) + brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename ); + else + { + if ( assumeBuilddir ) + { + brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename ); + brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ) + .absoluteFilePath( brandingFilename ); + brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename); + } + } + + return brandingPaths; +} + + void CalamaresApplication::initQmlPath() { @@ -250,59 +271,32 @@ CalamaresApplication::initBranding() ::exit( EXIT_FAILURE ); } - QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ) - .arg( brandingComponentName ); + QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ).arg( brandingComponentName ); + QStringList brandingFileCandidatesByPriority = brandingFileCandidates( isDebug(), brandingDescriptorSubpath); QFileInfo brandingFile; - if ( CalamaresUtils::isAppDataDirOverridden() ) + bool found = false; + + foreach ( const QString& path, brandingFileCandidatesByPriority ) { - brandingFile = QFileInfo( CalamaresUtils::appDataDir() - .absoluteFilePath( brandingDescriptorSubpath ) ); - if ( !brandingFile.exists() || !brandingFile.isReadable() ) + QFileInfo pathFi( path ); + if ( pathFi.exists() && pathFi.isReadable() ) { - cError() << "FATAL: explicitly configured application data directory" - << CalamaresUtils::appDataDir().absolutePath() - << "does not contain a valid branding component descriptor at" - << brandingFile.absoluteFilePath() - << "\nCowardly refusing to continue startup without branding."; - ::exit( EXIT_FAILURE ); + brandingFile = pathFi; + found = true; + break; } } - else + + if ( !found || !brandingFile.exists() || !brandingFile.isReadable() ) { - QStringList brandingFileCandidatesByPriority; - if ( isDebug() ) - { - brandingFileCandidatesByPriority.append( - QDir::currentPath() + - QDir::separator() + - "src" + - QDir::separator() + - brandingDescriptorSubpath ); - } - brandingFileCandidatesByPriority.append( QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ) - .absoluteFilePath( brandingDescriptorSubpath ) ); - brandingFileCandidatesByPriority.append( CalamaresUtils::appDataDir() - .absoluteFilePath( brandingDescriptorSubpath ) ); - - foreach ( const QString& path, brandingFileCandidatesByPriority ) - { - QFileInfo pathFi( path ); - if ( pathFi.exists() && pathFi.isReadable() ) - { - brandingFile = pathFi; - break; - } - } - - if ( !brandingFile.exists() || !brandingFile.isReadable() ) - { - cError() << "FATAL: none of the expected branding descriptor file paths (" - << brandingFileCandidatesByPriority.join( ", " ) - << ") contain a valid branding.desc file." - << "\nCowardly refusing to continue startup without branding."; - ::exit( EXIT_FAILURE ); - } + cError() << "Cowardly refusing to continue startup without branding." + << Logger::DebugList( brandingFileCandidatesByPriority ); + if ( CalamaresUtils::isAppDataDirOverridden() ) + cError() << "FATAL: explicitly configured application data directory is missing" << brandingComponentName; + else + cError() << "FATAL: none of the expected branding descriptor file paths exist."; + ::exit( EXIT_FAILURE ); } new Calamares::Branding( brandingFile.absoluteFilePath(), this ); From f899bda81d151155376ed3b4b257d85500957aff Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 5 Jul 2018 12:01:44 +0200 Subject: [PATCH 5/6] [calamares] Restore missing search paths - Misplaced {} makes the branding search path empty - Reported by @apachelogger --- src/calamares/CalamaresApplication.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index ef6c37912..018e2b677 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -181,12 +181,9 @@ brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename ) else { if ( assumeBuilddir ) - { brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename ); - brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ) - .absoluteFilePath( brandingFilename ); - brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename); - } + brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ).absoluteFilePath( brandingFilename ); + brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename); } return brandingPaths; From ae7700f2d735c99200bbbb5402e306576f02896c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Jul 2018 04:12:24 -0400 Subject: [PATCH 6/6] [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. --- src/libcalamaresui/modulesystem/Module.cpp | 53 ++++++++-------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index ed1cb33ea..8d92c37ad 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -44,14 +44,6 @@ #include -// 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, } +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 Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception { - QStringList configFilesByPriority; - - 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 ) + foreach ( const QString& path, moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName ) ) { QFile configFile( path ); if ( configFile.exists() && configFile.open( QFile::ReadOnly | QFile::Text ) )