[libcalamares] Provide convenience functions for warning and error

This commit is contained in:
Adriaan de Groot 2018-02-12 10:20:03 -05:00
parent 79d81700b3
commit df0d9dcb88
4 changed files with 15 additions and 13 deletions

View File

@ -143,7 +143,7 @@ CalamaresApplication::initQmlPath()
.absoluteFilePath( subpath ) ); .absoluteFilePath( subpath ) );
if ( !importPath.exists() || !importPath.isReadable() ) if ( !importPath.exists() || !importPath.isReadable() )
{ {
cLog() << "FATAL ERROR: explicitly configured application data directory" cError() << "FATAL: explicitly configured application data directory"
<< CalamaresUtils::appDataDir().absolutePath() << CalamaresUtils::appDataDir().absolutePath()
<< "does not contain a valid QML modules directory at" << "does not contain a valid QML modules directory at"
<< importPath.absolutePath() << importPath.absolutePath()
@ -176,7 +176,7 @@ CalamaresApplication::initQmlPath()
if ( !importPath.exists() || !importPath.isReadable() ) if ( !importPath.exists() || !importPath.isReadable() )
{ {
cLog() << "FATAL ERROR: none of the expected QML paths (" cError() << "FATAL: none of the expected QML paths ("
<< qmlDirCandidatesByPriority.join( ", " ) << qmlDirCandidatesByPriority.join( ", " )
<< ") exist." << ") exist."
<< "\nCowardly refusing to continue startup without the QML directory."; << "\nCowardly refusing to continue startup without the QML directory.";
@ -197,7 +197,7 @@ CalamaresApplication::initSettings()
settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) ); settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) );
if ( !settingsFile.exists() || !settingsFile.isReadable() ) if ( !settingsFile.exists() || !settingsFile.isReadable() )
{ {
cLog() << "FATAL ERROR: explicitly configured application data directory" cError() << "FATAL: explicitly configured application data directory"
<< CalamaresUtils::appDataDir().absolutePath() << CalamaresUtils::appDataDir().absolutePath()
<< "does not contain a valid settings.conf file." << "does not contain a valid settings.conf file."
<< "\nCowardly refusing to continue startup without settings."; << "\nCowardly refusing to continue startup without settings.";
@ -230,7 +230,7 @@ CalamaresApplication::initSettings()
if ( !settingsFile.exists() || !settingsFile.isReadable() ) if ( !settingsFile.exists() || !settingsFile.isReadable() )
{ {
cLog() << "FATAL ERROR: none of the expected configuration file paths (" cError() << "FATAL: none of the expected configuration file paths ("
<< settingsFileCandidatesByPriority.join( ", " ) << settingsFileCandidatesByPriority.join( ", " )
<< ") contain a valid settings.conf file." << ") contain a valid settings.conf file."
<< "\nCowardly refusing to continue startup without settings."; << "\nCowardly refusing to continue startup without settings.";
@ -248,7 +248,7 @@ CalamaresApplication::initBranding()
QString brandingComponentName = Calamares::Settings::instance()->brandingComponentName(); QString brandingComponentName = Calamares::Settings::instance()->brandingComponentName();
if ( brandingComponentName.simplified().isEmpty() ) if ( brandingComponentName.simplified().isEmpty() )
{ {
cLog() << "FATAL ERROR: branding component not set in settings.conf"; cError() << "FATAL: branding component not set in settings.conf";
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
@ -262,7 +262,7 @@ CalamaresApplication::initBranding()
.absoluteFilePath( brandingDescriptorSubpath ) ); .absoluteFilePath( brandingDescriptorSubpath ) );
if ( !brandingFile.exists() || !brandingFile.isReadable() ) if ( !brandingFile.exists() || !brandingFile.isReadable() )
{ {
cLog() << "FATAL ERROR: explicitly configured application data directory" cError() << "FATAL: explicitly configured application data directory"
<< CalamaresUtils::appDataDir().absolutePath() << CalamaresUtils::appDataDir().absolutePath()
<< "does not contain a valid branding component descriptor at" << "does not contain a valid branding component descriptor at"
<< brandingFile.absoluteFilePath() << brandingFile.absoluteFilePath()
@ -299,7 +299,7 @@ CalamaresApplication::initBranding()
if ( !brandingFile.exists() || !brandingFile.isReadable() ) if ( !brandingFile.exists() || !brandingFile.isReadable() )
{ {
cLog() << "FATAL ERROR: none of the expected branding descriptor file paths (" cError() << "FATAL: none of the expected branding descriptor file paths ("
<< brandingFileCandidatesByPriority.join( ", " ) << brandingFileCandidatesByPriority.join( ", " )
<< ") contain a valid branding.desc file." << ") contain a valid branding.desc file."
<< "\nCowardly refusing to continue startup without branding."; << "\nCowardly refusing to continue startup without branding.";

View File

@ -223,7 +223,7 @@ Helper::Helper( QObject* parent )
} }
else else
{ {
cDebug() << "WARNING: creating PythonHelper more than once. This is very bad."; cWarning() << "creating PythonHelper more than once. This is very bad.";
return; return;
} }

View File

@ -38,7 +38,7 @@ static CommandLine get_variant_object( const QVariantMap& m )
if ( !command.isEmpty() ) if ( !command.isEmpty() )
return CommandLine( command, timeout ); return CommandLine( command, timeout );
cDebug() << "WARNING Bad CommandLine element" << m; cWarning() << "Bad CommandLine element" << m;
return CommandLine(); return CommandLine();
} }
@ -58,7 +58,7 @@ static CommandList_t get_variant_stringlist( const QVariantList& l )
// Otherwise warning is already given // Otherwise warning is already given
} }
else else
cDebug() << "WARNING Bad CommandList element" << c << v.type() << v; cWarning() << "Bad CommandList element" << c << v.type() << v;
++c; ++c;
} }
return retl; return retl;
@ -79,7 +79,7 @@ CommandList::CommandList::CommandList( const QVariant& v, bool doChroot, int tim
if ( v_list.count() ) if ( v_list.count() )
append( get_variant_stringlist( v_list ) ); append( get_variant_stringlist( v_list ) );
else else
cDebug() << "WARNING: Empty CommandList"; cWarning() << "Empty CommandList";
} }
else if ( v.type() == QVariant::String ) else if ( v.type() == QVariant::String )
append( v.toString() ); append( v.toString() );
@ -91,7 +91,7 @@ CommandList::CommandList::CommandList( const QVariant& v, bool doChroot, int tim
// Otherwise warning is already given // Otherwise warning is already given
} }
else else
cDebug() << "WARNING: CommandList does not understand variant" << v.type(); cWarning() << "CommandList does not understand variant" << v.type();
} }
CommandList::~CommandList() CommandList::~CommandList()
@ -109,7 +109,7 @@ Calamares::JobResult CommandList::run()
{ {
if ( !gs || !gs->contains( "rootMountPoint" ) ) if ( !gs || !gs->contains( "rootMountPoint" ) )
{ {
cDebug() << "ERROR: No rootMountPoint defined."; cError() << "No rootMountPoint defined.";
return Calamares::JobResult::error( QCoreApplication::translate( "CommandList", "Could not run command." ), return Calamares::JobResult::error( QCoreApplication::translate( "CommandList", "Could not run command." ),
QCoreApplication::translate( "CommandList", "No rootMountPoint is defined, so command cannot be run in the target environment." ) ); QCoreApplication::translate( "CommandList", "No rootMountPoint is defined, so command cannot be run in the target environment." ) );
} }

View File

@ -65,5 +65,7 @@ namespace Logger
#define cLog Logger::CLog #define cLog Logger::CLog
#define cDebug Logger::CDebug #define cDebug Logger::CDebug
#define cWarning() Logger::CDebug(Logger::LOGWARNING) << "WARNING:"
#define cError() Logger::CDebug(Logger::LOGERROR) << "ERROR:"
#endif // CALAMARES_LOGGER_H #endif // CALAMARES_LOGGER_H