Merge branch 'master' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip Müller 2018-07-17 06:43:49 +02:00
commit 73faaeae2f
3 changed files with 143 additions and 163 deletions

View File

@ -133,39 +133,69 @@ 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;
}
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;
}
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 void
CalamaresApplication::initQmlPath() CalamaresApplication::initQmlPath()
{ {
QDir importPath; QDir importPath; // Right now, current-dir
QStringList qmlDirCandidatesByPriority = qmlDirCandidates( isDebug() );
QString subpath( "qml" ); bool found = false;
if ( CalamaresUtils::isAppDataDirOverridden() )
{
importPath = QDir( CalamaresUtils::appDataDir()
.absoluteFilePath( subpath ) );
if ( !importPath.exists() || !importPath.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 ) foreach ( const QString& path, qmlDirCandidatesByPriority )
{ {
@ -173,20 +203,23 @@ CalamaresApplication::initQmlPath()
if ( dir.exists() && dir.isReadable() ) if ( dir.exists() && dir.isReadable() )
{ {
importPath = dir; importPath = dir;
found = true;
break; break;
} }
} }
if ( !importPath.exists() || !importPath.isReadable() ) if ( !found || !importPath.exists() || !importPath.isReadable() )
{ {
cError() << "FATAL: none of the expected QML paths (" cError() << "Cowardly refusing to continue startup without a QML directory."
<< qmlDirCandidatesByPriority.join( ", " ) << Logger::DebugList( qmlDirCandidatesByPriority );
<< ") exist." if ( CalamaresUtils::isAppDataDirOverridden() )
<< "\nCowardly refusing to continue startup without the QML directory."; cError() << "FATAL: explicitly configured application data directory is missing qml/";
else
cError() << "FATAL: none of the expected QML paths exist.";
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
}
cDebug() << "Using Calamares QML directory" << importPath.absolutePath();
CalamaresUtils::setQmlModulesDir( importPath ); CalamaresUtils::setQmlModulesDir( importPath );
} }
@ -194,32 +227,10 @@ CalamaresApplication::initQmlPath()
void void
CalamaresApplication::initSettings() CalamaresApplication::initSettings()
{ {
QStringList settingsFileCandidatesByPriority = settingsFileCandidates( isDebug() );
QFileInfo settingsFile; QFileInfo settingsFile;
if ( CalamaresUtils::isAppDataDirOverridden() ) bool found = false;
{
settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) );
if ( !settingsFile.exists() || !settingsFile.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 );
}
}
else
{
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 ) foreach ( const QString& path, settingsFileCandidatesByPriority )
{ {
@ -227,19 +238,21 @@ CalamaresApplication::initSettings()
if ( pathFi.exists() && pathFi.isReadable() ) if ( pathFi.exists() && pathFi.isReadable() )
{ {
settingsFile = pathFi; settingsFile = pathFi;
found = true;
break; break;
} }
} }
if ( !settingsFile.exists() || !settingsFile.isReadable() ) if ( !found || !settingsFile.exists() || !settingsFile.isReadable() )
{ {
cError() << "FATAL: none of the expected configuration file paths (" cError() << "Cowardly refusing to continue startup without settings."
<< settingsFileCandidatesByPriority.join( ", " ) << Logger::DebugList( settingsFileCandidatesByPriority );
<< ") contain a valid settings.conf file." if ( CalamaresUtils::isAppDataDirOverridden() )
<< "\nCowardly refusing to continue startup without settings."; 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 ); ::exit( EXIT_FAILURE );
} }
}
new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this ); new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this );
} }
@ -255,40 +268,11 @@ CalamaresApplication::initBranding()
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ) QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ).arg( brandingComponentName );
.arg( brandingComponentName ); QStringList brandingFileCandidatesByPriority = brandingFileCandidates( isDebug(), brandingDescriptorSubpath);
QFileInfo brandingFile; QFileInfo brandingFile;
if ( CalamaresUtils::isAppDataDirOverridden() ) bool found = false;
{
brandingFile = QFileInfo( CalamaresUtils::appDataDir()
.absoluteFilePath( brandingDescriptorSubpath ) );
if ( !brandingFile.exists() || !brandingFile.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 );
}
}
else
{
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 ) foreach ( const QString& path, brandingFileCandidatesByPriority )
{ {
@ -296,19 +280,21 @@ CalamaresApplication::initBranding()
if ( pathFi.exists() && pathFi.isReadable() ) if ( pathFi.exists() && pathFi.isReadable() )
{ {
brandingFile = pathFi; brandingFile = pathFi;
found = true;
break; break;
} }
} }
if ( !brandingFile.exists() || !brandingFile.isReadable() ) if ( !found || !brandingFile.exists() || !brandingFile.isReadable() )
{ {
cError() << "FATAL: none of the expected branding descriptor file paths (" cError() << "Cowardly refusing to continue startup without branding."
<< brandingFileCandidatesByPriority.join( ", " ) << Logger::DebugList( brandingFileCandidatesByPriority );
<< ") contain a valid branding.desc file." if ( CalamaresUtils::isAppDataDirOverridden() )
<< "\nCowardly refusing to continue startup without branding."; 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 ); ::exit( EXIT_FAILURE );
} }
}
new Calamares::Branding( brandingFile.absoluteFilePath(), this ); new Calamares::Branding( brandingFile.absoluteFilePath(), this );
} }

View File

@ -108,7 +108,14 @@ main( int argc, char* argv[] )
returnCode = a.exec(); returnCode = a.exec();
} }
else else
{
auto instancelist = guard.instances();
qDebug() << "Calamares is already running, shutting down."; 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; return returnCode;
} }

View File

@ -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 ) )