-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from nintyfan/FlatpakPuller
Flatpak puller
- Loading branch information
Showing
9 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# === This file is part of Calamares - <https://calamares.io> === | ||
# | ||
# SPDX-FileCopyrightText: 2020 Adriaan de Groot <[email protected]> | ||
# 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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* === This file is part of Calamares - <https://calamares.io> === | ||
* | ||
* SPDX-FileCopyrightText: 2023 Sławomir Lach <[email protected]> | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
* Calamares is Free Software: see the License-Identifier above. | ||
* | ||
*/ | ||
|
||
#include "FlatpakInfoJob.h" | ||
|
||
#include "utils/Runner.h" | ||
#include "utils/Logger.h" | ||
#include "utils/Variant.h" | ||
|
||
#include "GlobalStorage.h" | ||
#include "JobQueue.h" | ||
#include "Settings.h" | ||
|
||
#include <QProcess> | ||
|
||
#include <unistd.h> | ||
|
||
#include "ItemFlatpak.h" | ||
#include "PackagePool.h" | ||
|
||
FlatpakInfoJob::FlatpakInfoJob( QObject* parent ) | ||
: Calamares::CppJob( parent ) | ||
{ | ||
} | ||
|
||
FlatpakInfoJob::~FlatpakInfoJob() | ||
{ | ||
ItemFlatpak_freeMem(); | ||
} | ||
|
||
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(); | ||
serializePackagesInfo(); | ||
|
||
return Calamares::JobResult::ok(); | ||
} | ||
|
||
|
||
void | ||
FlatpakInfoJob::setConfigurationMap( const QVariantMap& map ) | ||
{ | ||
} | ||
|
||
CALAMARES_PLUGIN_FACTORY_DEFINITION( FlatpakInfoJobFactory, registerPlugin< FlatpakInfoJob >(); ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* === This file is part of Calamares - <https://calamares.io> === | ||
* | ||
* SPDX-FileCopyrightText: 2023 Sławomir Lach <[email protected]> | ||
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* === This file is part of Calamares - <https://calamares.io> === | ||
* | ||
* SPDX-FileCopyrightText: 2023 Sławomir Lach <[email protected]> | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
* Calamares is Free Software: see the License-Identifier above. | ||
* | ||
*/ | ||
|
||
/* Qt */ | ||
#include <QVariantMap> | ||
|
||
/* CPP */ | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
/* Calamares */ | ||
#include "utils/Runner.h" | ||
|
||
/* Module */ | ||
#include "ItemFlatpak.h" | ||
#include "utils/Logger.h" | ||
#include "utils/Variant.h" | ||
|
||
PackageItem | ||
fromFlatpak( const QVariantMap& itemMap, InstalledList &installed ) | ||
{ | ||
// check if it is installed | ||
PackageItem item( Calamares::getString( itemMap, "appstream" ) ); | ||
item.setInstalled( false ); | ||
|
||
item.setInstalled( installed.contains( Calamares::getString( itemMap, "appstream" ) ) ); | ||
|
||
return item; | ||
} | ||
|
||
InstalledList::InstalledList() | ||
{ | ||
long long int prev_pos; | ||
long long int pos = 0; | ||
QString line; | ||
auto process = Calamares::System::instance()->targetEnvCommand( | ||
QStringList { QString::fromLatin1( "flatpak" ), | ||
QString::fromLatin1( "list" ), | ||
QString::fromLatin1( "--app" ), | ||
QString::fromLatin1( "--columns=application" ) } ); | ||
auto outputStr = process.second; | ||
|
||
do { | ||
prev_pos = pos; | ||
|
||
pos = outputStr.indexOf('\n', prev_pos); | ||
QString line = outputStr.mid(prev_pos, pos); | ||
installed.append(line); | ||
|
||
/* Increase by 1 to not stuck on newline */ | ||
++pos; | ||
|
||
/* QString::indexOf returns -1 since no occurences. 0 = -1 + 1.*/ | ||
} while (0 != pos); | ||
} | ||
|
||
InstalledList::~InstalledList() | ||
{ | ||
installed.clear(); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* === This file is part of Calamares - <https://calamares.io> === | ||
* | ||
* SPDX-FileCopyrightText: 2023 Sławomir Lach <[email protected]> | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
* Calamares is Free Software: see the License-Identifier above. | ||
*/ | ||
|
||
#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 "utils/Logger.h" | ||
#include "utils/Variant.h" | ||
#include "ItemFlatpak.h" | ||
#include "PackagePool.h" | ||
|
||
#include "utils/System.h" | ||
|
||
void PackagePool::downloadPackagesInfo(InstalledList &list) | ||
{ | ||
QHash<QString,bool> addedPackages; | ||
QString line; | ||
auto process = Calamares::System::instance()->targetEnvCommand( QStringList { QString::fromStdString( "flatpak" ), QString::fromStdString( "remotes" ), QString::fromStdString( "--columns=name" ) }); | ||
auto outputStr = process.second; | ||
QTextStream output(&outputStr); | ||
|
||
while (output.readLineInto(&line)) | ||
{ | ||
QString line2; | ||
auto process2 = Calamares::System::instance()->targetEnvCommand( | ||
QStringList { QString::fromStdString( "flatpak" ), | ||
QString::fromStdString( "remote-ls" ), | ||
QString::fromStdString( "--app" ), | ||
QString::fromStdString( "--columns=application" ), | ||
line } ); | ||
auto output2Str = process2.second; | ||
QTextStream output2( &output2Str ); | ||
|
||
while ( output2.readLineInto( &line2 ) ) | ||
{ | ||
if ( line2 == "" ) | ||
{ | ||
continue; | ||
} | ||
QVariantMap itemMap; | ||
|
||
if ( addedPackages.contains( line2 ) ) | ||
{ | ||
continue; | ||
} | ||
|
||
addedPackages.insert( line2, true ); | ||
|
||
itemMap.insert( "appstream", QVariant( line2 ) ); | ||
itemMap.insert( "id", QVariant( line2 ) ); | ||
|
||
PackageItem item = fromFlatpak( itemMap, list ); | ||
packages.append( item ); | ||
} | ||
} | ||
|
||
serializePackagesInfo(); | ||
} | ||
|
||
void PackagePool::serializePackagesInfo() | ||
{ | ||
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( "netinstallAdd" ) ) | ||
{ | ||
auto selectedOrig = gs->value( "netinstallAdd" ); | ||
|
||
changedValue = selectedOrig.toList(); | ||
for (auto current: packages) | ||
{ | ||
QStringList selfInstall; | ||
QVariantMap newValue; | ||
newValue.insert("name", current.getAppStreamId()); | ||
|
||
if (current.getInstalled()) | ||
{ | ||
newValue.insert("selected", true); | ||
newValue.insert("immutable", true); | ||
newValue.insert("description", "[Already installed; cannot be uninstalled]"); | ||
} | ||
else | ||
{ | ||
newValue.insert("selected", false); | ||
} | ||
selfInstall.append(current.getAppStreamId()); | ||
newValue.insert("packages", selfInstall); | ||
changedValue.append(newValue); | ||
} | ||
|
||
gs->remove( "netinstallAdd" ); | ||
} | ||
gs->insert( "netinstallAdd", changedValue ); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-FileCopyrightText: no | ||
# SPDX-License-Identifier: CC0-1.0 | ||
# | ||
# The flatpakinfo module will collect package list from configured flatpak repositories | ||
# | ||
# | ||
# | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: no | ||
# SPDX-License-Identifier: CC0-1.0 | ||
--- | ||
type: "job" | ||
name: "flatpakinfo" | ||
interface: "qtplugin" | ||
load: "libcalamares_job_flatpakInfo.so" |