From efd7145f765f2930156eec0caca42bd82ab7532b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Aug 2020 09:06:47 +0200 Subject: [PATCH] [libcalamares] Implement the interface-specific fields for descriptor --- src/libcalamares/modulesystem/Descriptor.cpp | 28 ++++++++++++++++++-- src/libcalamares/modulesystem/Descriptor.h | 27 +++++++++++++++---- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/libcalamares/modulesystem/Descriptor.cpp b/src/libcalamares/modulesystem/Descriptor.cpp index ecfd6b898..1ac4dc6c0 100644 --- a/src/libcalamares/modulesystem/Descriptor.cpp +++ b/src/libcalamares/modulesystem/Descriptor.cpp @@ -54,8 +54,6 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc ) { Descriptor d; - cDebug() << moduleDesc; - { bool typeOk = false; QString typeValue = moduleDesc.value( "type" ).toString(); @@ -92,6 +90,32 @@ Descriptor::fromDescriptorData( const QVariantMap& moduleDesc ) QStringList consumedKeys { "type", "interface", "name", "emergency", "noconfig", "requiredModules" }; + switch ( d.interface() ) + { + case Interface::QtPlugin: + d.m_script = CalamaresUtils::getString( moduleDesc, "load" ); + consumedKeys << "load"; + break; + case Interface::Python: + case Interface::PythonQt: + d.m_script = CalamaresUtils::getString( moduleDesc, "script" ); + consumedKeys << "script"; + break; + case Interface::Process: + d.m_script = CalamaresUtils::getString( moduleDesc, "command" ); + d.m_processTimeout = CalamaresUtils::getInteger( moduleDesc, "timeout", 30 ); + d.m_processChroot = CalamaresUtils::getBool( moduleDesc, "chroot", false ); + consumedKeys << "command" + << "timeout" + << "chroot"; + + if ( d.m_processTimeout < 0 ) + { + d.m_processTimeout = 0; + } + break; + } + QStringList superfluousKeys; for ( auto kv = moduleDesc.keyBegin(); kv != moduleDesc.keyEnd(); ++kv ) { diff --git a/src/libcalamares/modulesystem/Descriptor.h b/src/libcalamares/modulesystem/Descriptor.h index b44b53c48..8166f9869 100644 --- a/src/libcalamares/modulesystem/Descriptor.h +++ b/src/libcalamares/modulesystem/Descriptor.h @@ -95,7 +95,7 @@ public: */ /// @brief Short path to the shared-library; no extension. - QString load() const { return QString(); } + QString load() const { return m_interface == Interface::QtPlugin ? m_script : QString(); } /** @section Process Job modules * @@ -106,17 +106,20 @@ public: * Process Jobs execute one command. */ /// @brief The command to execute; passed to the shell - QString command() const { return QString(); } + QString command() const { return m_interface == Interface::Process ? m_script : QString(); } /// @brief Timeout in seconds - int timeout() const { return 30; } + int timeout() const { return m_processTimeout; } /// @brief Run command in chroot? - bool chroot() const { return false; } + bool chroot() const { return m_processChroot; } /** @section Python Job modules * * Python job modules have one specific script to load and run. */ - QString script() const { return QString(); } + QString script() const + { + return ( m_interface == Interface::Python || m_interface == Interface::PythonQt ) ? m_script : QString(); + } private: QString m_name; @@ -127,6 +130,20 @@ private: bool m_isValid = false; bool m_isEmergeny = false; bool m_hasConfig = true; + + /** @brief The name of the thing to load + * + * - A C++ module loads a shared library (via key *load*), + * - A Python module loads a Python script (via key *script*), + * - A process runs a specific command (via key *command*) + * + * This name-of-the-thing is stored here, regardless of which + * interface is being used. + */ + QString m_script; + + int m_processTimeout = 30; + bool m_processChroot = false; }; } // namespace ModuleSystem