From 98e565b8c3c1b1f0bb9ba5e1a9b8fa923273b4cf Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 7 Sep 2015 19:36:45 +0200 Subject: [PATCH] fixed includes, cli interface for upgrade lookup --- alpm/alpmdatabase.cpp | 10 +- alpm/alpmdatabase.h | 4 +- alpm/alpmpackage.cpp | 6 +- alpm/alpmpackage.h | 2 +- alpm/aurpackage.cpp | 4 +- alpm/aurpackage.h | 2 +- alpm/config.cpp | 10 +- alpm/group.cpp | 4 +- alpm/group.h | 4 +- alpm/manager.cpp | 12 +- alpm/manager.h | 4 +- alpm/mingwbundle.cpp | 8 +- alpm/mingwbundle.h | 4 +- alpm/package.cpp | 8 +- alpm/package.h | 2 +- alpm/repository.cpp | 6 +- alpm/repository.h | 4 +- alpm/resolvebuildorder.cpp | 16 ++- alpm/resolvebuildorder.h | 1 + alpm/upgradelookup.cpp | 239 ++++++++++++++++++++++++++++++++++--- alpm/upgradelookup.h | 77 +++++++++--- alpm/utilities.cpp | 22 +++- alpm/utilities.h | 7 +- main.cpp | 31 ++--- network/connection.cpp | 8 +- network/server.cpp | 2 +- network/userrepository.cpp | 2 +- network/userrepository.h | 4 +- web/js/repomanagement.js | 2 +- 29 files changed, 389 insertions(+), 116 deletions(-) diff --git a/alpm/alpmdatabase.cpp b/alpm/alpmdatabase.cpp index da7a3e0..71cd66d 100644 --- a/alpm/alpmdatabase.cpp +++ b/alpm/alpmdatabase.cpp @@ -1,8 +1,8 @@ -#include "alpmdatabase.h" -#include "group.h" -#include "upgradelookup.h" -#include "alpmpackage.h" -#include "utilities.h" +#include "./alpmdatabase.h" +#include "./group.h" +#include "./upgradelookup.h" +#include "./alpmpackage.h" +#include "./utilities.h" #include diff --git a/alpm/alpmdatabase.h b/alpm/alpmdatabase.h index 41d0204..376dec3 100644 --- a/alpm/alpmdatabase.h +++ b/alpm/alpmdatabase.h @@ -1,8 +1,8 @@ #ifndef ALPM_DATABASE_H #define ALPM_DATABASE_H -#include "repository.h" -#include "list.h" +#include "./repository.h" +#include "./list.h" #include #include diff --git a/alpm/alpmpackage.cpp b/alpm/alpmpackage.cpp index 34ab633..d050de1 100644 --- a/alpm/alpmpackage.cpp +++ b/alpm/alpmpackage.cpp @@ -1,6 +1,6 @@ -#include "alpmpackage.h" -#include "alpmdatabase.h" -#include "utilities.h" +#include "./alpmpackage.h" +#include "./alpmdatabase.h" +#include "./utilities.h" #include diff --git a/alpm/alpmpackage.h b/alpm/alpmpackage.h index 23daea9..1300d86 100644 --- a/alpm/alpmpackage.h +++ b/alpm/alpmpackage.h @@ -1,7 +1,7 @@ #ifndef PACKAGEMANAGEMENT_ALPMPACKAGE_H #define PACKAGEMANAGEMENT_ALPMPACKAGE_H -#include "package.h" +#include "./package.h" namespace RepoIndex { diff --git a/alpm/aurpackage.cpp b/alpm/aurpackage.cpp index f7294d8..bcddef7 100644 --- a/alpm/aurpackage.cpp +++ b/alpm/aurpackage.cpp @@ -1,6 +1,6 @@ -#include "aurpackage.h" +#include "./aurpackage.h" -#include "repoindex/network/userrepository.h" +#include "../network/userrepository.h" #include diff --git a/alpm/aurpackage.h b/alpm/aurpackage.h index eeab977..9c1f3ac 100644 --- a/alpm/aurpackage.h +++ b/alpm/aurpackage.h @@ -1,7 +1,7 @@ #ifndef PACKAGEMANAGEMENT_AURPACKAGE_H #define PACKAGEMANAGEMENT_AURPACKAGE_H -#include "package.h" +#include "./package.h" namespace RepoIndex { diff --git a/alpm/config.cpp b/alpm/config.cpp index 1442426..2f9a0fe 100644 --- a/alpm/config.cpp +++ b/alpm/config.cpp @@ -1,5 +1,5 @@ -#include "config.h" -#include "manager.h" +#include "./config.h" +#include "./manager.h" #include @@ -59,6 +59,8 @@ ConfigArgs::ConfigArgs(ArgumentParser &parser) : buildOrderArg.setValueNames(pkgValueNames); serverArg.setDenotesOperation(true); upgradeLookupArg.setDenotesOperation(true); + upgradeLookupArg.setRequiredValueCount(1); + upgradeLookupArg.setValueNames({"repo"}); mingwBundleArg.setDenotesOperation(true); mingwBundleArg.setRequiredValueCount(-1); mingwBundleArg.setValueNames(pkgValueNames); @@ -112,10 +114,10 @@ ConfigArgs::ConfigArgs(ArgumentParser &parser) : repoArg.setRequiredValueCount(1); repoArg.setValueNames({"repo name"}); serverArg.setSecondaryArguments({&rootdirArg, &dbpathArg, &pacmanConfArg, &certFileArg, &keyFileArg, &websocketAddrArg, &websocketPortArg, &insecureArg, &aurArg}); - upgradeLookupArg.setSecondaryArguments({&repoArg, &shSyntaxArg}); + upgradeLookupArg.setSecondaryArguments({&shSyntaxArg}); buildOrderArg.setSecondaryArguments({&aurArg, &verboseArg, &shSyntaxArg}); mingwBundleArg.setSecondaryArguments({&targetDirArg, &targetNameArg, &targetFormatArg, &iconThemesArg}); - parser.setMainArguments({&buildOrderArg, &serverArg, &mingwBundleArg, &repoindexConfArg, &repoindexConfArg, &helpArg}); + parser.setMainArguments({&buildOrderArg, &upgradeLookupArg, &serverArg, &mingwBundleArg, &repoindexConfArg, &repoindexConfArg, &helpArg}); } /*! diff --git a/alpm/group.cpp b/alpm/group.cpp index 1c0d317..10393e7 100644 --- a/alpm/group.cpp +++ b/alpm/group.cpp @@ -1,5 +1,5 @@ -#include "group.h" -#include "package.h" +#include "./group.h" +#include "./package.h" #include diff --git a/alpm/group.h b/alpm/group.h index 4422f7a..c7ab9b9 100644 --- a/alpm/group.h +++ b/alpm/group.h @@ -1,8 +1,8 @@ #ifndef ALPM_GROUP_H #define ALPM_GROUP_H -#include "list.h" -#include "package.h" +#include "./list.h" +#include "./package.h" #include diff --git a/alpm/manager.cpp b/alpm/manager.cpp index c72b646..3af13fd 100644 --- a/alpm/manager.cpp +++ b/alpm/manager.cpp @@ -1,10 +1,10 @@ -#include "manager.h" -#include "alpmdatabase.h" -#include "utilities.h" -#include "list.h" -#include "config.h" +#include "./manager.h" +#include "./alpmdatabase.h" +#include "./utilities.h" +#include "./list.h" +#include "./config.h" -#include "repoindex/network/userrepository.h" +#include "../network/userrepository.h" #include #include diff --git a/alpm/manager.h b/alpm/manager.h index b69e9fc..6437206 100644 --- a/alpm/manager.h +++ b/alpm/manager.h @@ -1,8 +1,8 @@ #ifndef ALPM_MANAGER_H #define ALPM_MANAGER_H -#include "upgradelookup.h" -#include "alpmpackage.h" +#include "./upgradelookup.h" +#include "./alpmpackage.h" #include diff --git a/alpm/mingwbundle.cpp b/alpm/mingwbundle.cpp index 4129e22..4ad2421 100644 --- a/alpm/mingwbundle.cpp +++ b/alpm/mingwbundle.cpp @@ -1,7 +1,7 @@ -#include "mingwbundle.h" -#include "utilities.h" -#include "manager.h" -#include "config.h" +#include "./mingwbundle.h" +#include "./utilities.h" +#include "./manager.h" +#include "./config.h" #include #include diff --git a/alpm/mingwbundle.h b/alpm/mingwbundle.h index 661f32a..ac48ef3 100644 --- a/alpm/mingwbundle.h +++ b/alpm/mingwbundle.h @@ -1,8 +1,8 @@ #ifndef PACKAGEMANAGEMENT_MINGWBUNDLE_H #define PACKAGEMANAGEMENT_MINGWBUNDLE_H -#include "package.h" -#include "alpmdatabase.h" +#include "./package.h" +#include "./alpmdatabase.h" #include diff --git a/alpm/package.cpp b/alpm/package.cpp index 661fbf3..603a947 100644 --- a/alpm/package.cpp +++ b/alpm/package.cpp @@ -1,7 +1,7 @@ -#include "package.h" -#include "alpmdatabase.h" -#include "utilities.h" -#include "repository.h" +#include "./package.h" +#include "./alpmdatabase.h" +#include "./utilities.h" +#include "./repository.h" #include #include diff --git a/alpm/package.h b/alpm/package.h index ef896b9..f967fb8 100644 --- a/alpm/package.h +++ b/alpm/package.h @@ -1,7 +1,7 @@ #ifndef ALPM_PACKAGE_H #define ALPM_PACKAGE_H -#include "list.h" +#include "./list.h" #include diff --git a/alpm/repository.cpp b/alpm/repository.cpp index 483900e..f331c1a 100644 --- a/alpm/repository.cpp +++ b/alpm/repository.cpp @@ -1,6 +1,6 @@ -#include "repository.h" -#include "upgradelookup.h" -#include "utilities.h" +#include "./repository.h" +#include "./upgradelookup.h" +#include "./utilities.h" #include #include diff --git a/alpm/repository.h b/alpm/repository.h index dd5f9a4..6869aa3 100644 --- a/alpm/repository.h +++ b/alpm/repository.h @@ -1,8 +1,8 @@ #ifndef PACKAGEMANAGEMENT_PACKAGESOURCE_H #define PACKAGEMANAGEMENT_PACKAGESOURCE_H -#include "package.h" -#include "group.h" +#include "./package.h" +#include "./group.h" #include diff --git a/alpm/resolvebuildorder.cpp b/alpm/resolvebuildorder.cpp index 02e2f2b..f9b2c2d 100644 --- a/alpm/resolvebuildorder.cpp +++ b/alpm/resolvebuildorder.cpp @@ -1,7 +1,8 @@ -#include "resolvebuildorder.h" +#include "./resolvebuildorder.h" -#include "manager.h" -#include "config.h" +#include "./manager.h" +#include "./config.h" +#include "./utilities.h" #include @@ -183,6 +184,15 @@ QStringList BuildOrderResolver::resolve(const StringVector &packages) const } } +void BuildOrderResolver::printResults(const QStringList &results) +{ + if(useShSyntax) { + Utilities::printBashArray(cout, "REPOINDEX_RESULTS", results); + } else { + Utilities::printValues(cout, "Results", results); + } +} + void BuildOrderResolver::addDeps(QList &tasks, TaskInfo *task) const { if(const auto pkg = m_manager.packageProviding(Dependency(task->name()))) { diff --git a/alpm/resolvebuildorder.h b/alpm/resolvebuildorder.h index ed85b05..bc511cf 100644 --- a/alpm/resolvebuildorder.h +++ b/alpm/resolvebuildorder.h @@ -18,6 +18,7 @@ public: BuildOrderResolver(const Manager &manager); QStringList resolve(const ApplicationUtilities::StringVector &packages) const; + static void printResults(const QStringList &results); private: void addDeps(QList &tasks, TaskInfo *task) const; diff --git a/alpm/upgradelookup.cpp b/alpm/upgradelookup.cpp index b9042c8..778d72b 100644 --- a/alpm/upgradelookup.cpp +++ b/alpm/upgradelookup.cpp @@ -1,24 +1,44 @@ -#include "upgradelookup.h" -#include "manager.h" -#include "alpmdatabase.h" -#include "config.h" +#include "./upgradelookup.h" +#include "./manager.h" +#include "./alpmdatabase.h" +#include "./config.h" +#include "./utilities.h" #include #include +#include using namespace std; namespace RepoIndex { +using namespace Utilities; + +/*! + * \class UpgradeResult + * \brief The UpgradeResult class wraps and upgrade/downgrade package and the current version. + */ + +/*! + * \brief Returns a JSON object for the current instance. + */ QJsonObject UpgradeResult::json() const { QJsonObject obj; obj.insert(QStringLiteral("pkg"), package->basicInfo(true)); - obj.insert(QStringLiteral("prevVersion"), previousVersion); + obj.insert(QStringLiteral("curVer"), currentVersion); return obj; } +/*! + * \class UpgradeLookupProcess + * \brief The UpgradeLookupProcess class performs an async upgrade lookup for a particular upgrade source. + */ + +/*! + * \brief Constructs a new upgrade lookup process. The upgrade lookup process is started immediately. + */ UpgradeLookupProcess::UpgradeLookupProcess(UpgradeLookup *upgradeLookup, const Repository *upgradeSource) : QObject(upgradeLookup), m_toCheck(upgradeLookup->toCheck()), @@ -49,11 +69,17 @@ UpgradeLookupProcess::UpgradeLookupProcess(UpgradeLookup *upgradeLookup, const R } } +/*! + * \brief Returns the results. Results are available, after the finished() signal has been emitted. + */ const UpgradeLookupResults &UpgradeLookupProcess::results() const { return m_results; } +/*! + * \brief Internally called when the upgrade source is ready. + */ void UpgradeLookupProcess::sourceReady() { // if a request was required, check whether there occured an error @@ -66,17 +92,78 @@ void UpgradeLookupProcess::sourceReady() } } +/*! + * \brief Internally called to perform the upgrade lookup. + */ void UpgradeLookupProcess::checkUpgrades() { m_toCheck->checkForUpgrades(m_results, QList() << m_upgradeSource); } -UpgradeLookup::UpgradeLookup(const Manager &manager, const QJsonObject &request, QObject *parent) : +/*! + * \class UpgradeLookup + * \brief The UpgradeLookup class performs an async upgrade lookup for using multiple upgrade sources. + * \remarks The object deletes itself after the lookup is done. + */ + +/*! + * \brief Constructs a new upgrade lookup (protected since this is a pure virtual class). + */ +UpgradeLookup::UpgradeLookup(QObject *parent) : QObject(parent), - m_request(request), m_toCheck(nullptr), m_remainingProcesses(0), m_firstFinished(false) +{} + +/*! + * \fn UpgradeLookup::processFinished() + * \brief Internally called when the finished() signal of an UpgradeLookupProcess instance is emitted. + */ + +/*! + * \class UpgradeLookupJson + * \brief The UpgradeLookupJson class performs an async upgrade lookup for using multiple upgrade sources. + * + * The request and the results are in JSON. + * + * Example request: + * { + * db: "repo", repository to be checked + * syncdbs: ["extra", "community"] upgrade sources to be used + * } + * + * Example result: + * { + * softwareUpdates: [ software upgrades + * {pkg: ..., basic info of package providing upgrade + * curVer: current version + * ], + * packageOnlyUpdates: [ package-only upgrades + * {pkg: ..., basic info of package providing upgrade + * curVer: current version + * ], + * downgrades: [ downgrades + * {pkg: ..., basic info of package providing downgrade + * curVer: current version + * ] + * orphanedPackages: [ ... ] basic info of orphaned packages + * warnings: [ ... ] warnings + * errors: [ ... ] errors + * } + */ + +/*! + * \fn UpgradeLookupJson::resultsAvailable() + * \brief Emitted when all results are availabe (also in the error case). + */ + +/*! + * \brief Constructs a new upgrade lookup for the specified \a request using the specified \a manager. + */ +UpgradeLookupJson::UpgradeLookupJson(const Manager &manager, const QJsonObject &request, QObject *parent) : + UpgradeLookup(parent), + m_request(request) { const auto toCheckName = request.value(QStringLiteral("db")).toString(); if((m_toCheck = manager.repositoryByName(toCheckName))) { @@ -114,19 +201,19 @@ UpgradeLookup::UpgradeLookup(const Manager &manager, const QJsonObject &request, deleteLater(); } -void UpgradeLookup::processFinished() +void UpgradeLookupJson::processFinished() { assert(m_remainingProcesses); // add results const auto &results = static_cast(sender())->results(); - for(const auto pkg : results.newVersions) { - m_softwareUpdatesArray << pkg.json(); + for(const auto &res : results.newVersions) { + m_softwareUpgradesArray << res.json(); } - for(const auto pkg : results.newReleases) { - m_packageOnlyUpdatesArray << pkg.json(); + for(const auto &res : results.newReleases) { + m_packageOnlyUpgradesArray << res.json(); } - for(const auto pkg : results.downgrades) { - m_downgradesArray << pkg.json(); + for(const auto &res : results.downgrades) { + m_downgradesArray << res.json(); } for(const auto &warning : results.warnings) { m_warningsArray << warning; @@ -148,8 +235,8 @@ void UpgradeLookup::processFinished() } // add results to results QJsonObject QJsonObject results; - results.insert(QStringLiteral("softwareUpdates"), m_softwareUpdatesArray); - results.insert(QStringLiteral("packageOnlyUpdates"), m_packageOnlyUpdatesArray); + results.insert(QStringLiteral("softwareUpdates"), m_softwareUpgradesArray); + results.insert(QStringLiteral("packageOnlyUpdates"), m_packageOnlyUpgradesArray); results.insert(QStringLiteral("downgrades"), m_downgradesArray); results.insert(QStringLiteral("orphanedPackages"), m_orphanedPackagesArray); if(!m_warningsArray.isEmpty()) { @@ -164,4 +251,124 @@ void UpgradeLookup::processFinished() } } +/*! + * \class UpgradeLookupCli + * \brief The UpgradeLookupJson class performs an async upgrade lookup for using multiple upgrade sources. + * + * The repository to be checked is specified as string. Results are printed to cerr/cout. + */ + +/*! + * \brief Constructs a new upgrade lookup for the specified \a db using the specified \a manager. + */ +UpgradeLookupCli::UpgradeLookupCli(const Manager &manager, const string &repo, QObject *parent) : + UpgradeLookup(parent) +{ + cerr << shchar << "Checking upgrades for \"" << repo << "\" ..." << endl; + const auto toCheckName = qstr(repo); + if((m_toCheck = manager.repositoryByName(toCheckName))) { + // construct upgrade lookup processes + for(const auto *src : m_toCheck->upgradeSources()) { + new UpgradeLookupProcess(this, src); + ++m_remainingProcesses; + } + // check whether any processes could be constructed + if(!m_remainingProcesses) { + m_errorsArray << QStringLiteral("No upgrade sources associated for repository \"%1\".").arg(m_toCheck->name()); + } else { + return; // no errors so far + } + } else { + m_errorsArray << QStringLiteral("Repository \"%1\" can not be found.").arg(toCheckName); + } + printResults(); // print errors +} + +void UpgradeLookupCli::processFinished() +{ + assert(m_remainingProcesses); + // add results + const auto &results = static_cast(sender())->results(); + m_softwareUpgradesArray.reserve(m_softwareUpgradesArray.size() + results.newVersions.size()); + m_packageOnlyUpgradesArray.reserve(m_packageOnlyUpgradesArray.size() + results.newReleases.size()); + m_downgradesArray.reserve(m_downgradesArray.size() + results.downgrades.size()); + m_warningsArray.reserve(m_warningsArray.size() + results.warnings.size()); + m_errorsArray.reserve(m_errorsArray.size() + results.errors.size()); + for(const auto &res : results.newVersions) { + m_softwareUpgradesArray << res.package->name(); + } + for(const auto &res : results.newReleases) { + m_packageOnlyUpgradesArray << res.package->name(); + } + for(const auto &res : results.downgrades) { + m_downgradesArray << res.package->name(); + } + for(const auto &warning : results.warnings) { + m_warningsArray << warning; + } + for(const auto &error : results.errors) { + m_errorsArray << error; + } + if(m_firstFinished) { + m_orphanedPackages = m_orphanedPackages.intersect(results.orphaned); + } else { + m_firstFinished = true; + m_orphanedPackages = results.orphaned; + } + // check whether all processes are finished + if(--m_remainingProcesses == 0) { + // finally make info for orphanded packages + m_orphanedPackagesArray.reserve(m_orphanedPackages.size()); + for(const auto *pkg : m_orphanedPackages) { + m_orphanedPackagesArray << pkg->name(); + } + printResults(); + } +} + +void UpgradeLookupCli::printResults() +{ + if(useShSyntax) { + if(!m_errorsArray.isEmpty()) { + Utilities::printBashArray(cerr, "REPOINDEX_ERRORS", m_errorsArray); + } + if(!m_warningsArray.isEmpty()) { + Utilities::printBashArray(cerr, "REPOINDEX_WARNINGS", m_warningsArray); + } + if(!m_softwareUpgradesArray.isEmpty()) { + Utilities::printBashArray(cout, "REPOINDEX_RESULTS_SOFTWARE_UPGRADES", m_softwareUpgradesArray); + } + if(!m_packageOnlyUpgradesArray.isEmpty()) { + Utilities::printBashArray(cout, "REPOINDEX_RESULTS_PACKAGE_UPGRADES", m_packageOnlyUpgradesArray); + } + if(!m_downgradesArray.isEmpty()) { + Utilities::printBashArray(cout, "REPOINDEX_RESULTS_DOWNGRADES", m_downgradesArray); + } + if(!m_orphanedPackagesArray.isEmpty()) { + Utilities::printBashArray(cout, "REPOINDEX_RESULTS_ORPHANED", m_orphanedPackagesArray); + } + } else { + if(!m_errorsArray.isEmpty()) { + Utilities::printValues(cerr, "Errors", m_errorsArray); + } + if(!m_warningsArray.isEmpty()) { + Utilities::printValues(cerr, "Warnings", m_warningsArray); + } + if(!m_softwareUpgradesArray.isEmpty()) { + Utilities::printValues(cout, "Software upgrades", m_softwareUpgradesArray); + } + if(!m_packageOnlyUpgradesArray.isEmpty()) { + Utilities::printValues(cout, "Package upgrades", m_packageOnlyUpgradesArray); + } + if(!m_downgradesArray.isEmpty()) { + Utilities::printValues(cout, "Downgrades", m_downgradesArray); + } + if(!m_orphanedPackagesArray.isEmpty()) { + Utilities::printValues(cout, "Orphaned packages", m_orphanedPackagesArray); + } + } + // lookup done, delete this helper object + deleteLater(); +} + } // namespace PackageManagement diff --git a/alpm/upgradelookup.h b/alpm/upgradelookup.h index 65e51ca..7ce4354 100644 --- a/alpm/upgradelookup.h +++ b/alpm/upgradelookup.h @@ -1,7 +1,7 @@ #ifndef PACKAGEMANAGEMENT_UPDATELOOKUP_H #define PACKAGEMANAGEMENT_UPDATELOOKUP_H -#include "package.h" +#include "./package.h" #include #include @@ -18,15 +18,18 @@ class PackageReply; class UpgradeResult { public: - UpgradeResult(const Package *package, const QString &previousVersion); + UpgradeResult(const Package *package, const QString ¤tVersion); const Package *package; - QString previousVersion; + QString currentVersion; QJsonObject json() const; }; +/*! + * \brief Constructs a new upgrade result. + */ inline UpgradeResult::UpgradeResult(const Package *package, const QString &previousVersion) : package(package), - previousVersion(previousVersion) + currentVersion(previousVersion) {} class UpgradeLookupResults @@ -103,35 +106,75 @@ class UpgradeLookup : public QObject { Q_OBJECT friend class UpgradeLookupProcess; + public: - explicit UpgradeLookup(const Manager &manager, const QJsonObject &request, QObject *parent = nullptr); const Repository *toCheck() const; -signals: - void resultsAvailable(const QJsonValue &what, const QJsonValue &id, const QJsonValue &value); - private slots: - void processFinished(); + virtual void processFinished() = 0; + +protected: + explicit UpgradeLookup(QObject *parent = nullptr); -private: - const QJsonObject m_request; const Repository *m_toCheck; unsigned int m_remainingProcesses; bool m_firstFinished; QSet m_orphanedPackages; - QJsonArray m_warningsArray; - QJsonArray m_errorsArray; - QJsonArray m_softwareUpdatesArray; - QJsonArray m_packageOnlyUpdatesArray; - QJsonArray m_downgradesArray; - QJsonArray m_orphanedPackagesArray; }; +/*! + * \brief Returns the repository to be checked (if available; otherwise nullptr). + */ inline const Repository *UpgradeLookup::toCheck() const { return m_toCheck; } +class UpgradeLookupJson : public UpgradeLookup +{ + Q_OBJECT +public: + explicit UpgradeLookupJson(const Manager &manager, const QJsonObject &request, QObject *parent = nullptr); + +signals: + void resultsAvailable(const QJsonValue &what, const QJsonValue &id, const QJsonValue &value); + +private slots: + virtual void processFinished(); + +private: + const QJsonObject m_request; + QJsonArray m_warningsArray; + QJsonArray m_errorsArray; + QJsonArray m_softwareUpgradesArray; + QJsonArray m_packageOnlyUpgradesArray; + QJsonArray m_downgradesArray; + QJsonArray m_orphanedPackagesArray; +}; + +class UpgradeLookupCli : public UpgradeLookup +{ + Q_OBJECT + friend class UpgradeLookupProcess; +public: + explicit UpgradeLookupCli(const Manager &manager, const std::string &repo, QObject *parent = nullptr); + const Repository *toCheck() const; + +private slots: + void processFinished(); + +private: + void printResults(); + + QStringList m_warningsArray; + QStringList m_errorsArray; + QStringList m_softwareUpgradesArray; + QStringList m_packageOnlyUpgradesArray; + QStringList m_downgradesArray; + QStringList m_orphanedPackagesArray; +}; + + } // namespace PackageManagement #endif // PACKAGEMANAGEMENT_UPDATELOOKUP_H diff --git a/alpm/utilities.cpp b/alpm/utilities.cpp index bd2920f..dcad57b 100644 --- a/alpm/utilities.cpp +++ b/alpm/utilities.cpp @@ -1,9 +1,11 @@ -#include "utilities.h" +#include "./utilities.h" #include #include #include +#include + using namespace std; namespace RepoIndex { @@ -202,6 +204,24 @@ QStringList qstrlist(StringList list) return strings; } +void printValues(ostream &output, const char *label, const QStringList &values) +{ + output << label << ':'; + for(const auto &value : values) { + output << ' ' << value.toLocal8Bit().data(); + } + output << endl; +} + +void printBashArray(ostream &output, const char *name, const QStringList &values) +{ + output << "export " << name << '=' << '('; + for(const auto &value : values) { + output << ' ' << '\'' << value.toLocal8Bit().data() << '\''; + } + output << ' ' << ')' << endl; +} + } } // namespace Alpm diff --git a/alpm/utilities.h b/alpm/utilities.h index f69cb2b..235842f 100644 --- a/alpm/utilities.h +++ b/alpm/utilities.h @@ -1,7 +1,7 @@ #ifndef ALPM_UTILITIES_H #define ALPM_UTILITIES_H -#include "list.h" +#include "./list.h" #include @@ -15,7 +15,6 @@ namespace RepoIndex { namespace Utilities { std::list getNames(DependencyList dependencyList); - QJsonArray sigLevelStrings(alpm_siglevel_t sigLevel); QJsonArray usageStrings(alpm_db_usage_t usage); QString sigStatusString(alpm_sigstatus_t sigStatus); @@ -36,6 +35,10 @@ inline QString qstr(const std::string &str) return QString::fromLocal8Bit(str.data()); } +void printValues(std::ostream &output, const char *label, const QStringList &values); + +void printBashArray(std::ostream &output, const char *name, const QStringList &values); + } } // namespace Alpm diff --git a/main.cpp b/main.cpp index f41e40f..23f05ed 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,10 @@ -#include "repoindex/alpm/manager.h" -#include "repoindex/alpm/utilities.h" -#include "repoindex/alpm/config.h" -#include "repoindex/alpm/resolvebuildorder.h" -#include "repoindex/alpm/mingwbundle.h" +#include "./alpm/manager.h" +#include "./alpm/utilities.h" +#include "./alpm/config.h" +#include "./alpm/resolvebuildorder.h" +#include "./alpm/mingwbundle.h" -#include "repoindex/network/server.h" +#include "./network/server.h" #include #include @@ -64,28 +64,15 @@ int main(int argc, char *argv[]) return application.exec(); } else if(configArgs.buildOrderArg.isPresent()) { BuildOrderResolver resolver(manager); - const QStringList results = resolver.resolve(configArgs.buildOrderArg.values()); - // print results - if(useShSyntax) { - cout << "export REPOINDEX_RESULTS=("; - for(const auto &pkgName : results) { - cout << ' ' << '\'' << pkgName.toLocal8Bit().data() << '\''; - } - cout << ' ' << ')' << endl; - } else { - cout << "Results: "; - for(const auto &pkgName : results) { - cout << pkgName.toLocal8Bit().data() << ' '; - } - cout << endl; - } + BuildOrderResolver::printResults(resolver.resolve(configArgs.buildOrderArg.values())); } else if(configArgs.mingwBundleArg.isPresent()) { MingwBundle bundle(manager, configArgs.mingwBundleArg.values(), configArgs.iconThemesArg.values()); bundle.createBundle(configArgs.targetDirArg.isPresent() ? configArgs.targetDirArg.values().front() : string("."), configArgs.targetNameArg.values().front(), configArgs.targetFormatArg.isPresent() ? configArgs.targetFormatArg.values().front() : string("zip")); } else if(configArgs.upgradeLookupArg.isPresent()) { - cerr << shchar << "TODO" << endl; + QObject::connect(new UpgradeLookupCli(manager, configArgs.upgradeLookupArg.values().front()), &QObject::destroyed, &application, &QCoreApplication::quit); + return application.exec(); } } else if(!configArgs.helpArg.isPresent()) { if(useShSyntax) { diff --git a/network/connection.cpp b/network/connection.cpp index b643afa..0cda69c 100644 --- a/network/connection.cpp +++ b/network/connection.cpp @@ -1,7 +1,7 @@ -#include "connection.h" +#include "./connection.h" -#include "alpm/manager.h" -#include "alpm/upgradelookup.h" +#include "../alpm/manager.h" +#include "../alpm/upgradelookup.h" #include #include @@ -75,7 +75,7 @@ void Connection::handleQuery(const QJsonObject &obj) m_groupInfoUpdatesRequested = obj.value(QStringLiteral("updates")).toBool(m_groupInfoUpdatesRequested); sendResults(what, id, m_alpmManager.groupInfo()); } else if(what == QLatin1String("checkforupdates")) { - connect(new UpgradeLookup(m_alpmManager, obj), &UpgradeLookup::resultsAvailable, this, &Connection::sendResult); + connect(new UpgradeLookupJson(m_alpmManager, obj), &UpgradeLookupJson::resultsAvailable, this, &Connection::sendResult); } else if(what == QLatin1String("ping")) { sendResult(what, id, QStringLiteral("pong")); } else { diff --git a/network/server.cpp b/network/server.cpp index c911cb1..712e930 100644 --- a/network/server.cpp +++ b/network/server.cpp @@ -1,7 +1,7 @@ #include "server.h" #include "connection.h" -#include "alpm/config.h" +#include "../alpm/config.h" #include #include diff --git a/network/userrepository.cpp b/network/userrepository.cpp index b86161c..0a6e951 100644 --- a/network/userrepository.cpp +++ b/network/userrepository.cpp @@ -1,6 +1,6 @@ #include "userrepository.h" -#include "alpm/aurpackage.h" +#include "../alpm/aurpackage.h" #include diff --git a/network/userrepository.h b/network/userrepository.h index 2d33011..7005ef6 100644 --- a/network/userrepository.h +++ b/network/userrepository.h @@ -1,8 +1,8 @@ #ifndef ALPM_USER_REPOSITORY_H #define ALPM_USER_REPOSITORY_H -#include "repoindex/alpm/package.h" -#include "repoindex/alpm/repository.h" +#include "./alpm/package.h" +#include "./alpm/repository.h" #include #include diff --git a/web/js/repomanagement.js b/web/js/repomanagement.js index 7526da8..d642583 100644 --- a/web/js/repomanagement.js +++ b/web/js/repomanagement.js @@ -252,7 +252,7 @@ newEntry.info.index = updateEntries.length; if(updates[i1].entries[i2].pkg) { newEntry.applyBasicInfo(updates[i1].entries[i2].pkg, true); - if(updates[i1].entries[i2].prevVersion) { + if(updates[i1].entries[i2].curVer) { newEntry.info.ver = updates[i1].entries[i2].prevVersion + " → " + (newEntry.info.ver ? newEntry.info.ver : "?"); } // find associated repo entry