diff options
author | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-22 13:07:14 -0300 |
---|---|---|
committer | Daniel Nicoletti <dantti12@gmail.com> | 2012-04-22 13:07:14 -0300 |
commit | 6c76071f88a17ddaf0aa8e02fb71f5403cef8b75 (patch) | |
tree | e6c986d4021168a19ef5c647fce39e07b741d1f7 | |
parent | 311255d4a62678bd35b21304b3793ff8e4bbe8bc (diff) |
aptcc: Create a PkgList class to provide convience methods and remove uneeded apt-intf.h includes
-rw-r--r-- | backends/aptcc/Makefile.am | 4 | ||||
-rw-r--r-- | backends/aptcc/PkgList.cpp | 74 | ||||
-rw-r--r-- | backends/aptcc/PkgList.h | 49 | ||||
-rw-r--r-- | backends/aptcc/acqpkitstatus.cpp | 2 | ||||
-rw-r--r-- | backends/aptcc/acqpkitstatus.h | 7 | ||||
-rw-r--r-- | backends/aptcc/apt-intf.cpp | 34 | ||||
-rw-r--r-- | backends/aptcc/apt-intf.h | 6 | ||||
-rw-r--r-- | backends/aptcc/apt-messages.cpp | 2 | ||||
-rw-r--r-- | backends/aptcc/apt-sourceslist.cpp | 1 | ||||
-rw-r--r-- | backends/aptcc/apt-utils.cpp | 12 | ||||
-rw-r--r-- | backends/aptcc/apt-utils.h | 36 |
11 files changed, 156 insertions, 71 deletions
diff --git a/backends/aptcc/Makefile.am b/backends/aptcc/Makefile.am index e84a0d4e7..3357936de 100644 --- a/backends/aptcc/Makefile.am +++ b/backends/aptcc/Makefile.am @@ -4,7 +4,8 @@ INCLUDES = \ plugindir = $(PK_PLUGIN_DIR) plugin_LTLIBRARIES = libpk_backend_aptcc.la -libpk_backend_aptcc_la_SOURCES = pkg_acqfile.cpp \ +libpk_backend_aptcc_la_SOURCES = PkgList.cpp \ + pkg_acqfile.cpp \ acqpkitstatus.cpp \ deb-file.cpp \ matcher.cpp \ @@ -25,6 +26,7 @@ aptconfdir = ${SYSCONFDIR}/apt/apt.conf.d aptconf_DATA = 20packagekit EXTRA_DIST = 20packagekit \ + PkgList.h \ apt-intf.h \ apt-utils.h \ apt-sourceslist.h \ diff --git a/backends/aptcc/PkgList.cpp b/backends/aptcc/PkgList.cpp new file mode 100644 index 000000000..b68867506 --- /dev/null +++ b/backends/aptcc/PkgList.cpp @@ -0,0 +1,74 @@ +/* PkgList.cpp + * + * Copyright (c) 2012 Daniel Nicoletti <dantti12@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "PkgList.h" + +#include <algorithm> + +// compare...uses the candidate version of each package. +class compare +{ +public: + compare() {} + + bool operator()(const pkgCache::VerIterator &a, + const pkgCache::VerIterator &b) { + int ret = strcmp(a.ParentPkg().Name(), b.ParentPkg().Name()); + if (ret == 0) { + return strcmp(a.VerStr(), b.VerStr()) < 0; + } + return ret < 0; + } +}; + +/** \brief operator== for match results. */ +class result_equality +{ +public: + result_equality() {} + + bool operator() (const pkgCache::VerIterator &a, const pkgCache::VerIterator &b) { + return strcmp(a.ParentPkg().Name(), b.ParentPkg().Name()) == 0 && + strcmp(a.VerStr(), b.VerStr()) == 0 && + strcmp(a.Arch(), b.Arch()) == 0; + } +}; + +bool PkgList::contains(const pkgCache::PkgIterator &pkg) +{ + for (PkgList::const_iterator it = begin(); it != end(); ++it) { + if (it->ParentPkg() == pkg) { + return true; + } + } + return false; +} + +void PkgList::sort() +{ + // Sort so we can remove the duplicated entries + std::sort(begin(), end(), compare()); +} + +void PkgList::removeDuplicates() +{ + // Remove the duplicated entries + erase(unique(begin(), end(), result_equality()), end()); +} diff --git a/backends/aptcc/PkgList.h b/backends/aptcc/PkgList.h new file mode 100644 index 000000000..103a64e2c --- /dev/null +++ b/backends/aptcc/PkgList.h @@ -0,0 +1,49 @@ +/* PkgList.h + * + * Copyright (c) 2012 Daniel Nicoletti <dantti12@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef PKG_LIST_H +#define PKG_LIST_H + +#include <apt-pkg/pkgcache.h> + +using std::vector; + +/** + * This class is maent to show Operation Progress using PackageKit + */ +class PkgList : public vector<pkgCache::VerIterator> +{ +public: + /** + * Return if the given vector contain a package + */ + bool contains(const pkgCache::PkgIterator &pkg); + + /** + * Sort the package list + */ + void sort(); + + /** + * Remove duplicated packages (it's recommended to sort() first) + */ + void removeDuplicates(); +}; + +#endif // PKG_LIST_H diff --git a/backends/aptcc/acqpkitstatus.cpp b/backends/aptcc/acqpkitstatus.cpp index e95b8acf9..cdaa36df0 100644 --- a/backends/aptcc/acqpkitstatus.cpp +++ b/backends/aptcc/acqpkitstatus.cpp @@ -20,6 +20,8 @@ #include "acqpkitstatus.h" +#include "apt-intf.h" + #include <apt-pkg/acquire-item.h> #include <apt-pkg/acquire-worker.h> diff --git a/backends/aptcc/acqpkitstatus.h b/backends/aptcc/acqpkitstatus.h index 7d09a1a1f..0977f4444 100644 --- a/backends/aptcc/acqpkitstatus.h +++ b/backends/aptcc/acqpkitstatus.h @@ -24,8 +24,13 @@ #include <apt-pkg/acquire.h> #include <pk-backend.h> -#include "apt-intf.h" +#include "PkgList.h" +#include <set> + +using std::set; + +class AptIntf; class AcqPackageKitStatus : public pkgAcquireStatus { public: diff --git a/backends/aptcc/apt-intf.cpp b/backends/aptcc/apt-intf.cpp index 60aa4889b..edd45898d 100644 --- a/backends/aptcc/apt-intf.cpp +++ b/backends/aptcc/apt-intf.cpp @@ -349,13 +349,10 @@ void AptIntf::emitPackage(const pkgCache::VerIterator &ver, PkInfoEnum state) void AptIntf::emitPackages(PkgList &output, PkBitfield filters, PkInfoEnum state) { // Sort so we can remove the duplicated entries - sort(output.begin(), output.end(), compare()); + output.sort(); // Remove the duplicated entries - output.erase(unique(output.begin(), - output.end(), - result_equality()), - output.end()); + output.removeDuplicates(); for (PkgList::const_iterator it = output.begin(); it != output.end(); ++it) { if (m_cancel) { @@ -371,13 +368,10 @@ void AptIntf::emitPackages(PkgList &output, PkBitfield filters, PkInfoEnum state void AptIntf::emitRequireRestart(PkgList &output) { // Sort so we can remove the duplicated entries - sort(output.begin(), output.end(), compare()); - + output.sort(); + // Remove the duplicated entries - output.erase(unique(output.begin(), - output.end(), - result_equality()), - output.end()); + output.removeDuplicates(); for (PkgList::const_iterator it = output.begin(); it != output.end(); ++it) { gchar *package_id; @@ -391,12 +385,10 @@ void AptIntf::emitUpdates(PkgList &output, PkBitfield filters) { PkInfoEnum state; // Sort so we can remove the duplicated entries - sort(output.begin(), output.end(), compare()); + output.sort(); + // Remove the duplicated entries - output.erase(unique(output.begin(), - output.end(), - result_equality()), - output.end()); + output.removeDuplicates(); for (PkgList::const_iterator i = output.begin(); i != output.end(); ++i) { if (m_cancel) { @@ -673,10 +665,10 @@ void AptIntf::emitPackageDetail(const pkgCache::VerIterator &ver) void AptIntf::emitDetails(PkgList &pkgs) { // Sort so we can remove the duplicated entries - sort(pkgs.begin(), pkgs.end(), compare()); + pkgs.sort(); + // Remove the duplicated entries - pkgs.erase(unique(pkgs.begin(), pkgs.end(), result_equality()), - pkgs.end()); + pkgs.removeDuplicates(); for (PkgList::const_iterator i = pkgs.begin(); i != pkgs.end(); ++i) { if (m_cancel) { @@ -946,7 +938,7 @@ void AptIntf::getDepends(PkgList &output, continue; } else if (dep->Type == pkgCache::Dep::Depends) { if (recursive) { - if (!contains(output, dep.TargetPkg())) { + if (!output.contains(dep.TargetPkg())) { output.push_back(ver); getDepends(output, ver, recursive); } @@ -980,7 +972,7 @@ void AptIntf::getRequires(PkgList &output, for (PkgList::const_iterator it = deps.begin(); it != deps.end(); ++it) { if (*it == ver) { if (recursive) { - if (!contains(output, parentPkg)) { + if (!output.contains(parentPkg)) { output.push_back(parentVer); getRequires(output, parentVer, recursive); } diff --git a/backends/aptcc/apt-intf.h b/backends/aptcc/apt-intf.h index 1d80b06cc..1fafc51dc 100644 --- a/backends/aptcc/apt-intf.h +++ b/backends/aptcc/apt-intf.h @@ -31,14 +31,12 @@ #include <pk-backend.h> +#include "PkgList.h" + #define PREUPGRADE_BINARY "/usr/bin/do-release-upgrade" #define GDEBI_BINARY "/usr/bin/gdebi" #define REBOOT_REQUIRED "/var/run/reboot-required" -using namespace std; - -typedef vector<pkgCache::VerIterator> PkgList; - class pkgProblemResolver; class Matcher; class AptCacheFile; diff --git a/backends/aptcc/apt-messages.cpp b/backends/aptcc/apt-messages.cpp index 4c38d062b..d011bee95 100644 --- a/backends/aptcc/apt-messages.cpp +++ b/backends/aptcc/apt-messages.cpp @@ -24,6 +24,8 @@ #include "apt-utils.h" +#include <apt-pkg/error.h> + #include <sstream> using namespace std; diff --git a/backends/aptcc/apt-sourceslist.cpp b/backends/aptcc/apt-sourceslist.cpp index a984493c5..36d1db526 100644 --- a/backends/aptcc/apt-sourceslist.cpp +++ b/backends/aptcc/apt-sourceslist.cpp @@ -37,7 +37,6 @@ #include <fstream> #include "config.h" -#include "apt-intf.h" SourcesList::~SourcesList() { diff --git a/backends/aptcc/apt-utils.cpp b/backends/aptcc/apt-utils.cpp index 6fea1ac49..9d22a195e 100644 --- a/backends/aptcc/apt-utils.cpp +++ b/backends/aptcc/apt-utils.cpp @@ -22,6 +22,8 @@ #include "pkg_acqfile.h" +#include <glib/gstdio.h> + #include <fstream> PkGroupEnum get_enum_group(string group) @@ -242,16 +244,6 @@ string getBugzillaUrls(const string &changelog) return ret; } -bool contains(const PkgList &packages, const pkgCache::PkgIterator &pkg) -{ - for (PkgList::const_iterator it = packages.begin(); it != packages.end(); ++it) { - if (it->ParentPkg() == pkg) { - return true; - } - } - return false; -} - bool ends_with(const string &str, const char *end) { size_t endSize = strlen(end); diff --git a/backends/aptcc/apt-utils.h b/backends/aptcc/apt-utils.h index 3297e16db..0102fdef4 100644 --- a/backends/aptcc/apt-utils.h +++ b/backends/aptcc/apt-utils.h @@ -25,36 +25,11 @@ #include <apt-pkg/pkgrecords.h> #include <apt-pkg/acquire.h> -#include "apt-intf.h" +#include <glib.h> -// compare...uses the candidate version of each package. -class compare -{ -public: - compare() {} +#include <pk-backend.h> - bool operator()(const pkgCache::VerIterator &a, - const pkgCache::VerIterator &b) { - int ret = strcmp(a.ParentPkg().Name(), b.ParentPkg().Name()); - if (ret == 0) { - return strcmp(a.VerStr(), b.VerStr()) < 0; - } - return ret < 0; - } -}; - -/** \brief operator== for match results. */ -class result_equality -{ -public: - result_equality() {} - - bool operator() (const pkgCache::VerIterator &a, const pkgCache::VerIterator &b) { - return strcmp(a.ParentPkg().Name(), b.ParentPkg().Name()) == 0 && - strcmp(a.VerStr(), b.VerStr()) == 0 && - strcmp(a.Arch(), b.Arch()) == 0; - } -}; +using namespace std; /** * Return the PkEnumGroup of the give group string. @@ -82,11 +57,6 @@ string getCVEUrls(const string &changelog); string getBugzillaUrls(const string &changelog); /** - * Return if the given vector contain a package - */ -bool contains(const PkgList &packages, const pkgCache::PkgIterator &pkg); - -/** * Return if the given string ends with the other */ bool ends_with(const string &str, const char *end); |