[libcalamares] Start a packages service for netinstall and others
This commit is contained in:
parent
6662cb5f2d
commit
b868894371
@ -59,6 +59,9 @@ set( libSources
|
||||
# Network service
|
||||
network/Manager.cpp
|
||||
|
||||
# Packages service
|
||||
packages/Globals.cpp
|
||||
|
||||
# Partition service
|
||||
partition/Mount.cpp
|
||||
partition/PartitionSize.cpp
|
||||
@ -228,6 +231,12 @@ calamares_add_test(
|
||||
network/Tests.cpp
|
||||
)
|
||||
|
||||
calamares_add_test(
|
||||
libcalamarespackagestest
|
||||
SOURCES
|
||||
packages/Tests.cpp
|
||||
)
|
||||
|
||||
calamares_add_test(
|
||||
libcalamarespartitiontest
|
||||
SOURCES
|
||||
|
69
src/libcalamares/packages/Globals.cpp
Normal file
69
src/libcalamares/packages/Globals.cpp
Normal 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;
|
||||
}
|
32
src/libcalamares/packages/Globals.h
Normal file
32
src/libcalamares/packages/Globals.h
Normal 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
|
44
src/libcalamares/packages/Tests.cpp
Normal file
44
src/libcalamares/packages/Tests.cpp
Normal 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"
|
Loading…
Reference in New Issue
Block a user