Make it possible to override the config dir from the command line

This commit is contained in:
Aurélien Gâteau 2014-07-28 18:11:24 +02:00
parent cb53cc41cb
commit 289704ab90
3 changed files with 29 additions and 4 deletions

View File

@ -20,10 +20,12 @@
#include "CalamaresApplication.h" #include "CalamaresApplication.h"
#include "kdsingleapplicationguard/kdsingleapplicationguard.h" #include "kdsingleapplicationguard/kdsingleapplicationguard.h"
#include "utils/CalamaresUtils.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QDebug> #include <QDebug>
#include <QDir>
int int
main( int argc, char *argv[] ) main( int argc, char *argv[] )
@ -38,10 +40,17 @@ main( int argc, char *argv[] )
"Verbose output for debugging purposes." ); "Verbose output for debugging purposes." );
parser.addOption( debugOption ); parser.addOption( debugOption );
QCommandLineOption configOption( QStringList() << "c" << "config",
"Configuration dir to use, for testing purposes.", "config" );
parser.addOption( configOption );
parser.process( a ); parser.process( a );
a.setDebug( parser.isSet( debugOption ) ); a.setDebug( parser.isSet( debugOption ) );
if ( parser.isSet( configOption ) )
CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) );
KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances );
int returnCode = 0; int returnCode = 0;

View File

@ -34,14 +34,26 @@
namespace CalamaresUtils namespace CalamaresUtils
{ {
static QDir s_appDataDir;
void
setAppDataDir( const QDir& dir )
{
s_appDataDir = dir;
}
QDir QDir
appDataDir() appDataDir()
{ {
QDir path( CMAKE_INSTALL_FULL_DATADIR ); if ( s_appDataDir.path().isEmpty() )
if ( !path.exists() || !path.isReadable() ) {
path.mkpath( path.absolutePath() ); s_appDataDir = QDir( CMAKE_INSTALL_FULL_DATADIR );
if ( !s_appDataDir.exists() || !s_appDataDir.isReadable() )
s_appDataDir.mkpath( s_appDataDir.absolutePath() );
}
return path; return s_appDataDir;
} }

View File

@ -36,6 +36,10 @@ namespace CalamaresUtils
DLLEXPORT QDir systemLibDir(); DLLEXPORT QDir systemLibDir();
DLLEXPORT void installTranslator( QObject* parent ); DLLEXPORT void installTranslator( QObject* parent );
/**
* Override app data dir. Only for testing purposes.
*/
DLLEXPORT void setAppDataDir( const QDir& dir );
} }
#endif // CALAMARESUTILS_H #endif // CALAMARESUTILS_H