CI: apply coding style to libcalamaresui/modulesystem

main
Adriaan de Groot 6 years ago
parent bd8c3fd893
commit 0bd2bfa708

@ -19,9 +19,9 @@
#include "CppJobModule.h"
#include "utils/PluginFactory.h"
#include "utils/Logger.h"
#include "CppJob.h"
#include "utils/Logger.h"
#include "utils/PluginFactory.h"
#include <QDir>
#include <QPluginLoader>
@ -62,10 +62,10 @@ CppJobModule::loadSelf()
cDebug() << Q_FUNC_INFO << m_loader->errorString();
return;
}
// cDebug() << "CppJobModule loading self for instance" << instanceKey()
// << "\nCppJobModule at address" << this
// << "\nCalamares::PluginFactory at address" << pf
// << "\nCppJob at address" << cppJob;
// cDebug() << "CppJobModule loading self for instance" << instanceKey()
// << "\nCppJobModule at address" << this
// << "\nCalamares::PluginFactory at address" << pf
// << "\nCppJob at address" << cppJob;
cppJob->setModuleInstanceKey( instanceKey() );
cppJob->setConfigurationMap( m_configurationMap );
@ -97,7 +97,7 @@ CppJobModule::initFrom( const QVariantMap& moduleDescriptor )
// If a load path is not specified, we look for a plugin to load in the directory.
if ( load.isEmpty() || !QLibrary::isLibrary( load ) )
{
const QStringList ls = directory.entryList( QStringList{ "*.so" } );
const QStringList ls = directory.entryList( QStringList { "*.so" } );
if ( !ls.isEmpty() )
{
for ( QString entry : ls )
@ -126,4 +126,4 @@ CppJobModule::~CppJobModule()
delete m_loader;
}
} // namespace Calamares
} // namespace Calamares

@ -21,8 +21,8 @@
#ifndef CALAMARES_CPPJOBMODULE_H
#define CALAMARES_CPPJOBMODULE_H
#include "UiDllMacro.h"
#include "Module.h"
#include "UiDllMacro.h"
class QPluginLoader;
@ -42,7 +42,7 @@ protected:
void initFrom( const QVariantMap& moduleDescriptor ) override;
private:
friend class Module; //so only the superclass can instantiate
friend class Module; //so only the superclass can instantiate
explicit CppJobModule();
virtual ~CppJobModule() override;
@ -50,6 +50,6 @@ private:
job_ptr m_job;
};
} // namespace Calamares
} // namespace Calamares
#endif // CALAMARES_CPPJOBMODULE_H
#endif // CALAMARES_CPPJOBMODULE_H

@ -48,8 +48,7 @@ static const char EMERGENCY[] = "emergency";
namespace Calamares
{
Module::~Module()
{}
Module::~Module() {}
Module*
Module::fromDescriptor( const QVariantMap& moduleDescriptor,
@ -57,7 +56,7 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
const QString& configFileName,
const QString& moduleDirectory )
{
std::unique_ptr<Module> m;
std::unique_ptr< Module > m;
QString typeString = moduleDescriptor.value( "type" ).toString();
QString intfString = moduleDescriptor.value( "interface" ).toString();
@ -70,7 +69,9 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
if ( ( typeString == "view" ) || ( typeString == "viewmodule" ) )
{
if ( intfString == "qtplugin" )
{
m.reset( new ViewModule() );
}
else if ( intfString == "pythonqt" )
{
#ifdef WITH_PYTHONQT
@ -80,14 +81,20 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
#endif
}
else
{
cError() << "Bad interface" << intfString << "for module type" << typeString;
}
}
else if ( typeString == "job" )
{
if ( intfString == "qtplugin" )
{
m.reset( new CppJobModule() );
}
else if ( intfString == "process" )
{
m.reset( new ProcessJobModule() );
}
else if ( intfString == "python" )
{
#ifdef WITH_PYTHON
@ -97,22 +104,27 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
#endif
}
else
{
cError() << "Bad interface" << intfString << "for module type" << typeString;
}
}
else
{
cError() << "Bad module type" << typeString;
}
if ( !m )
{
cError() << "Bad module type (" << typeString
<< ") or interface string (" << intfString
<< ") for module " << instanceId;
cError() << "Bad module type (" << typeString << ") or interface string (" << intfString << ") for module "
<< instanceId;
return nullptr;
}
QDir moduleDir( moduleDirectory );
if ( moduleDir.exists() && moduleDir.isReadable() )
{
m->m_directory = moduleDir.absolutePath();
}
else
{
cError() << "Bad module directory" << moduleDirectory << "for" << instanceId;
@ -141,22 +153,32 @@ moduleConfigurationCandidates( bool assumeBuildDir, const QString& moduleName, c
QStringList paths;
if ( CalamaresUtils::isAppDataDirOverridden() )
{
paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) );
}
else
{
// If an absolute path is given, in debug mode, look for it
// first. The case contains('/'), below, will add the absolute
// path a second time, though.
if ( assumeBuildDir && configFileName.startsWith( '/' ) )
{
paths << configFileName;
}
if ( assumeBuildDir )
paths << QDir().absoluteFilePath(QString( "src/modules/%1/%2" ).arg( moduleName ).arg( configFileName ) );
{
paths << QDir().absoluteFilePath( QString( "src/modules/%1/%2" ).arg( moduleName ).arg( configFileName ) );
}
if ( assumeBuildDir && configFileName.contains( '/' ) )
{
paths << QDir().absoluteFilePath( configFileName );
}
if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraConfigDirs() )
{
paths << ( s + QString( "modules/%1" ).arg( configFileName ) );
}
paths << QString( "/etc/calamares/modules/%1" ).arg( configFileName );
paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) );
@ -165,10 +187,10 @@ moduleConfigurationCandidates( bool assumeBuildDir, const QString& moduleName, c
return paths;
}
void
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
void Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
{
QStringList configCandidates = moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName );
QStringList configCandidates
= moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName );
for ( const QString& path : configCandidates )
{
QFile configFile( path );
@ -192,9 +214,8 @@ Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Ex
cDebug() << "Loaded module configuration" << path;
m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ).toMap();
m_emergency = m_maybe_emergency
&& m_configurationMap.contains( EMERGENCY )
&& m_configurationMap[ EMERGENCY ].toBool();
m_emergency = m_maybe_emergency && m_configurationMap.contains( EMERGENCY )
&& m_configurationMap[ EMERGENCY ].toBool();
return;
}
}
@ -235,7 +256,7 @@ Module::typeString() const
{
switch ( type() )
{
case Type::Job:
case Type::Job:
return "Job Module";
case Type::View:
return "View Module";
@ -249,7 +270,7 @@ Module::interfaceString() const
{
switch ( interface() )
{
case Interface::Process:
case Interface::Process:
return "External process";
case Interface::Python:
return "Python (Boost.Python)";
@ -271,7 +292,8 @@ Module::configurationMap()
Module::Module()
: m_loaded( false )
{}
{
}
void
@ -279,7 +301,9 @@ Module::initFrom( const QVariantMap& moduleDescriptor )
{
m_name = moduleDescriptor.value( "name" ).toString();
if ( moduleDescriptor.contains( EMERGENCY ) )
{
m_maybe_emergency = moduleDescriptor[ EMERGENCY ].toBool();
}
}
RequirementsList
@ -288,4 +312,4 @@ Module::checkRequirements()
return RequirementsList();
}
} //ns
} // namespace Calamares

@ -66,8 +66,8 @@ public:
*/
enum class Interface
{
QtPlugin, // Jobs or Views
Python, // Jobs only
QtPlugin, // Jobs or Views
Python, // Jobs only
Process, // Deprecated interface
PythonQt // Views only, available as enum even if PythonQt isn't used
};
@ -141,10 +141,7 @@ public:
* @brief isLoaded reports on the loaded status of a module.
* @return true if the module's loading phase has finished, otherwise false.
*/
bool isLoaded() const
{
return m_loaded;
}
bool isLoaded() const { return m_loaded; }
/**
* @brief loadSelf initialized the module.
@ -161,10 +158,7 @@ public:
* are not run (in the common case where there is only
* one exec block, this doesn't really matter).
*/
bool isEmergency() const
{
return m_emergency;
}
bool isEmergency() const { return m_emergency; }
/**
* @brief jobs returns any jobs exposed by this module.
@ -194,16 +188,15 @@ protected:
bool m_maybe_emergency = false; // Based on the module.desc
private:
void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception
void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception
QString m_name;
QString m_directory;
QString m_instanceId;
friend void ::operator>>( const QVariantMap& moduleDescriptor,
Calamares::Module* m );
friend void ::operator>>( const QVariantMap& moduleDescriptor, Calamares::Module* m );
};
}
} // namespace Calamares
#endif // CALAMARES_MODULE_H
#endif // CALAMARES_MODULE_H

@ -56,7 +56,9 @@ ModuleManager::~ModuleManager()
{
// The map is populated with Module::fromDescriptor(), which allocates on the heap.
for ( auto moduleptr : m_loadedModulesByInstanceKey )
{
delete moduleptr;
}
}
@ -89,15 +91,17 @@ ModuleManager::doInit()
bool success = currentDir.cd( subdir );
if ( success )
{
QFileInfo descriptorFileInfo( currentDir.absoluteFilePath( QLatin1Literal( "module.desc") ) );
QFileInfo descriptorFileInfo( currentDir.absoluteFilePath( QLatin1Literal( "module.desc" ) ) );
if ( !descriptorFileInfo.exists() )
{
cDebug() << "ModuleManager expected descriptor is missing:" << descriptorFileInfo.absoluteFilePath();
cDebug() << "ModuleManager expected descriptor is missing:"
<< descriptorFileInfo.absoluteFilePath();
continue;
}
if ( !descriptorFileInfo.isReadable() )
{
cDebug() << "ModuleManager descriptor file is unreadable:" << descriptorFileInfo.absoluteFilePath();
cDebug() << "ModuleManager descriptor file is unreadable:"
<< descriptorFileInfo.absoluteFilePath();
continue;
}
@ -105,8 +109,8 @@ ModuleManager::doInit()
QVariantMap moduleDescriptorMap = CalamaresUtils::loadYaml( descriptorFileInfo, &ok );
QString moduleName = ok ? moduleDescriptorMap.value( "name" ).toString() : QString();
if ( ok && ( moduleName == currentDir.dirName() ) &&
!m_availableDescriptorsByModuleName.contains( moduleName ) )
if ( ok && ( moduleName == currentDir.dirName() )
&& !m_availableDescriptorsByModuleName.contains( moduleName ) )
{
m_availableDescriptorsByModuleName.insert( moduleName, moduleDescriptorMap );
m_moduleDirectoriesByModuleName.insert( moduleName,
@ -155,16 +159,16 @@ ModuleManager::moduleInstance( const QString& instanceKey )
*
* @return -1 on failure, otherwise index of the instance that matches.
*/
static int findCustomInstance( const Settings::InstanceDescriptionList& customInstances,
const QString& module,
const QString& id )
static int
findCustomInstance( const Settings::InstanceDescriptionList& customInstances, const QString& module, const QString& id )
{
for ( int i = 0; i < customInstances.count(); ++i )
{
const auto& thisInstance = customInstances[ i ];
if ( thisInstance.value( "module" ) == module &&
thisInstance.value( "id" ) == id )
if ( thisInstance.value( "module" ) == module && thisInstance.value( "id" ) == id )
{
return i;
}
}
return -1;
}
@ -173,26 +177,23 @@ static int findCustomInstance( const Settings::InstanceDescriptionList& customIn
void
ModuleManager::loadModules()
{
QTimer::singleShot( 0, this, [ this ]()
{
QTimer::singleShot( 0, this, [this]() {
QStringList failedModules = checkDependencies();
Settings::InstanceDescriptionList customInstances =
Settings::instance()->customModuleInstances();
Settings::InstanceDescriptionList customInstances = Settings::instance()->customModuleInstances();
const auto modulesSequence = failedModules.isEmpty() ? Settings::instance()->modulesSequence() : Settings::ModuleSequence();
const auto modulesSequence
= failedModules.isEmpty() ? Settings::instance()->modulesSequence() : Settings::ModuleSequence();
for ( const auto& modulePhase : modulesSequence )
{
ModuleAction currentAction = modulePhase.first;
foreach ( const QString& moduleEntry,
modulePhase.second )
foreach ( const QString& moduleEntry, modulePhase.second )
{
QStringList moduleEntrySplit = moduleEntry.split( '@' );
QString moduleName;
QString instanceId;
QString configFileName;
if ( moduleEntrySplit.length() < 1 ||
moduleEntrySplit.length() > 2 )
if ( moduleEntrySplit.length() < 1 || moduleEntrySplit.length() > 2 )
{
cError() << "Wrong module entry format for module" << moduleEntry;
failedModules.append( moduleEntry );
@ -202,8 +203,8 @@ ModuleManager::loadModules()
instanceId = moduleEntrySplit.last();
configFileName = QString( "%1.conf" ).arg( moduleName );
if ( !m_availableDescriptorsByModuleName.contains( moduleName ) ||
m_availableDescriptorsByModuleName.value( moduleName ).isEmpty() )
if ( !m_availableDescriptorsByModuleName.contains( moduleName )
|| m_availableDescriptorsByModuleName.value( moduleName ).isEmpty() )
{
cError() << "Module" << moduleName << "not found in module search paths."
<< Logger::DebugList( m_paths );
@ -211,13 +212,15 @@ ModuleManager::loadModules()
continue;
}
if ( moduleName != instanceId ) //means this is a custom instance
if ( moduleName != instanceId ) //means this is a custom instance
{
int found = findCustomInstance( customInstances, moduleName, instanceId );
if ( found > -1 )
{
configFileName = customInstances[ found ].value( "config" );
else //ought to be a custom instance, but cannot find instance entry
}
else //ought to be a custom instance, but cannot find instance entry
{
cError() << "Custom instance" << moduleEntry << "not found in custom instances section.";
failedModules.append( moduleEntry );
@ -233,12 +236,9 @@ ModuleManager::loadModules()
// exists and is valid, but that's the only thing that could fail
// from this point on. -- Teo 8/2015
QString instanceKey = QString( "%1@%2" )
.arg( moduleName )
.arg( instanceId );
QString instanceKey = QString( "%1@%2" ).arg( moduleName ).arg( instanceId );
Module* thisModule =
m_loadedModulesByInstanceKey.value( instanceKey, nullptr );
Module* thisModule = m_loadedModulesByInstanceKey.value( instanceKey, nullptr );
if ( thisModule && !thisModule->isLoaded() )
{
cError() << "Module" << instanceKey << "exists but not loaded.";
@ -247,14 +247,15 @@ ModuleManager::loadModules()
}
if ( thisModule && thisModule->isLoaded() )
{
cDebug() << "Module" << instanceKey << "already loaded.";
}
else
{
thisModule =
Module::fromDescriptor( m_availableDescriptorsByModuleName.value( moduleName ),
instanceId,
configFileName,
m_moduleDirectoriesByModuleName.value( moduleName ) );
thisModule = Module::fromDescriptor( m_availableDescriptorsByModuleName.value( moduleName ),
instanceId,
configFileName,
m_moduleDirectoriesByModuleName.value( moduleName ) );
if ( !thisModule )
{
cError() << "Module" << instanceKey << "cannot be created from descriptor" << configFileName;
@ -284,10 +285,9 @@ ModuleManager::loadModules()
// thisModule. We now need to enqueue jobs info into an EVS.
if ( currentAction == ModuleAction::Exec )
{
ExecutionViewStep* evs =
qobject_cast< ExecutionViewStep* >(
Calamares::ViewManager::instance()->viewSteps().last() );
if ( !evs ) // If the last step is not an EVS, we must create it.
ExecutionViewStep* evs
= qobject_cast< ExecutionViewStep* >( Calamares::ViewManager::instance()->viewSteps().last() );
if ( !evs ) // If the last step is not an EVS, we must create it.
{
evs = new ExecutionViewStep( ViewManager::instance() );
ViewManager::instance()->addViewStep( evs );
@ -303,7 +303,9 @@ ModuleManager::loadModules()
emit modulesFailed( failedModules );
}
else
{
emit modulesLoaded();
}
} );
}
@ -314,12 +316,12 @@ ModuleManager::checkRequirements()
QVector< Module* > modules( m_loadedModulesByInstanceKey.count() );
int count = 0;
for (const auto& module : m_loadedModulesByInstanceKey )
for ( const auto& module : m_loadedModulesByInstanceKey )
{
modules[count++] = module;
modules[ count++ ] = module;
}
RequirementsChecker *rq = new RequirementsChecker( modules, this );
RequirementsChecker* rq = new RequirementsChecker( modules, this );
connect( rq, &RequirementsChecker::requirementsResult, this, &ModuleManager::requirementsResult );
connect( rq, &RequirementsChecker::requirementsComplete, this, &ModuleManager::requirementsComplete );
connect( rq, &RequirementsChecker::requirementsProgress, this, &ModuleManager::requirementsProgress );
@ -332,10 +334,12 @@ static QStringList
missingRequiredModules( const QStringList& required, const QMap< QString, QVariantMap >& available )
{
QStringList l;
for( const QString& depName : required )
for ( const QString& depName : required )
{
if ( !available.contains( depName ) )
{
l.append( depName );
}
}
return l;
@ -352,10 +356,11 @@ ModuleManager::checkDependencies()
do
{
somethingWasRemovedBecauseOfUnmetDependencies = false;
for ( auto it = m_availableDescriptorsByModuleName.begin();
it != m_availableDescriptorsByModuleName.end(); ++it )
for ( auto it = m_availableDescriptorsByModuleName.begin(); it != m_availableDescriptorsByModuleName.end();
++it )
{
QStringList unmet = missingRequiredModules( it->value( "requiredModules" ).toStringList(), m_availableDescriptorsByModuleName );
QStringList unmet = missingRequiredModules( it->value( "requiredModules" ).toStringList(),
m_availableDescriptorsByModuleName );
if ( unmet.count() > 0 )
{
@ -368,8 +373,7 @@ ModuleManager::checkDependencies()
break;
}
}
}
while( somethingWasRemovedBecauseOfUnmetDependencies );
} while ( somethingWasRemovedBecauseOfUnmetDependencies );
return failed;
}
@ -378,12 +382,13 @@ bool
ModuleManager::checkDependencies( const Module& m )
{
bool allRequirementsFound = true;
QStringList requiredModules = m_availableDescriptorsByModuleName[ m.name() ].value( "requiredModules" ).toStringList();
QStringList requiredModules
= m_availableDescriptorsByModuleName[ m.name() ].value( "requiredModules" ).toStringList();
for ( const QString& required : requiredModules )
{
bool requirementFound = false;
for( const Module* v : m_loadedModulesByInstanceKey )
for ( const Module* v : m_loadedModulesByInstanceKey )
if ( required == v->name() )
{
requirementFound = true;
@ -399,4 +404,4 @@ ModuleManager::checkDependencies( const Module& m )
return allRequirementsFound;
}
} // namespace
} // namespace Calamares

@ -91,7 +91,7 @@ public:
signals:
void initDone();
void modulesLoaded(); /// All of the modules were loaded successfully
void modulesFailed( QStringList ); /// .. or not
void modulesFailed( QStringList ); /// .. or not
// Below, see RequirementsChecker documentation
void requirementsComplete( bool );
void requirementsResult( RequirementsList );
@ -129,6 +129,6 @@ private:
static ModuleManager* s_instance;
};
}
} // namespace Calamares
#endif // MODULELOADER_H
#endif // MODULELOADER_H

@ -44,12 +44,11 @@ void
ProcessJobModule::loadSelf()
{
if ( m_loaded )
{
return;
}
m_job = job_ptr( new ProcessJob( m_command,
m_workingPath,
m_runInChroot,
m_secondsTimeout ) );
m_job = job_ptr( new ProcessJob( m_command, m_workingPath, m_runInChroot, m_secondsTimeout ) );
m_loaded = true;
}
@ -69,17 +68,21 @@ ProcessJobModule::initFrom( const QVariantMap& moduleDescriptor )
m_workingPath = directory.absolutePath();
if ( !moduleDescriptor.value( "command" ).toString().isEmpty() )
{
m_command = moduleDescriptor.value( "command" ).toString();
}
m_secondsTimeout = 30;
if ( moduleDescriptor.contains( "timeout" ) &&
!moduleDescriptor.value( "timeout" ).isNull() )
if ( moduleDescriptor.contains( "timeout" ) && !moduleDescriptor.value( "timeout" ).isNull() )
{
m_secondsTimeout = moduleDescriptor.value( "timeout" ).toInt();
}
m_runInChroot = false;
if ( moduleDescriptor.contains( "chroot" )&&
!moduleDescriptor.value( "chroot" ).isNull() )
if ( moduleDescriptor.contains( "chroot" ) && !moduleDescriptor.value( "chroot" ).isNull() )
{
m_runInChroot = moduleDescriptor.value( "chroot" ).toBool();
}
}
@ -87,11 +90,11 @@ ProcessJobModule::ProcessJobModule()
: Module()
, m_secondsTimeout( 30 )
, m_runInChroot( false )
{}
{
}
ProcessJobModule::~ProcessJobModule()
{}
ProcessJobModule::~ProcessJobModule() {}
} // namespace Calamares
} // namespace Calamares

@ -51,6 +51,6 @@ private:
job_ptr m_job;
};
} // namespace Calamares
} // namespace Calamares
#endif // CALAMARES_PROCESSJOBMODULE_H
#endif // CALAMARES_PROCESSJOBMODULE_H

@ -45,7 +45,9 @@ void
PythonJobModule::loadSelf()
{
if ( m_loaded )
{
return;
}
m_job = Calamares::job_ptr( new PythonJob( m_scriptFileName, m_workingPath, m_configurationMap ) );
m_loaded = true;
@ -67,17 +69,19 @@ PythonJobModule::initFrom( const QVariantMap& moduleDescriptor )
m_workingPath = directory.absolutePath();
if ( !moduleDescriptor.value( "script" ).toString().isEmpty() )
{
m_scriptFileName = moduleDescriptor.value( "script" ).toString();
}
}
PythonJobModule::PythonJobModule()
: Module()
{}
{
}
PythonJobModule::~PythonJobModule()
{}
PythonJobModule::~PythonJobModule() {}
} // namespace Calamares
} // namespace Calamares

@ -48,6 +48,6 @@ private:
job_ptr m_job;
};
} // namespace Calamares
} // namespace Calamares
#endif // CALAMARES_PYTHONJOBMODULE_H
#endif // CALAMARES_PYTHONJOBMODULE_H

@ -20,15 +20,15 @@
#include "PythonQtViewModule.h"
#include "utils/Logger.h"
#include "viewpages/ViewStep.h"
#include "viewpages/PythonQtViewStep.h"
#include "ViewManager.h"
#include "CalamaresConfig.h"
#include "viewpages/PythonQtGlobalStorageWrapper.h"
#include "viewpages/PythonQtUtilsWrapper.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "ViewManager.h"
#include "utils/Logger.h"
#include "viewpages/PythonQtGlobalStorageWrapper.h"
#include "viewpages/PythonQtUtilsWrapper.h"
#include "viewpages/PythonQtViewStep.h"
#include "viewpages/ViewStep.h"
#include <PythonQt.h>
#include <PythonQt_QtAll.h>
@ -65,11 +65,12 @@ PythonQtViewModule::loadSelf()
if ( PythonQt::self() == nullptr )
{
if ( Py_IsInitialized() )
PythonQt::init( PythonQt::IgnoreSiteModule |
PythonQt::RedirectStdOut |
PythonQt::PythonAlreadyInitialized );
PythonQt::init( PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut
| PythonQt::PythonAlreadyInitialized );
else
{
PythonQt::init();
}
PythonQt_QtAll::init();
cDebug() << "Initializing PythonQt bindings."
@ -81,8 +82,7 @@ PythonQtViewModule::loadSelf()
// We only do the following to force PythonQt to create a submodule
// "calamares" for us to put our static objects in
PythonQt::self()->registerClass( &::GlobalStorage::staticMetaObject,
"calamares" );
PythonQt::self()->registerClass( &::GlobalStorage::staticMetaObject, "calamares" );
// Get a PythonQtObjectPtr to the PythonQt.calamares submodule
PythonQtObjectPtr pqtm = PythonQt::priv()->pythonQtModule();
@ -90,39 +90,34 @@ PythonQtViewModule::loadSelf()
// Prepare GlobalStorage object, in module PythonQt.calamares
if ( !s_gs )
{
s_gs = new ::GlobalStorage( Calamares::JobQueue::instance()->globalStorage() );
}
cala.addObject( "global_storage", s_gs );
// Prepare Utils object, in module PythonQt.calamares
if ( !s_utils )
{
s_utils = new ::Utils( Calamares::JobQueue::instance()->globalStorage() );
}
cala.addObject( "utils", s_utils );
// Append configuration object, in module PythonQt.calamares
cala.addVariable( "configuration", m_configurationMap );
// Basic stdout/stderr handling
QObject::connect( PythonQt::self(), &PythonQt::pythonStdOut,
[]( const QString& message )
{
cDebug() << "PythonQt OUT>" << message;
}
);
QObject::connect( PythonQt::self(), &PythonQt::pythonStdErr,
[]( const QString& message )
{
cDebug() << "PythonQt ERR>" << message;
}
);
QObject::connect( PythonQt::self(), &PythonQt::pythonStdOut, []( const QString& message ) {
cDebug() << "PythonQt OUT>" << message;
} );
QObject::connect( PythonQt::self(), &PythonQt::pythonStdErr, []( const QString& message ) {
cDebug() << "PythonQt ERR>" << message;
} );
}
QDir workingDir( m_workingPath );
if ( !workingDir.exists() )
{
cDebug() << "Invalid working directory"
<< m_workingPath
<< "for module"
<< name();
cDebug() << "Invalid working directory" << m_workingPath << "for module" << name();
return;
}
@ -130,23 +125,15 @@ PythonQtViewModule::loadSelf()
QFileInfo scriptFileInfo( fullPath );
if ( !scriptFileInfo.isReadable() )
{
cDebug() << "Invalid main script file path"
<< fullPath
<< "for module"
<< name();
cDebug() << "Invalid main script file path" << fullPath << "for module" << name();
return;
}
// Construct empty Python module with the given name
PythonQtObjectPtr cxt =
PythonQt::self()->
createModuleFromScript( name() );
PythonQtObjectPtr cxt = PythonQt::self()->createModuleFromScript( name() );
if ( cxt.isNull() )
{
cDebug() << "Cannot load PythonQt context from file"
<< fullPath
<< "for module"
<< name();
cDebug() << "Cannot load PythonQt context from file" << fullPath << "for module" << name();
return;
}
@ -165,9 +152,8 @@ PythonQtViewModule::loadSelf()
m_viewStep = new PythonQtViewStep( cxt );
cDebug() << "PythonQtViewModule loading self for instance" << instanceKey()
<< "\nPythonQtViewModule at address" << this
<< "\nViewStep at address" << m_viewStep;
cDebug() << "PythonQtViewModule loading self for instance" << instanceKey() << "\nPythonQtViewModule at address"
<< this << "\nViewStep at address" << m_viewStep;
m_viewStep->setModuleInstanceKey( instanceKey() );
m_viewStep->setConfigurationMap( m_configurationMap );
@ -193,7 +179,9 @@ PythonQtViewModule::initFrom( const QVariantMap& moduleDescriptor )
m_workingPath = directory.absolutePath();
if ( !moduleDescriptor.value( "script" ).toString().isEmpty() )
{
m_scriptFileName = moduleDescriptor.value( "script" ).toString();
}
}
PythonQtViewModule::PythonQtViewModule()
@ -201,8 +189,6 @@ PythonQtViewModule::PythonQtViewModule()
{
}
PythonQtViewModule::~PythonQtViewModule()
{
}
PythonQtViewModule::~PythonQtViewModule() {}
} // namespace Calamares
} // namespace Calamares

@ -19,8 +19,8 @@
#ifndef CALAMARES_PYTHONQTVIEWMODULE_H
#define CALAMARES_PYTHONQTVIEWMODULE_H
#include "UiDllMacro.h"
#include "Module.h"
#include "UiDllMacro.h"
namespace Calamares
{
@ -40,7 +40,7 @@ protected:
void initFrom( const QVariantMap& moduleDescriptor ) override;
private:
friend class Module; //so only the superclass can instantiate
friend class Module; //so only the superclass can instantiate
explicit PythonQtViewModule();
virtual ~PythonQtViewModule();
@ -50,6 +50,6 @@ private:
QString m_workingPath;
};
} // namespace Calamares
} // namespace Calamares
#endif // CALAMARES_PYTHONQTVIEWMODULE_H
#endif // CALAMARES_PYTHONQTVIEWMODULE_H

@ -16,4 +16,3 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Requirement.h"

@ -62,6 +62,6 @@ using RequirementsList = QList< RequirementEntry >;
} // namespace Calamares
Q_DECLARE_METATYPE(Calamares::RequirementEntry)
Q_DECLARE_METATYPE( Calamares::RequirementEntry )
#endif

@ -25,10 +25,10 @@
#include <algorithm>
#include <QtConcurrent/QtConcurrent>
#include <QFuture>
#include <QFutureWatcher>
#include <QTimer>
#include <QtConcurrent/QtConcurrent>
namespace Calamares
@ -54,12 +54,15 @@ registerMetatypes()
}
static void
check( Module * const &m, RequirementsChecker *c )
check( Module* const& m, RequirementsChecker* c )
{
RequirementsList l = m->checkRequirements();
if ( l.count() > 0 )
{
c->addCheckedRequirements( l );
c->requirementsProgress( QObject::tr( "Requirements checking for module <i>%1</i> is complete." ).arg( m->name() ) );
}
c->requirementsProgress(
QObject::tr( "Requirements checking for module <i>%1</i> is complete." ).arg( m->name() ) );
}
RequirementsChecker::RequirementsChecker( QVector< Module* > modules, QObject* parent )
@ -74,9 +77,7 @@ RequirementsChecker::RequirementsChecker( QVector< Module* > modules, QObject* p
registerMetatypes();
}
RequirementsChecker::~RequirementsChecker()
{
}
RequirementsChecker::~RequirementsChecker() {}
void
RequirementsChecker::run()
@ -85,9 +86,9 @@ RequirementsChecker::run()
connect( m_progressTimer, &QTimer::timeout, this, &RequirementsChecker::reportProgress );
m_progressTimer->start( 1200 ); // msec
for (const auto& module : m_modules )
for ( const auto& module : m_modules )
{
Watcher *watcher = new Watcher( this );
Watcher* watcher = new Watcher( this );
watcher->setFuture( QtConcurrent::run( check, module, this ) );
m_watchers.append( watcher );
connect( watcher, &Watcher::finished, this, &RequirementsChecker::finished );
@ -102,7 +103,9 @@ RequirementsChecker::finished()
static QMutex finishedMutex;
QMutexLocker lock( &finishedMutex );
if ( m_progressTimer && std::all_of( m_watchers.cbegin(), m_watchers.cend(), []( const Watcher *w ) { return w && w->isFinished(); } ) )
if ( m_progressTimer && std::all_of( m_watchers.cbegin(), m_watchers.cend(), []( const Watcher* w ) {
return w && w->isFinished();
} ) )
{
cDebug() << "All requirements have been checked.";
if ( m_progressTimer )
@ -125,7 +128,7 @@ RequirementsChecker::finished()
}
emit requirementsComplete( acceptable );
QTimer::singleShot(0, this, &RequirementsChecker::done );
QTimer::singleShot( 0, this, &RequirementsChecker::done );
}
}
@ -146,7 +149,8 @@ RequirementsChecker::reportProgress()
{
m_progressTimeouts++;
auto remaining = std::count_if( m_watchers.cbegin(), m_watchers.cend(), []( const Watcher *w ) { return w && !w->isFinished(); } );
auto remaining = std::count_if(
m_watchers.cbegin(), m_watchers.cend(), []( const Watcher* w ) { return w && !w->isFinished(); } );
if ( remaining > 0 )
{
unsigned int posInterval = ( m_progressTimer->interval() < 0 ) ? 1000 : uint( m_progressTimer->interval() );
@ -155,7 +159,9 @@ RequirementsChecker::reportProgress()
emit requirementsProgress( waiting + QString( " " ) + elapsed );
}
else
{
emit requirementsProgress( tr( "System-requirements checking is complete." ) );
}
}
}
} // namespace Calamares

@ -78,10 +78,10 @@ private:
RequirementsList m_collectedRequirements;
QTimer *m_progressTimer;
QTimer* m_progressTimer;
unsigned m_progressTimeouts;
} ;
};
}
} // namespace Calamares
#endif

@ -19,10 +19,10 @@
#include "ViewModule.h"
#include "utils/PluginFactory.h"
#include "ViewManager.h"
#include "utils/Logger.h"
#include "utils/PluginFactory.h"
#include "viewpages/ViewStep.h"
#include "ViewManager.h"
#include <QDir>
#include <QPluginLoader>
@ -75,7 +75,9 @@ ViewModule::loadSelf()
cDebug() << "ViewModule" << instanceKey() << "loading complete.";
}
else
{
cWarning() << Q_FUNC_INFO << "No view step was created";
}
}
@ -100,7 +102,7 @@ ViewModule::initFrom( const QVariantMap& moduleDescriptor )
// If a load path is not specified, we look for a plugin to load in the directory.
if ( load.isEmpty() || !QLibrary::isLibrary( load ) )
{
const QStringList ls = directory.entryList( QStringList{ "*.so" } );
const QStringList ls = directory.entryList( QStringList { "*.so" } );
if ( !ls.isEmpty() )
{
for ( QString entry : ls )
@ -135,4 +137,4 @@ ViewModule::checkRequirements()
return m_viewStep->checkRequirements();
}
} // namespace Calamares
} // namespace Calamares

@ -20,8 +20,8 @@
#ifndef CALAMARES_VIEWMODULE_H
#define CALAMARES_VIEWMODULE_H
#include "UiDllMacro.h"
#include "Module.h"
#include "UiDllMacro.h"
class QPluginLoader;
@ -45,7 +45,7 @@ protected:
void initFrom( const QVariantMap& moduleDescriptor ) override;
private:
friend class Module; //so only the superclass can instantiate
friend class Module; //so only the superclass can instantiate
explicit ViewModule();
virtual ~ViewModule() override;
@ -53,6 +53,6 @@ private:
ViewStep* m_viewStep = nullptr;
};
} // namespace Calamares
} // namespace Calamares
#endif // CALAMARES_VIEWMODULE_H
#endif // CALAMARES_VIEWMODULE_H

Loading…
Cancel
Save