[libcalamares] Start a packages service for netinstall and others

This commit is contained in:
Adriaan de Groot 2021-03-16 13:50:15 +01:00
parent 6662cb5f2d
commit b868894371
4 changed files with 154 additions and 0 deletions

View File

@ -59,6 +59,9 @@ set( libSources
# Network service # Network service
network/Manager.cpp network/Manager.cpp
# Packages service
packages/Globals.cpp
# Partition service # Partition service
partition/Mount.cpp partition/Mount.cpp
partition/PartitionSize.cpp partition/PartitionSize.cpp
@ -228,6 +231,12 @@ calamares_add_test(
network/Tests.cpp network/Tests.cpp
) )
calamares_add_test(
libcalamarespackagestest
SOURCES
packages/Tests.cpp
)
calamares_add_test( calamares_add_test(
libcalamarespartitiontest libcalamarespartitiontest
SOURCES SOURCES

View File

@ -0,0 +1,69 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#include "Globals.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/Logger.h"
bool
CalamaresUtils::Packages::setGSPackageAdditions( const Calamares::ModuleSystem::InstanceKey& module,
const QVariantList& installPackages,
const QVariantList& tryInstallPackages )
{
static const char PACKAGEOP[] = "packageOperations";
// Check if there's already a PACAKGEOP entry in GS, and if so we'll
// extend that one (overwriting the value in GS at the end of this method)
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
QVariantList packageOperations = gs->contains( PACKAGEOP ) ? gs->value( PACKAGEOP ).toList() : QVariantList();
cDebug() << "Existing package operations length" << packageOperations.length();
const QString key = module.toString() + QStringLiteral( ";add" );
// Clear out existing operations for this module, going backwards:
// Sometimes we remove an item, and we don't want the index to
// fall off the end of the list.
bool somethingRemoved = false;
for ( int index = packageOperations.length() - 1; 0 <= index; index-- )
{
const QVariantMap op = packageOperations.at( index ).toMap();
if ( op.contains( "source" ) && op.value( "source" ).toString() == key )
{
cDebug() << Logger::SubEntry << "Removing existing operations for" << key;
packageOperations.removeAt( index );
somethingRemoved = true;
}
}
if ( !installPackages.empty() )
{
QVariantMap op;
op.insert( "install", QVariant( installPackages ) );
op.insert( "source", key );
packageOperations.append( op );
cDebug() << Logger::SubEntry << installPackages.length() << "critical packages.";
}
if ( !tryInstallPackages.empty() )
{
QVariantMap op;
op.insert( "try_install", QVariant( tryInstallPackages ) );
op.insert( "source", key );
packageOperations.append( op );
cDebug() << Logger::SubEntry << tryInstallPackages.length() << "non-critical packages.";
}
if ( somethingRemoved || !packageOperations.isEmpty() )
{
gs->insert( PACKAGEOP, packageOperations );
return true;
}
return false;
}

View File

@ -0,0 +1,32 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#ifndef LIBCALAMARES_PACKAGES_GLOBALS_H
#define LIBCALAMARES_PACKAGES_GLOBALS_H
#include "modulesystem/InstanceKey.h"
namespace CalamaresUtils
{
namespace Packages
{
/** @brief Sets the install-packages GS keys for the given module
*
* This replaces previously-set install-packages lists for the
* given module by the two new lists.
*/
bool setGSPackageAdditions( const Calamares::ModuleSystem::InstanceKey& module,
const QVariantList& installPackages,
const QVariantList& tryInstallPackages );
// void setGSPackageRemovals( const Calamares::ModuleSystem::InstanceKey& key, const QVariantList& removePackages );
} // namespace Packages
} // namespace CalamaresUtils
#endif

View File

@ -0,0 +1,44 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#include "utils/Logger.h"
#include "GlobalStorage.h"
#include <QtTest/QtTest>
class PackagesTests : public QObject
{
Q_OBJECT
public:
PackagesTests() {}
~PackagesTests() override {}
private Q_SLOTS:
void initTestCase();
void testEmpty();
};
void
PackagesTests::initTestCase()
{
Logger::setupLogLevel( Logger::LOGDEBUG );
}
void
PackagesTests::testEmpty()
{
}
QTEST_GUILESS_MAIN( PackagesTests )
#include "utils/moc-warnings.h"
#include "Tests.moc"