From d8276801a1c84582a85ed9ea1f2eb4e66e052e6b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 15 Jun 2010 20:46:09 +0200 Subject: * cmdline/cacheset.cc: - doesn't include it in the library for now as it is too volatile --- cmdline/cacheset.h | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 cmdline/cacheset.h (limited to 'cmdline/cacheset.h') diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h new file mode 100644 index 000000000..2bc268380 --- /dev/null +++ b/cmdline/cacheset.h @@ -0,0 +1,274 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/** \file cacheset.h + Wrappers around std::set to have set::iterators which behave + similar to the Iterators of the cache structures. + + Provides also a few helper methods which work with these sets */ + /*}}}*/ +#ifndef APT_CACHESET_H +#define APT_CACHESET_H +// Include Files /*{{{*/ +#include +#include +#include +#include +#include +#include + +#include +#include + /*}}}*/ +namespace APT { +class PackageSet : public std::set { /*{{{*/ +/** \class APT::PackageSet + + Simple wrapper around a std::set to provide a similar interface to + a set of packages as to the complete set of all packages in the + pkgCache. */ +public: /*{{{*/ + /** \brief smell like a pkgCache::PkgIterator */ + class const_iterator : public std::set::const_iterator { + public: + const_iterator(std::set::const_iterator x) : + std::set::const_iterator(x) {} + + operator pkgCache::PkgIterator(void) { return **this; } + + inline const char *Name() const {return (**this).Name(); } + inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); } + inline std::string FullName() const { return (**this).FullName(); } + inline const char *Section() const {return (**this).Section(); } + inline bool Purge() const {return (**this).Purge(); } + inline const char *Arch() const {return (**this).Arch(); } + inline pkgCache::GrpIterator Group() const { return (**this).Group(); } + inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); } + inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); } + inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); } + inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); } + inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); } + inline const char *CandVersion() const { return (**this).CandVersion(); } + inline const char *CurVersion() const { return (**this).CurVersion(); } + inline pkgCache *Cache() const { return (**this).Cache(); }; + inline unsigned long Index() const {return (**this).Index();}; + // we have only valid iterators here + inline bool end() const { return false; }; + + friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); } + + inline pkgCache::Package const * operator->() const { + return &***this; + }; + }; + // 103. set::iterator is required to be modifiable, but this allows modification of keys + typedef APT::PackageSet::const_iterator iterator; + + using std::set::insert; + inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + + /** \brief returns all packages in the cache whose name matchs a given pattern + + A simple helper responsible for executing a regular expression on all + package names in the cache. Optional it prints a a notice about the + packages chosen cause of the given package. + \param Cache the packages are in + \param pattern regular expression for package names + \param out stream to print the notice to */ + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromRegEx(Cache, pattern, out); + } + + /** \brief returns all packages specified by a string + + \param Cache the packages are in + \param string String the package name(s) should be extracted from + \param out stream to print various notices to */ + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, std::ostream &out); + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromString(Cache, string, out); + } + + /** \brief returns all packages specified on the commandline + + Get all package names from the commandline and executes regex's if needed. + No special package command is supported, just plain names. + \param Cache the packages are in + \param cmdline Command line the package names should be extracted from + \param out stream to print various notices to */ + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromCommandLine(Cache, cmdline, out); + } + + struct Modifier { + enum Position { NONE, PREFIX, POSTFIX }; + unsigned short ID; + const char * const Alias; + Position Pos; + Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; + }; + + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out); + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, + mods, fallback, out); + } + /*}}}*/ +}; /*}}}*/ +class VersionSet : public std::set { /*{{{*/ +/** \class APT::VersionSet + + Simple wrapper around a std::set to provide a similar interface to + a set of versions as to the complete set of all versions in the + pkgCache. */ +public: /*{{{*/ + /** \brief smell like a pkgCache::VerIterator */ + class const_iterator : public std::set::const_iterator { + public: + const_iterator(std::set::const_iterator x) : + std::set::const_iterator(x) {} + + operator pkgCache::VerIterator(void) { return **this; } + + inline pkgCache *Cache() const { return (**this).Cache(); }; + inline unsigned long Index() const {return (**this).Index();}; + // we have only valid iterators here + inline bool end() const { return false; }; + + inline pkgCache::Version const * operator->() const { + return &***this; + }; + + inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); }; + inline const char *VerStr() const { return (**this).VerStr(); }; + inline const char *Section() const { return (**this).Section(); }; + inline const char *Arch() const { return (**this).Arch(); }; + inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); }; + inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); }; + inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); }; + inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); }; + inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); }; + inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }; + inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); }; + inline bool Downloadable() const { return (**this).Downloadable(); }; + inline const char *PriorityType() const { return (**this).PriorityType(); }; + inline string RelStr() const { return (**this).RelStr(); }; + inline bool Automatic() const { return (**this).Automatic(); }; + inline bool Pseudo() const { return (**this).Pseudo(); }; + inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; + }; + // 103. set::iterator is required to be modifiable, but this allows modification of keys + typedef APT::VersionSet::const_iterator iterator; + + using std::set::insert; + inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; + + /** \brief specifies which version(s) will be returned if non is given */ + enum Version { + /** All versions */ + ALL, + /** Candidate and installed version */ + CANDANDINST, + /** Candidate version */ + CANDIDATE, + /** Installed version */ + INSTALLED, + /** Candidate or if non installed version */ + CANDINST, + /** Installed or if non candidate version */ + INSTCAND, + /** Newest version */ + NEWEST + }; + + /** \brief returns all versions specified on the commandline + + Get all versions from the commandline, uses given default version if + non specifically requested and executes regex's if needed on names. + \param Cache the packages and versions are in + \param cmdline Command line the versions should be extracted from + \param out stream to print various notices to */ + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, std::ostream &out); + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out); + } + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); + } + + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback, std::ostream &out); + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, + APT::VersionSet::Version const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::FromString(Cache, pkg, fallback, out); + } + static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { + return APT::VersionSet::FromString(Cache, pkg, CANDINST); + } + + struct Modifier { + enum Position { NONE, PREFIX, POSTFIX }; + unsigned short ID; + const char * const Alias; + Position Pos; + VersionSet::Version SelectVersion; + Modifier (unsigned short const &id, const char * const alias, Position const &pos, + VersionSet::Version const &select) : ID(id), Alias(alias), Pos(pos), + SelectVersion(select) {}; + }; + + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback, std::ostream &out); + static std::map GroupedFromCommandLine( + pkgCacheFile &Cache, const char **cmdline, + std::list const &mods, + unsigned short const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, + mods, fallback, out); + } + /*}}}*/ +protected: /*{{{*/ + + /** \brief returns the candidate version of the package + + \param Cache to be used to query for information + \param Pkg we want the candidate version from this package + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + + /** \brief returns the installed version of the package + + \param Cache to be used to query for information + \param Pkg we want the installed version from this package + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + + + static bool AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, + pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, + bool const &AllowError = false); + + /*}}}*/ +}; /*}}}*/ +} +#endif -- cgit v1.2.3 From dc0f01f7cbe2ed8ae6a1d2dbc0e00c19bb04679d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 19 Jun 2010 11:49:38 +0200 Subject: get packages by task^ with FromTask() --- cmdline/cacheset.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'cmdline/cacheset.h') diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 2bc268380..64a72e758 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -28,7 +28,7 @@ class PackageSet : public std::set { /*{{{*/ pkgCache. */ public: /*{{{*/ /** \brief smell like a pkgCache::PkgIterator */ - class const_iterator : public std::set::const_iterator { + class const_iterator : public std::set::const_iterator {/*{{{*/ public: const_iterator(std::set::const_iterator x) : std::set::const_iterator(x) {} @@ -62,10 +62,25 @@ public: /*{{{*/ }; // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef APT::PackageSet::const_iterator iterator; + /*}}}*/ using std::set::insert; inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + /** \brief returns all packages in the cache who belong to the given task + + A simple helper responsible for search for all members of a task + in the cache. Optional it prints a a notice about the + packages chosen cause of the given task. + \param Cache the packages are in + \param pattern name of the task + \param out stream to print the notice to */ + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromTask(Cache, pattern, out); + } + /** \brief returns all packages in the cache whose name matchs a given pattern A simple helper responsible for executing a regular expression on all @@ -134,7 +149,7 @@ class VersionSet : public std::set { /*{{{*/ pkgCache. */ public: /*{{{*/ /** \brief smell like a pkgCache::VerIterator */ - class const_iterator : public std::set::const_iterator { + class const_iterator : public std::set::const_iterator {/*{{{*/ public: const_iterator(std::set::const_iterator x) : std::set::const_iterator(x) {} @@ -168,6 +183,7 @@ public: /*{{{*/ inline bool Pseudo() const { return (**this).Pseudo(); }; inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); }; }; + /*}}}*/ // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef APT::VersionSet::const_iterator iterator; -- cgit v1.2.3 From 70e706adf75ed319d931a220ce27db2b981093f5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 22 Jun 2010 18:01:11 +0200 Subject: =?UTF-8?q?Use=20an=20abstract=20helper=20for=20error=20handling?= =?UTF-8?q?=20and=20output=20instead=20of=20doing=20this=20directly=20in?= =?UTF-8?q?=20the=20CacheSets.=20With=20this=20method=20an=20application?= =?UTF-8?q?=20like=20apt-get=20can=20change=20the=20behavior=20of=20the=20?= =?UTF-8?q?CacheSets=20to=20his=20liking.=20It=20can=20for=20example=20eas?= =?UTF-8?q?ily=20keep=20track=20of=20how=20packages=20were=20added=20to=20?= =?UTF-8?q?the=20set:=20by=20names=20or=20with=20regex's=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmdline/cacheset.h | 104 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 33 deletions(-) (limited to 'cmdline/cacheset.h') diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 64a72e758..9c9491020 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -20,6 +20,45 @@ #include /*}}}*/ namespace APT { +class PackageSet; +class VersionSet; +class CacheSetHelper { /*{{{*/ +/** \class APT::CacheSetHelper + Simple base class with a lot of virtual methods which can be overridden + to alter the behavior or the output of the CacheSets. + + This helper is passed around by the static methods in the CacheSets and + used every time they hit an error condition or something could be + printed out. +*/ +public: /*{{{*/ + CacheSetHelper(bool const &ShowError = true) : ShowError(ShowError) {}; + virtual ~CacheSetHelper() {}; + + virtual void showTaskSelection(PackageSet const &pkgset, string const &pattern) {}; + virtual void showRegExSelection(PackageSet const &pkgset, string const &pattern) {}; + virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, + string const &ver, bool const &verIsRel) {}; + + virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); + virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); + virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); + virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); + + bool showErrors() const { return ShowError; }; + bool showErrors(bool const &newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }; + /*}}}*/ +protected: + bool ShowError; +}; /*}}}*/ class PackageSet : public std::set { /*{{{*/ /** \class APT::PackageSet @@ -66,6 +105,7 @@ public: /*{{{*/ using std::set::insert; inline void insert(pkgCache::PkgIterator const &P) { if (P.end() == false) std::set::insert(P); }; + inline void insert(PackageSet const &pkgset) { insert(pkgset.begin(), pkgset.end()); }; /** \brief returns all packages in the cache who belong to the given task @@ -75,10 +115,10 @@ public: /*{{{*/ \param Cache the packages are in \param pattern name of the task \param out stream to print the notice to */ - static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromTask(Cache, pattern, out); + CacheSetHelper helper; + return APT::PackageSet::FromTask(Cache, pattern, helper); } /** \brief returns all packages in the cache whose name matchs a given pattern @@ -89,10 +129,10 @@ public: /*{{{*/ \param Cache the packages are in \param pattern regular expression for package names \param out stream to print the notice to */ - static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromRegEx(Cache, pattern, out); + CacheSetHelper helper; + return APT::PackageSet::FromRegEx(Cache, pattern, helper); } /** \brief returns all packages specified by a string @@ -100,10 +140,10 @@ public: /*{{{*/ \param Cache the packages are in \param string String the package name(s) should be extracted from \param out stream to print various notices to */ - static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, std::ostream &out); + static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromString(Cache, string, out); + CacheSetHelper helper; + return APT::PackageSet::FromString(Cache, string, helper); } /** \brief returns all packages specified on the commandline @@ -113,10 +153,10 @@ public: /*{{{*/ \param Cache the packages are in \param cmdline Command line the package names should be extracted from \param out stream to print various notices to */ - static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::PackageSet::FromCommandLine(Cache, cmdline, out); + CacheSetHelper helper; + return APT::PackageSet::FromCommandLine(Cache, cmdline, helper); } struct Modifier { @@ -130,14 +170,14 @@ public: /*{{{*/ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, - unsigned short const &fallback, std::ostream &out); + unsigned short const &fallback, CacheSetHelper &helper); static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, unsigned short const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); + CacheSetHelper helper; return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, out); + mods, fallback, helper); } /*}}}*/ }; /*}}}*/ @@ -189,6 +229,7 @@ public: /*{{{*/ using std::set::insert; inline void insert(pkgCache::VerIterator const &V) { if (V.end() == false) std::set::insert(V); }; + inline void insert(VersionSet const &verset) { insert(verset.begin(), verset.end()); }; /** \brief specifies which version(s) will be returned if non is given */ enum Version { @@ -216,22 +257,22 @@ public: /*{{{*/ \param cmdline Command line the versions should be extracted from \param out stream to print various notices to */ static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, - APT::VersionSet::Version const &fallback, std::ostream &out); + APT::VersionSet::Version const &fallback, CacheSetHelper &helper); static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, APT::VersionSet::Version const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out); + CacheSetHelper helper; + return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, helper); } static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); } static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, std::ostream &out); + APT::VersionSet::Version const &fallback, CacheSetHelper &helper); static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, APT::VersionSet::Version const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); - return APT::VersionSet::FromString(Cache, pkg, fallback, out); + CacheSetHelper helper; + return APT::VersionSet::FromString(Cache, pkg, fallback, helper); } static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg) { return APT::VersionSet::FromString(Cache, pkg, CANDINST); @@ -251,14 +292,14 @@ public: /*{{{*/ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, - unsigned short const &fallback, std::ostream &out); + unsigned short const &fallback, CacheSetHelper &helper); static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, unsigned short const &fallback) { - std::ostream out (std::ofstream("/dev/null").rdbuf()); + CacheSetHelper helper; return APT::VersionSet::GroupedFromCommandLine(Cache, cmdline, - mods, fallback, out); + mods, fallback, helper); } /*}}}*/ protected: /*{{{*/ @@ -266,23 +307,20 @@ protected: /*{{{*/ /** \brief returns the candidate version of the package \param Cache to be used to query for information - \param Pkg we want the candidate version from this package - \param AllowError add an error to the stack if not */ + \param Pkg we want the candidate version from this package */ static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); /** \brief returns the installed version of the package \param Cache to be used to query for information - \param Pkg we want the installed version from this package - \param AllowError add an error to the stack if not */ + \param Pkg we want the installed version from this package */ static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, - pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); - + pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - static bool AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, + static void AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, - bool const &AllowError = false); + CacheSetHelper &helper); /*}}}*/ }; /*}}}*/ -- cgit v1.2.3 From bd631595620ca5b3c53ede4ef46c89399c26c5f3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 28 Jun 2010 22:13:17 +0200 Subject: - factor out code to get a single package FromName() - check in Grouped* first without modifier interpretation --- cmdline/cacheset.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'cmdline/cacheset.h') diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 9c9491020..21c42c511 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -40,6 +40,7 @@ public: /*{{{*/ virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, string const &ver, bool const &verIsRel) {}; + virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); virtual PackageSet canNotFindTask(pkgCacheFile &Cache, std::string pattern); virtual PackageSet canNotFindRegEx(pkgCacheFile &Cache, std::string pattern); virtual PackageSet canNotFindPackage(pkgCacheFile &Cache, std::string const &str); @@ -146,6 +147,17 @@ public: /*{{{*/ return APT::PackageSet::FromString(Cache, string, helper); } + /** \brief returns a package specified by a string + + \param Cache the package is in + \param string String the package name should be extracted from + \param out stream to print various notices to */ + static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); + static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { + CacheSetHelper helper; + return APT::PackageSet::FromName(Cache, string, helper); + } + /** \brief returns all packages specified on the commandline Get all package names from the commandline and executes regex's if needed. @@ -268,7 +280,8 @@ public: /*{{{*/ } static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, - APT::VersionSet::Version const &fallback, CacheSetHelper &helper); + APT::VersionSet::Version const &fallback, CacheSetHelper &helper, + bool const &onlyFromName = false); static APT::VersionSet FromString(pkgCacheFile &Cache, std::string pkg, APT::VersionSet::Version const &fallback) { CacheSetHelper helper; -- cgit v1.2.3 From fb83c1d078b9f5e2e28a828c325dc62dcf060f2b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 29 Jun 2010 19:10:47 +0200 Subject: rename AddSelectedVersion() to a better public FromPackage() --- cmdline/cacheset.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'cmdline/cacheset.h') diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 21c42c511..bf863fb39 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -291,6 +291,15 @@ public: /*{{{*/ return APT::VersionSet::FromString(Cache, pkg, CANDINST); } + /** \brief returns all versions specified for the package + + \param Cache the package and versions are in + \param P the package in question + \param fallback the version(s) you want to get + \param helper the helper used for display and error handling */ + static VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + VersionSet::Version const &fallback, CacheSetHelper &helper); + struct Modifier { enum Position { NONE, PREFIX, POSTFIX }; unsigned short ID; @@ -330,11 +339,6 @@ protected: /*{{{*/ \param Pkg we want the installed version from this package */ static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper); - - static void AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset, - pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, - CacheSetHelper &helper); - /*}}}*/ }; /*}}}*/ } -- cgit v1.2.3 From cf28bcadb301d00f6534fea97ccf1fde63041e7b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 29 Jun 2010 19:21:35 +0200 Subject: if the package has no installed & candidate but is virtual see if only one package provides it - if it is only one use this package instead --- cmdline/cacheset.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmdline/cacheset.h') diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index bf863fb39..2ca794f28 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -47,6 +47,8 @@ public: /*{{{*/ virtual VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); virtual VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + virtual VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg); virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, -- cgit v1.2.3 From c8db3fff877f102dc6fb62c4e4c7f700160b68f5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 2 Jul 2010 07:06:53 +0200 Subject: add a ConstructedBy member to the PackageSet which can be used by the e.g. FromString to tell the caller if the string was an exact match or found by regex or task. The two later ones can match packages for which we want to ignore failures in the VersionSet --- cmdline/cacheset.h | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'cmdline/cacheset.h') diff --git a/cmdline/cacheset.h b/cmdline/cacheset.h index 2ca794f28..c8c3dd096 100644 --- a/cmdline/cacheset.h +++ b/cmdline/cacheset.h @@ -117,7 +117,7 @@ public: /*{{{*/ packages chosen cause of the given task. \param Cache the packages are in \param pattern name of the task - \param out stream to print the notice to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromTask(pkgCacheFile &Cache, std::string const &pattern) { CacheSetHelper helper; @@ -131,7 +131,7 @@ public: /*{{{*/ packages chosen cause of the given package. \param Cache the packages are in \param pattern regular expression for package names - \param out stream to print the notice to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { CacheSetHelper helper; @@ -142,7 +142,7 @@ public: /*{{{*/ \param Cache the packages are in \param string String the package name(s) should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) { CacheSetHelper helper; @@ -153,7 +153,7 @@ public: /*{{{*/ \param Cache the package is in \param string String the package name should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string, CacheSetHelper &helper); static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &string) { CacheSetHelper helper; @@ -166,7 +166,7 @@ public: /*{{{*/ No special package command is supported, just plain names. \param Cache the packages are in \param cmdline Command line the package names should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { CacheSetHelper helper; @@ -181,6 +181,17 @@ public: /*{{{*/ Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}; }; + /** \brief group packages by a action modifiers + + At some point it is needed to get from the same commandline + different package sets grouped by a modifier. Take + apt-get install apt awesome- + as an example. + \param Cache the packages are in + \param cmdline Command line the package names should be extracted from + \param mods list of modifiers the method should accept + \param fallback the default modifier group for a package + \param helper responsible for error and message handling */ static std::map GroupedFromCommandLine( pkgCacheFile &Cache, const char **cmdline, std::list const &mods, @@ -193,6 +204,15 @@ public: /*{{{*/ return APT::PackageSet::GroupedFromCommandLine(Cache, cmdline, mods, fallback, helper); } + + enum Constructor { UNKNOWN, REGEX, TASK }; + Constructor getConstructor() const { return ConstructedBy; }; + + PackageSet() : ConstructedBy(UNKNOWN) {}; + PackageSet(Constructor const &by) : ConstructedBy(by) {}; + /*}}}*/ +private: /*{{{*/ + Constructor ConstructedBy; /*}}}*/ }; /*}}}*/ class VersionSet : public std::set { /*{{{*/ @@ -269,7 +289,7 @@ public: /*{{{*/ non specifically requested and executes regex's if needed on names. \param Cache the packages and versions are in \param cmdline Command line the versions should be extracted from - \param out stream to print various notices to */ + \param helper responsible for error and message handling */ static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, APT::VersionSet::Version const &fallback, CacheSetHelper &helper); static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, @@ -299,8 +319,16 @@ public: /*{{{*/ \param P the package in question \param fallback the version(s) you want to get \param helper the helper used for display and error handling */ - static VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, VersionSet::Version const &fallback, CacheSetHelper &helper); + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, + APT::VersionSet::Version const &fallback) { + CacheSetHelper helper; + return APT::VersionSet::FromPackage(Cache, P, fallback, helper); + } + static APT::VersionSet FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { + return APT::VersionSet::FromPackage(Cache, P, CANDINST); + } struct Modifier { enum Position { NONE, PREFIX, POSTFIX }; -- cgit v1.2.3