From c6ab4195c785efaa1f4aed2f910fee5338d4f0c4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 20 Dec 2017 09:12:27 -0500 Subject: [PATCH] [contextualprocess] Stub of a contextual-process job This is meant to run one or more jobs based on specific global configuration values; if could also be done by a Python module with just some if's, but this one can be used with just the config file and covers a bunch of use-cases. --- src/modules/contextualprocess/CMakeLists.txt | 9 +++ .../ContextualProcessJob.cpp | 64 +++++++++++++++++++ .../contextualprocess/ContextualProcessJob.h | 51 +++++++++++++++ .../contextualprocess/contextualprocess.conf | 19 ++++++ src/modules/contextualprocess/module.desc | 5 ++ 5 files changed, 148 insertions(+) create mode 100644 src/modules/contextualprocess/CMakeLists.txt create mode 100644 src/modules/contextualprocess/ContextualProcessJob.cpp create mode 100644 src/modules/contextualprocess/ContextualProcessJob.h create mode 100644 src/modules/contextualprocess/contextualprocess.conf create mode 100644 src/modules/contextualprocess/module.desc diff --git a/src/modules/contextualprocess/CMakeLists.txt b/src/modules/contextualprocess/CMakeLists.txt new file mode 100644 index 000000000..df27dc938 --- /dev/null +++ b/src/modules/contextualprocess/CMakeLists.txt @@ -0,0 +1,9 @@ +calamares_add_plugin( contextualprocess + TYPE job + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + ContextualProcessJob.cpp + LINK_PRIVATE_LIBRARIES + calamares + SHARED_LIB +) diff --git a/src/modules/contextualprocess/ContextualProcessJob.cpp b/src/modules/contextualprocess/ContextualProcessJob.cpp new file mode 100644 index 000000000..131a42fca --- /dev/null +++ b/src/modules/contextualprocess/ContextualProcessJob.cpp @@ -0,0 +1,64 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "ContextualProcessJob.h" + +#include +#include +#include + +#include "CalamaresVersion.h" +#include "JobQueue.h" +#include "GlobalStorage.h" + +#include "utils/Logger.h" + +ContextualProcessJob::ContextualProcessJob( QObject* parent ) + : Calamares::CppJob( parent ) +{ +} + + +ContextualProcessJob::~ContextualProcessJob() +{ +} + + +QString +ContextualProcessJob::prettyName() const +{ + return tr( "Contextual Processes Job" ); +} + + +Calamares::JobResult +ContextualProcessJob::exec() +{ + QThread::sleep( 3 ); + + return Calamares::JobResult::ok(); +} + + +void +ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap ) +{ + m_configurationMap = configurationMap; +} + +CALAMARES_PLUGIN_FACTORY_DEFINITION( ContextualProcessJobFactory, registerPlugin(); ) diff --git a/src/modules/contextualprocess/ContextualProcessJob.h b/src/modules/contextualprocess/ContextualProcessJob.h new file mode 100644 index 000000000..d12dff91d --- /dev/null +++ b/src/modules/contextualprocess/ContextualProcessJob.h @@ -0,0 +1,51 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CONTEXTUALPROCESSJOB_H +#define CONTEXTUALPROCESSJOB_H + +#include +#include + +#include + +#include + +#include + +class PLUGINDLLEXPORT ContextualProcessJob : public Calamares::CppJob +{ + Q_OBJECT + +public: + explicit ContextualProcessJob( QObject* parent = nullptr ); + virtual ~ContextualProcessJob() override; + + QString prettyName() const override; + + Calamares::JobResult exec() override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +private: + QVariantMap m_configurationMap; +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( ContextualProcessJobFactory ) + +#endif // CONTEXTUALPROCESSJOB_H diff --git a/src/modules/contextualprocess/contextualprocess.conf b/src/modules/contextualprocess/contextualprocess.conf new file mode 100644 index 000000000..832613080 --- /dev/null +++ b/src/modules/contextualprocess/contextualprocess.conf @@ -0,0 +1,19 @@ +# Configuration for the contextual process job. +# +# Contextual processes are based on **global** configuration values. +# When a given global value (string) equals a given value, then +# the associated command is executed. +# +# Configuration consists of keys for global variable names, +# and the sub-keys are strings to compare to the variable's value. +# If the variable has that particular value, the corresponding +# value is executed as a shell command in the target environment. +# +# If a command starts with "-" (a single minus sign), then the +# return value of the command following the - is ignored; otherwise, +# a failing command will abort the installation. This is much like +# make's use of - in a command. +--- +firmwareType: + efi: "-pkg remove efi-firmware" + bios: "-pkg remove bios-firmware" diff --git a/src/modules/contextualprocess/module.desc b/src/modules/contextualprocess/module.desc new file mode 100644 index 000000000..e0d1bd87f --- /dev/null +++ b/src/modules/contextualprocess/module.desc @@ -0,0 +1,5 @@ +--- +type: "job" +name: "contextualprocess" +interface: "qtplugin" +load: "libcalamares_job_contextualprocess.so"