On Sun, Jun 10, 2012 at 06:11:21PM +0200, Benjamin Mesing wrote: > [patch snipped]
I am not comfortable changing that bit of code in libept: it adds complexity, which I would then have to maintain, and I don't have the energy for it. When I say that I want to get rid of libept because I can't maintain it anymore, I am serious, I mean it. If you would like to add functionality to it you're welcom to, as long as you take over upstream maintenance. So I'm proposing (one of) the two attached patches instead: * 0001-Expose-the-underlying-libapt.patch It exposes libapt-pkg. This is a very simple patch, and it is a good thing because it helps client code migrate to apt-pkg. * 0002-Separate-method-to-lookup-translated-descs.patch This adds a function to lookup translated descriptions. I put it in libept just because I had the file open and I could test compiling it, but that function only needs the apt cache object and strings with package name and versions to run it. Since the only program that would use it is packagesearch, I propose that instead of having that function in libept, you just add it to packagesearch. That would keep the change to libept straightforward and minimal. So, my proposal is that 0001-Expose-the-underlying-libapt.patch goes into libept,and that 0002-Separate-method-to-lookup-translated-descs.patch gets adapted to be added to packagesearch instead. Does it sound sensible? Ciao, Enrico -- GPG key: 1024D/797EBFAB 2000-12-05 Enrico Zini <enr...@enricozini.org>
>From 7e3fe98d1ea56ab090a94573e3e48e6a61d69044 Mon Sep 17 00:00:00 2001 From: Enrico Zini <enr...@enricozini.org> Date: Thu, 14 Jun 2012 13:11:11 +0200 Subject: [PATCH 1/2] Expose the underlying libapt --- ept/apt/apt.cc | 7 +++++++ ept/apt/apt.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/ept/apt/apt.cc b/ept/apt/apt.cc index 76c34f0..2d625fb 100644 --- a/ept/apt/apt.cc +++ b/ept/apt/apt.cc @@ -633,6 +633,13 @@ std::string Apt::rawRecord(const Version& ver) const return std::string(); } + +const pkgCache* Apt::aptPkgCache() const +{ + return impl->m_cache; +} + + void Apt::checkCacheUpdates() { if (impl->m_open_timestamp < timestamp()) diff --git a/ept/apt/apt.h b/ept/apt/apt.h index 0cfff60..6e6ce74 100644 --- a/ept/apt/apt.h +++ b/ept/apt/apt.h @@ -29,6 +29,8 @@ #include <iterator> +class pkgCache; + namespace ept { namespace apt { @@ -198,6 +200,7 @@ public: Apt(); ~Apt(); + iterator begin() const; iterator end() const; @@ -257,6 +260,11 @@ public: /// Get the raw package record for the given Version std::string rawRecord(const Version& ver) const; + /// Returns the pointer to the internal libapt pkgCache object used. + const pkgCache* aptPkgCache() const; + + + /// Timestamp of when the apt index was last modified time_t timestamp(); -- 1.7.10
>From 4d6aaf759ff2aeb97a806feb8f3f8556e3f67f7d Mon Sep 17 00:00:00 2001 From: Enrico Zini <enr...@enricozini.org> Date: Thu, 14 Jun 2012 13:31:30 +0200 Subject: [PATCH 2/2] Separate method to lookup translated descs --- ept/apt/apt.cc | 29 +++++++++++++++++++++++++++++ ept/apt/apt.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/ept/apt/apt.cc b/ept/apt/apt.cc index 2d625fb..2af3646 100644 --- a/ept/apt/apt.cc +++ b/ept/apt/apt.cc @@ -633,6 +633,35 @@ std::string Apt::rawRecord(const Version& ver) const return std::string(); } +std::string Apt::translatedDescription(const std::string& ver) const +{ + // TODO: possibly reimplement using a single lump of apt code, to avoid + // repeating lookups + return translatedDescription(anyVersion(ver)); +} + +std::string Apt::translatedDescription(const Version& ver) const +{ + pkgCache::PkgIterator pi = impl->cache().FindPkg(ver.name()); + if (pi.end()) return std::string(); + for (pkgCache::VerIterator vi = pi.VersionList(); !vi.end(); vi++) + { + const char* v = vi.VerStr(); + if (v == 0) continue; + if (ver.version() != v) continue; + + // Get the translated record + pkgRecords Recs(impl->cache()); + pkgCache::DescIterator Desc = vi.TranslatedDescription(); + pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); + // TODO currently the language code is not added here + // this would break the packagerecord parsing algorithm, should be implemented + // in the future though + //result << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc(); + return P.LongDesc(); + } + return std::string(); +} const pkgCache* Apt::aptPkgCache() const { diff --git a/ept/apt/apt.h b/ept/apt/apt.h index 6e6ce74..e0c88f8 100644 --- a/ept/apt/apt.h +++ b/ept/apt/apt.h @@ -260,6 +260,12 @@ public: /// Get the raw package record for the given Version std::string rawRecord(const Version& ver) const; + /// Get the translated package record for the given Version + std::string translatedDescription(const std::string& pkg) const; + + /// Get the translated package record for the given Version + std::string translatedDescription(const Version& ver) const; + /// Returns the pointer to the internal libapt pkgCache object used. const pkgCache* aptPkgCache() const; -- 1.7.10