From 58ae8e13c9f49ea1caf691b7957796b7e56d190e Mon Sep 17 00:00:00 2001 From: shainer Date: Sat, 12 Nov 2016 17:57:58 +0000 Subject: [PATCH] Add support for non-critical groups in netinstall. Package groups are divided into critical and non-critical depending on whether we want all Calamares to fail if installing a package in the group fails, or we are okay with just logging a warning. The distinction is configured in the YAML file listing the package groups. By default, all groups are critical, to keep supporting the previous behaviour. --- src/modules/netinstall/NetInstallPage.cpp | 17 ++++--- src/modules/netinstall/NetInstallPage.h | 46 +++++++++---------- src/modules/netinstall/NetInstallViewStep.cpp | 27 +++++++++-- src/modules/netinstall/README.md | 12 ++++- 4 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/modules/netinstall/NetInstallPage.cpp b/src/modules/netinstall/NetInstallPage.cpp index 89f8e58dd..5c02d0b1b 100644 --- a/src/modules/netinstall/NetInstallPage.cpp +++ b/src/modules/netinstall/NetInstallPage.cpp @@ -85,6 +85,9 @@ void NetInstallPage::readGroups( const QByteArray& yamlData ) if ( groupDefinition["hidden"] ) m_groups[name].hidden = yamlToVariant( groupDefinition["hidden"] ).toBool(); + if ( groupDefinition["critical"] ) + m_groups[name].critical = yamlToVariant( groupDefinition["critical"] ).toBool(); + m_groupOrder.append( name ); } } @@ -124,25 +127,25 @@ NetInstallPage::dataIsHere( QNetworkReply* reply ) emit checkReady( isReady() ); } -QStringList NetInstallPage::selectedPackages() const +QList NetInstallPage::selectedGroups() const { - QStringList selectedPackages; + QList selectedGroups; - // Add all the packages for groups that are toggled in the view. + // Add all the groups that are toggled in the view. for ( auto it = m_groupWidgets.constBegin(); it != m_groupWidgets.constEnd(); it++ ) { if ( it.value()->isToggled() ) - selectedPackages += m_groups[it.key()].packages; + selectedGroups += m_groups[it.key()]; } - // Add all the packages for groups that are hidden but selected. + // Add all groups that are hidden but selected. for ( const Group& group : m_groups.values() ) { if ( group.hidden && group.selected ) - selectedPackages += group.packages; + selectedGroups += group; } - return selectedPackages; + return selectedGroups; } void NetInstallPage::loadGroupList() diff --git a/src/modules/netinstall/NetInstallPage.h b/src/modules/netinstall/NetInstallPage.h index 5145fdb23..a79c116b5 100644 --- a/src/modules/netinstall/NetInstallPage.h +++ b/src/modules/netinstall/NetInstallPage.h @@ -34,29 +34,30 @@ namespace Ui class Page_NetInst; } +// Representation of a package group. +struct Group +{ + Group() + : Group( "","",false, false, true ) { } + Group( QString name, QString description, bool selected, bool hidden, bool critical ) + : name( name ), description( description ), selected( selected ), hidden( hidden ), critical( critical ) { } + Group( QString name, QString description ) + : Group( name, description, false, false, true ) { } + + QString name; + QString description; + QStringList packages; + + // See README.md for a description of these fields. + bool selected = false; + bool hidden = false; + bool critical = true; +}; + class NetInstallPage : public QWidget { Q_OBJECT - // Internal representation of a package group. - struct Group - { - Group() - : Group( "","",false, false ) { } - Group( QString name, QString description, bool selected, bool hidden ) - : name( name ), description( description ), selected( selected ), hidden( hidden ) { } - Group( QString name, QString description ) - : Group( name, description, false, false ) { } - - QString name; - QString description; - QStringList packages; - - // See README.md for a description of these two fields. - bool selected = false; - bool hidden = false; - }; - public: NetInstallPage( QWidget* parent = nullptr ); @@ -69,10 +70,9 @@ public: // in the global storage. This should be called before displaying the page. void loadGroupList(); - // Returns the list of packages belonging to groups that are - // selected in the view in this given moment. No data is cached here, so - // this function does not have constant time. - QStringList selectedPackages() const; + // Return a list of groups currently selected. No data is cached here, so + // this function does not run in constant time. + QList selectedGroups() const; public slots: void dataIsHere( QNetworkReply* ); diff --git a/src/modules/netinstall/NetInstallViewStep.cpp b/src/modules/netinstall/NetInstallViewStep.cpp index 333debd9b..3313996b2 100644 --- a/src/modules/netinstall/NetInstallViewStep.cpp +++ b/src/modules/netinstall/NetInstallViewStep.cpp @@ -125,12 +125,31 @@ NetInstallViewStep::onLeave() cDebug() << "Leaving netinstall, adding packages to be installed" << "to global storage"; - if ( !m_widget->selectedPackages().empty() ) + const QList& selectedGroups = m_widget->selectedGroups(); + + if ( !selectedGroups.empty() ) { QMap packagesWithOperation; - // Gets all packages selected in the page; includes groups that are - // selected by default but not displayed. - packagesWithOperation.insert( "install", m_widget->selectedPackages() ); + QStringList packages, critical_packages; + + // We have two types of groups: "critical" (failing to install any of + // the packages makes Calamares fail) and "non critical" (we only log + // an error if the installation fails). We distinguish them here and select + // the correct package operation. + for (const Group& group : selectedGroups) { + if (group.critical) { + critical_packages += group.packages; + } else { + packages += group.packages; + } + } + + if (!critical_packages.empty()) { + packagesWithOperation.insert( "install", critical_packages ); + } + if (!packages.empty()) { + packagesWithOperation.insert( "try_install", packages); + } Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); gs->insert( "packageOperations", QVariant( packagesWithOperation ) ); diff --git a/src/modules/netinstall/README.md b/src/modules/netinstall/README.md index 790691e1b..85eb3d67b 100644 --- a/src/modules/netinstall/README.md +++ b/src/modules/netinstall/README.md @@ -27,8 +27,16 @@ The URL must point to a YAML file. Here is a short example of how the YAML file The file is composed of a list of entry, each describing one group. The keys *name*, *description* and *packages* are required. -Two more keys are supported, *hidden* (if true, do not show the group on the page) and *selected* (if true, display the group as selected). Both default to false if not present. -If both keys are set to true for the same group, you are basically creating a "default" group of packages which will always be installed in the user's system. +Three more keys are supported: + + - hidden: if true, do not show the group on the page. Defaults to false. + - selected: if true, display the group as selected. Defaults to false. + - critical: if true, make the installation process fail if installing + any of the packages in the group fails. Otherwise, just log a warning. + Defaults to true. + +If you set both *hidden* and *selected* for a group, you are basically creating a "default" group of packages +which will always be installed in the user's system. ## Configuration of the module Here is the set of instructions to have the module work in your Calamares. As of July 2016, this has been successfully