Made possible to select flatpaks to install (fill list of netinstall)
This commit is contained in:
parent
d77215c227
commit
cc90dcf556
17
src/modules/flatpakinfo/CMakeLists.txt
Normal file
17
src/modules/flatpakinfo/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
# === This file is part of Calamares - <https://calamares.io> ===
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
calamares_add_plugin(flatpakInfo
|
||||
TYPE job
|
||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
SOURCES
|
||||
flatpakInfoJob.h
|
||||
ItemFlatpak.h
|
||||
PackagePool.h
|
||||
flatpakInfoJob.cpp
|
||||
ItemFlatpak.cpp
|
||||
PackagePool.cpp
|
||||
SHARED_LIB
|
||||
)
|
32
src/modules/flatpakinfo/ItemFlatpak.cpp
Normal file
32
src/modules/flatpakinfo/ItemFlatpak.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
#include "ItemFlatpak.h"
|
||||
|
||||
PackageItem
|
||||
fromFlatpak( const QVariantMap& item_map )
|
||||
{
|
||||
// check if it is installed
|
||||
PackageItem item(CalamaresUtils::getString( item_map, "appstream" ));
|
||||
int status;
|
||||
int pid = fork();
|
||||
if (0 == pid)
|
||||
{
|
||||
execlp("flatpak", "flatpak", "info", item.getAppStreamId().toStdString().c_str(), NULL);
|
||||
}
|
||||
waitpid(pid, &status, 0);
|
||||
|
||||
if (WEXITSTATUS(status) == 0)
|
||||
{
|
||||
item.setInstalled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.setInstalled(false);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
47
src/modules/flatpakinfo/ItemFlatpak.h
Normal file
47
src/modules/flatpakinfo/ItemFlatpak.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ITEMFLATPAK_H
|
||||
#define ITEMFLATPAK_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
|
||||
class PackageItem
|
||||
{
|
||||
public:
|
||||
PackageItem(QString appstreamid):
|
||||
appstreamid(appstreamid),
|
||||
installed(false)
|
||||
{
|
||||
|
||||
}
|
||||
QString& getAppStreamId(void)
|
||||
{
|
||||
return this->appstreamid;
|
||||
}
|
||||
void setInstalled(bool installed)
|
||||
{
|
||||
this->installed = installed;
|
||||
}
|
||||
bool getInstalled(void)
|
||||
{
|
||||
return this->installed;
|
||||
}
|
||||
private:
|
||||
QString appstreamid;
|
||||
bool installed;
|
||||
};
|
||||
|
||||
|
||||
|
||||
PackageItem fromFlatpak( const QVariantMap& map );
|
||||
|
||||
#endif
|
90
src/modules/flatpakinfo/PackagePool.cpp
Normal file
90
src/modules/flatpakinfo/PackagePool.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
#include <ext/stdio_filebuf.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QDesktopServices>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
#include "packages/Globals.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
#include "ItemFlatpak.h"
|
||||
|
||||
|
||||
void serializePackagesInfo(void);
|
||||
|
||||
QVector < PackageItem > packages;
|
||||
|
||||
void downloadPackagesInfo(void)
|
||||
{
|
||||
int pid;
|
||||
int pipefd[2];
|
||||
bool poolOk = false;
|
||||
pipe(pipefd);
|
||||
|
||||
pid = fork();
|
||||
if (0 == pid)
|
||||
{
|
||||
close(pipefd[0]);
|
||||
dup2(pipefd[1], 1);
|
||||
execlp("flatpak", "flatpak", "search", "--columns=application", "", NULL);
|
||||
exit(1);
|
||||
}
|
||||
close(pipefd[1]);
|
||||
|
||||
std::string line;
|
||||
__gnu_cxx::stdio_filebuf<char> filebuf(pipefd[0], std::ios::in);
|
||||
std::istream stream(&filebuf);
|
||||
|
||||
while (!stream.eof())
|
||||
{
|
||||
getline(stream, line);
|
||||
QVariantMap item_map;
|
||||
|
||||
//std::cerr << line;
|
||||
item_map.insert("appstream", QVariant(QString::fromStdString(line)));
|
||||
item_map.insert("id", QVariant(QString::fromStdString(line)));
|
||||
|
||||
PackageItem item = fromFlatpak(item_map);
|
||||
packages.append(item);
|
||||
}
|
||||
|
||||
waitpid(pid, nullptr, 0);
|
||||
|
||||
serializePackagesInfo();
|
||||
}
|
||||
|
||||
void serializePackagesInfo(void)
|
||||
{
|
||||
QList<QVariant> changedValue;
|
||||
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||
|
||||
// If an earlier packagechooser instance added this data to global storage, combine them
|
||||
if ( gs->contains( "groups" ) )
|
||||
{
|
||||
auto selectedOrig = gs->value( "groups" );
|
||||
|
||||
changedValue = selectedOrig.toList();
|
||||
for (auto current: packages)
|
||||
{
|
||||
QStringList selfInstall;
|
||||
QVariantMap newValue;
|
||||
newValue.insert("name", current.getAppStreamId());
|
||||
|
||||
selfInstall.append(current.getAppStreamId());
|
||||
newValue.insert("packages", selfInstall);
|
||||
changedValue.append(newValue);
|
||||
}
|
||||
|
||||
gs->remove( "groups" );
|
||||
}
|
||||
gs->insert( "gropus", changedValue );
|
||||
}
|
15
src/modules/flatpakinfo/PackagePool.h
Normal file
15
src/modules/flatpakinfo/PackagePool.h
Normal file
@ -0,0 +1,15 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Evan James <dalto@fastmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*/
|
||||
|
||||
#ifndef ___PACKAGEPOOL__H___
|
||||
#define ___PACKAGEPOOL__H___
|
||||
|
||||
void downloadPackagesInfo(void);
|
||||
void serializePackagesInfo(void);
|
||||
|
||||
#endif
|
8
src/modules/flatpakinfo/flatpakInfo.cfg
Normal file
8
src/modules/flatpakinfo/flatpakInfo.cfg
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
# The zfs module creates the zfs pools and datasets
|
||||
#
|
||||
#
|
||||
#
|
||||
---
|
59
src/modules/flatpakinfo/flatpakInfoJob.cpp
Normal file
59
src/modules/flatpakinfo/flatpakInfoJob.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Evan James <dalto@fastmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "flatpakInfoJob.h"
|
||||
|
||||
#include "utils/CalamaresUtilsSystem.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "PackagePool.h"
|
||||
|
||||
FlatpakInfoJob::FlatpakInfoJob( QObject* parent )
|
||||
: Calamares::CppJob( parent )
|
||||
{
|
||||
}
|
||||
|
||||
FlatpakInfoJob::~FlatpakInfoJob() {}
|
||||
|
||||
QString
|
||||
FlatpakInfoJob::prettyName() const
|
||||
{
|
||||
return tr( "Fill netinstall with flatpak packages" );
|
||||
}
|
||||
|
||||
|
||||
Calamares::JobResult
|
||||
FlatpakInfoJob::exec()
|
||||
{
|
||||
QVariantList partitions;
|
||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||
|
||||
|
||||
downloadPackagesInfo();
|
||||
|
||||
return Calamares::JobResult::ok();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FlatpakInfoJob::setConfigurationMap( const QVariantMap& map )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( FlatpakInfoJobFactory, registerPlugin< FlatpakInfoJob >(); )
|
43
src/modules/flatpakinfo/flatpakInfoJob.h
Normal file
43
src/modules/flatpakinfo/flatpakInfoJob.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Evan James <dalto@fastmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FLATPAKINFOJOB_H
|
||||
#define FLATPAKINFOJOB_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "CppJob.h"
|
||||
|
||||
#include "utils/PluginFactory.h"
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
/** @brief Create zpools and zfs datasets
|
||||
*
|
||||
*/
|
||||
class PLUGINDLLEXPORT FlatpakInfoJob : public Calamares::CppJob
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FlatpakInfoJob( QObject* parent = nullptr );
|
||||
~FlatpakInfoJob() override;
|
||||
|
||||
QString prettyName() const override;
|
||||
|
||||
Calamares::JobResult exec() override;
|
||||
|
||||
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
||||
};
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( FlatpakInfoJobFactory )
|
||||
|
||||
#endif // ZFSJOB_H
|
7
src/modules/flatpakinfo/module.desc
Normal file
7
src/modules/flatpakinfo/module.desc
Normal file
@ -0,0 +1,7 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
---
|
||||
type: "job"
|
||||
name: "flatpakinfo"
|
||||
interface: "qtplugin"
|
||||
load: "libcalamares_job_flatpakInfo.so"
|
Loading…
Reference in New Issue
Block a user