From 0bd2bfa7081d7d974a71f9a77f69fa3ce51715b1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 27 Jun 2019 15:15:47 +0200 Subject: [PATCH] CI: apply coding style to libcalamaresui/modulesystem --- .../modulesystem/CppJobModule.cpp | 16 +-- .../modulesystem/CppJobModule.h | 8 +- src/libcalamaresui/modulesystem/Module.cpp | 58 +++++++--- src/libcalamaresui/modulesystem/Module.h | 23 ++-- .../modulesystem/ModuleManager.cpp | 103 +++++++++--------- .../modulesystem/ModuleManager.h | 6 +- .../modulesystem/ProcessJobModule.cpp | 27 +++-- .../modulesystem/ProcessJobModule.h | 4 +- .../modulesystem/PythonJobModule.cpp | 12 +- .../modulesystem/PythonJobModule.h | 4 +- .../modulesystem/PythonQtViewModule.cpp | 76 ++++++------- .../modulesystem/PythonQtViewModule.h | 8 +- .../modulesystem/Requirement.cpp | 1 - src/libcalamaresui/modulesystem/Requirement.h | 2 +- .../modulesystem/RequirementsChecker.cpp | 30 +++-- .../modulesystem/RequirementsChecker.h | 6 +- .../modulesystem/ViewModule.cpp | 10 +- src/libcalamaresui/modulesystem/ViewModule.h | 8 +- 18 files changed, 212 insertions(+), 190 deletions(-) diff --git a/src/libcalamaresui/modulesystem/CppJobModule.cpp b/src/libcalamaresui/modulesystem/CppJobModule.cpp index 22d9a0524..17c191024 100644 --- a/src/libcalamaresui/modulesystem/CppJobModule.cpp +++ b/src/libcalamaresui/modulesystem/CppJobModule.cpp @@ -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 #include @@ -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 diff --git a/src/libcalamaresui/modulesystem/CppJobModule.h b/src/libcalamaresui/modulesystem/CppJobModule.h index e3b232353..feb0f22bb 100644 --- a/src/libcalamaresui/modulesystem/CppJobModule.h +++ b/src/libcalamaresui/modulesystem/CppJobModule.h @@ -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 diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 44798b32b..799da941e 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -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 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 diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index 6da9c0ce4..ae3b31e6d 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -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 diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index a030e55cd..a65f64108 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -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 diff --git a/src/libcalamaresui/modulesystem/ModuleManager.h b/src/libcalamaresui/modulesystem/ModuleManager.h index 64db75b6a..8412e51d5 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.h +++ b/src/libcalamaresui/modulesystem/ModuleManager.h @@ -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 diff --git a/src/libcalamaresui/modulesystem/ProcessJobModule.cpp b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp index 85bdfa4de..f15e5c457 100644 --- a/src/libcalamaresui/modulesystem/ProcessJobModule.cpp +++ b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp @@ -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 diff --git a/src/libcalamaresui/modulesystem/ProcessJobModule.h b/src/libcalamaresui/modulesystem/ProcessJobModule.h index 704f8a639..9c20aa4f4 100644 --- a/src/libcalamaresui/modulesystem/ProcessJobModule.h +++ b/src/libcalamaresui/modulesystem/ProcessJobModule.h @@ -51,6 +51,6 @@ private: job_ptr m_job; }; -} // namespace Calamares +} // namespace Calamares -#endif // CALAMARES_PROCESSJOBMODULE_H +#endif // CALAMARES_PROCESSJOBMODULE_H diff --git a/src/libcalamaresui/modulesystem/PythonJobModule.cpp b/src/libcalamaresui/modulesystem/PythonJobModule.cpp index e910a4c80..46ec1dff1 100644 --- a/src/libcalamaresui/modulesystem/PythonJobModule.cpp +++ b/src/libcalamaresui/modulesystem/PythonJobModule.cpp @@ -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 diff --git a/src/libcalamaresui/modulesystem/PythonJobModule.h b/src/libcalamaresui/modulesystem/PythonJobModule.h index 38b10be83..8fa137f71 100644 --- a/src/libcalamaresui/modulesystem/PythonJobModule.h +++ b/src/libcalamaresui/modulesystem/PythonJobModule.h @@ -48,6 +48,6 @@ private: job_ptr m_job; }; -} // namespace Calamares +} // namespace Calamares -#endif // CALAMARES_PYTHONJOBMODULE_H +#endif // CALAMARES_PYTHONJOBMODULE_H diff --git a/src/libcalamaresui/modulesystem/PythonQtViewModule.cpp b/src/libcalamaresui/modulesystem/PythonQtViewModule.cpp index ec9f3c805..0b775e067 100644 --- a/src/libcalamaresui/modulesystem/PythonQtViewModule.cpp +++ b/src/libcalamaresui/modulesystem/PythonQtViewModule.cpp @@ -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 #include @@ -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 diff --git a/src/libcalamaresui/modulesystem/PythonQtViewModule.h b/src/libcalamaresui/modulesystem/PythonQtViewModule.h index cc6899599..6ebb5c433 100644 --- a/src/libcalamaresui/modulesystem/PythonQtViewModule.h +++ b/src/libcalamaresui/modulesystem/PythonQtViewModule.h @@ -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 diff --git a/src/libcalamaresui/modulesystem/Requirement.cpp b/src/libcalamaresui/modulesystem/Requirement.cpp index 3347a2ae8..e4525e8d6 100644 --- a/src/libcalamaresui/modulesystem/Requirement.cpp +++ b/src/libcalamaresui/modulesystem/Requirement.cpp @@ -16,4 +16,3 @@ * along with Calamares. If not, see . */ #include "Requirement.h" - diff --git a/src/libcalamaresui/modulesystem/Requirement.h b/src/libcalamaresui/modulesystem/Requirement.h index 396fe852b..3f8d1a54b 100644 --- a/src/libcalamaresui/modulesystem/Requirement.h +++ b/src/libcalamaresui/modulesystem/Requirement.h @@ -62,6 +62,6 @@ using RequirementsList = QList< RequirementEntry >; } // namespace Calamares -Q_DECLARE_METATYPE(Calamares::RequirementEntry) +Q_DECLARE_METATYPE( Calamares::RequirementEntry ) #endif diff --git a/src/libcalamaresui/modulesystem/RequirementsChecker.cpp b/src/libcalamaresui/modulesystem/RequirementsChecker.cpp index f71c24b8b..2f500c771 100644 --- a/src/libcalamaresui/modulesystem/RequirementsChecker.cpp +++ b/src/libcalamaresui/modulesystem/RequirementsChecker.cpp @@ -25,10 +25,10 @@ #include -#include #include #include #include +#include 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 %1 is complete." ).arg( m->name() ) ); + } + c->requirementsProgress( + QObject::tr( "Requirements checking for module %1 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 diff --git a/src/libcalamaresui/modulesystem/RequirementsChecker.h b/src/libcalamaresui/modulesystem/RequirementsChecker.h index 6e681971c..2e1708016 100644 --- a/src/libcalamaresui/modulesystem/RequirementsChecker.h +++ b/src/libcalamaresui/modulesystem/RequirementsChecker.h @@ -78,10 +78,10 @@ private: RequirementsList m_collectedRequirements; - QTimer *m_progressTimer; + QTimer* m_progressTimer; unsigned m_progressTimeouts; -} ; +}; -} +} // namespace Calamares #endif diff --git a/src/libcalamaresui/modulesystem/ViewModule.cpp b/src/libcalamaresui/modulesystem/ViewModule.cpp index 2789dcfe3..5cd2fe7d9 100644 --- a/src/libcalamaresui/modulesystem/ViewModule.cpp +++ b/src/libcalamaresui/modulesystem/ViewModule.cpp @@ -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 #include @@ -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 diff --git a/src/libcalamaresui/modulesystem/ViewModule.h b/src/libcalamaresui/modulesystem/ViewModule.h index 7813130d0..e9db1347b 100644 --- a/src/libcalamaresui/modulesystem/ViewModule.h +++ b/src/libcalamaresui/modulesystem/ViewModule.h @@ -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