summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nicoletti <dantti12@gmail.com>2012-04-17 05:01:49 -0300
committerDaniel Nicoletti <dantti12@gmail.com>2012-04-17 05:01:49 -0300
commit0e5f551fd3bd930e1d31b376cd576a0f36a85c94 (patch)
treea96aa34f157efa2fb950f2f753eb084f93d78ad3
parentaca0b4b143e071f4b4390c89c86d62ba5741d088 (diff)
aptcc: Move cache related functions to pkgCacheFile subclass
-rw-r--r--backends/aptcc/AptCacheFile.cpp123
-rw-r--r--backends/aptcc/AptCacheFile.h32
-rw-r--r--backends/aptcc/apt-intf.cpp39
-rw-r--r--backends/aptcc/apt-intf.h6
-rw-r--r--backends/aptcc/apt-utils.cpp133
-rw-r--r--backends/aptcc/apt-utils.h31
-rw-r--r--backends/aptcc/pk-backend-aptcc.cpp6
7 files changed, 175 insertions, 195 deletions
diff --git a/backends/aptcc/AptCacheFile.cpp b/backends/aptcc/AptCacheFile.cpp
index 556323a4..ca20f67f 100644
--- a/backends/aptcc/AptCacheFile.cpp
+++ b/backends/aptcc/AptCacheFile.cpp
@@ -254,3 +254,126 @@ void AptCacheFile::buildPkgRecords()
// Create the text record parser
m_packageRecords = new pkgRecords(*this);
}
+
+pkgCache::VerIterator AptCacheFile::findCandidateVer(const pkgCache::PkgIterator &pkg)
+{
+ // get the candidate version iterator
+ return (*this)[pkg].CandidateVerIter(*this);
+}
+
+std::string AptCacheFile::getDefaultShortDescription(const pkgCache::VerIterator &ver)
+{
+ if (ver.end() || ver.FileList().end() || GetPkgRecords() == 0) {
+ return string();
+ }
+
+ pkgCache::VerFileIterator vf = ver.FileList();
+ return m_packageRecords->Lookup(vf).ShortDesc();
+}
+
+std::string AptCacheFile::getShortDescription(const pkgCache::VerIterator &ver)
+{
+ if (ver.end() || ver.FileList().end() || GetPkgRecords() == 0) {
+ return string();
+ }
+
+ pkgCache::DescIterator d = ver.TranslatedDescription();
+ if (d.end()) {
+ return string();
+ }
+
+ pkgCache::DescFileIterator df = d.FileList();
+ if (df.end()) {
+ return string();
+ } else {
+ return m_packageRecords->Lookup(df).ShortDesc();
+ }
+}
+
+std::string AptCacheFile::getDefaultLongDescription(const pkgCache::VerIterator &ver)
+{
+ if(ver.end() || ver.FileList().end() || GetPkgRecords() == 0) {
+ return string();
+ }
+
+ pkgCache::VerFileIterator vf = ver.FileList();
+
+ if (vf.end()) {
+ return string();
+ } else {
+ return m_packageRecords->Lookup(vf).LongDesc();
+ }
+}
+
+std::string AptCacheFile::getLongDescription(const pkgCache::VerIterator &ver)
+{
+ if (ver.end() || ver.FileList().end() || GetPkgRecords() == 0) {
+ return string();
+ }
+
+ pkgCache::DescIterator d = ver.TranslatedDescription();
+ if (d.end()) {
+ return string();
+ }
+
+ pkgCache::DescFileIterator df = d.FileList();
+ if (df.end()) {
+ return string();
+ } else {
+ return m_packageRecords->Lookup(df).LongDesc();
+ }
+}
+
+std::string AptCacheFile::getLongDescriptionParsed(const pkgCache::VerIterator &ver)
+{
+ return debParser(getLongDescription(ver));
+}
+
+std::string AptCacheFile::debParser(std::string descr)
+{
+ // Policy page on package descriptions
+ // http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
+ unsigned int i;
+ string::size_type nlpos=0;
+
+ nlpos = descr.find('\n');
+ // delete first line
+ if (nlpos != string::npos) {
+ descr.erase(0, nlpos + 2); // del "\n " too
+ }
+
+ // avoid replacing '\n' for a ' ' after a '.\n' is found
+ bool removedFullStop = false;
+ while (nlpos < descr.length()) {
+ // find the new line position
+ nlpos = descr.find('\n', nlpos);
+ if (nlpos == string::npos) {
+ // if it could not find the new line
+ // get out of the loop
+ break;
+ }
+
+ i = nlpos;
+ // erase the char after '\n' which is always " "
+ descr.erase(++i, 1);
+
+ // remove lines likes this: " .", making it a \n
+ if (descr[i] == '.') {
+ descr.erase(i, 1);
+ nlpos = i;
+ // don't permit the next round to replace a '\n' to a ' '
+ removedFullStop = true;
+ continue;
+ } else if (descr[i] != ' ' && removedFullStop == false) {
+ // it's not a line to be verbatim displayed
+ // So it's a paragraph let's replace '\n' with a ' '
+ // replace new line with " "
+ descr.replace(nlpos, 1, " ");
+ }
+
+ removedFullStop = false;
+ nlpos++;
+ }
+
+ return descr;
+}
diff --git a/backends/aptcc/AptCacheFile.h b/backends/aptcc/AptCacheFile.h
index 620b5687..e04cebd4 100644
--- a/backends/aptcc/AptCacheFile.h
+++ b/backends/aptcc/AptCacheFile.h
@@ -69,8 +69,40 @@ public:
*/
inline pkgDepCache* GetDepCache() { BuildCaches(); BuildPolicy(); BuildDepCache(); return DCache; }
+ /**
+ * Tries to find the candidate version of a package
+ * @returns pkgCache::VerIterator, if .end() is true the version could not be found
+ */
+ pkgCache::VerIterator findCandidateVer(const pkgCache::PkgIterator &pkg);
+
+ /** \return a short description string corresponding to the given
+ * version.
+ */
+ std::string getDefaultShortDescription(const pkgCache::VerIterator &ver);
+
+ /** \return a short description string corresponding to the given
+ * version.
+ */
+ std::string getShortDescription(const pkgCache::VerIterator &ver);
+
+ /** \return a short description string corresponding to the given
+ * version.
+ */
+ std::string getDefaultLongDescription(const pkgCache::VerIterator &ver);
+
+ /** \return a short description string corresponding to the given
+ * version.
+ */
+ std::string getLongDescription(const pkgCache::VerIterator &ver);
+
+ /** \return a short description string corresponding to the given
+ * version.
+ */
+ std::string getLongDescriptionParsed(const pkgCache::VerIterator &ver);
+
private:
void buildPkgRecords();
+ static std::string debParser(std::string descr);
pkgRecords *m_packageRecords;
PkBackend *m_backend;
diff --git a/backends/aptcc/apt-intf.cpp b/backends/aptcc/apt-intf.cpp
index 055487b1..76d31ef6 100644
--- a/backends/aptcc/apt-intf.cpp
+++ b/backends/aptcc/apt-intf.cpp
@@ -137,7 +137,7 @@ pkgCache::VerIterator AptIntf::findPackageId(const gchar *packageId)
return ver;
}
- const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg);
+ const pkgCache::VerIterator &candidateVer = m_cache.findCandidateVer(pkg);
// check to see if the provided package isn't virtual too
if (candidateVer.end() == false &&
strcmp(candidateVer.VerStr(), parts[PK_PACKAGE_ID_VERSION]) == 0) {
@@ -158,7 +158,7 @@ pkgCache::VerIterator AptIntf::findVer(const pkgCache::PkgIterator &pkg)
}
// Else get the candidate version iterator
- const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg);
+ const pkgCache::VerIterator &candidateVer = m_cache.findCandidateVer(pkg);
if (!candidateVer.end()) {
return candidateVer;
}
@@ -167,12 +167,6 @@ pkgCache::VerIterator AptIntf::findVer(const pkgCache::PkgIterator &pkg)
return pkg.VersionList();
}
-pkgCache::VerIterator AptIntf::findCandidateVer(const pkgCache::PkgIterator &pkg)
-{
- // get the candidate version iterator
- return (*m_cache.GetDepCache())[pkg].CandidateVerIter(m_cache);
-}
-
bool AptIntf::matchPackage(const pkgCache::VerIterator &ver, PkBitfield filters)
{
if (filters != 0) {
@@ -321,7 +315,7 @@ void AptIntf::emitPackage(const pkgCache::VerIterator &ver,
pk_backend_package(m_backend,
state,
package_id,
- get_short_description(ver, m_cache.GetPkgRecords()).c_str());
+ m_cache.getShortDescription(ver).c_str());
g_free(package_id);
}
@@ -417,7 +411,7 @@ void AptIntf::providesCodec(PkgList &output, gchar **values)
// Ignore virtual packages
pkgCache::VerIterator ver = findVer(pkg);
if (ver.end() == true) {
- ver = findCandidateVer(pkg);
+ ver = m_cache.findCandidateVer(pkg);
if (ver.end() == true) {
continue;
}
@@ -489,7 +483,7 @@ void AptIntf::providesLibrary(PkgList &output, gchar **values)
// TODO: Ignore virtual packages
pkgCache::VerIterator ver = findVer (pkg);
if (ver.end()) {
- ver = findCandidateVer(pkg);
+ ver = m_cache.findCandidateVer(pkg);
if (ver.end()) {
continue;
}
@@ -627,7 +621,7 @@ void AptIntf::emitPackageDetail(const pkgCache::VerIterator &ver)
package_id,
"unknown",
get_enum_group(section),
- get_long_description_parsed(ver, m_cache.GetPkgRecords()).c_str(),
+ m_cache.getLongDescriptionParsed(ver).c_str(),
rec.Homepage().c_str(),
size);
@@ -1092,7 +1086,7 @@ PkgList AptIntf::searchPackageDetails(Matcher *matcher)
const pkgCache::VerIterator &ver = findVer(pkg);
if (ver.end() == false) {
if (matcher->matches(pkg.Name()) ||
- matcher->matches(get_long_description(ver, m_cache.GetPkgRecords()))) {
+ matcher->matches(m_cache.getLongDescription(ver))) {
// The package matched
output.push_back(ver);
}
@@ -1556,7 +1550,7 @@ void AptIntf::emitChangedPackages(AptCacheFile &cache)
for (pkgCache::PkgIterator pkg = cache->PkgBegin(); ! pkg.end(); ++pkg) {
if (cache[pkg].NewInstall() == true) {
// installing;
- const pkgCache::VerIterator &ver = findCandidateVer(pkg);
+ const pkgCache::VerIterator &ver = m_cache.findCandidateVer(pkg);
if (!ver.end()) {
installing.push_back(ver);
}
@@ -1568,7 +1562,7 @@ void AptIntf::emitChangedPackages(AptCacheFile &cache)
}
} else if (cache[pkg].Upgrade() == true) {
// updating
- const pkgCache::VerIterator &ver = findCandidateVer(pkg);
+ const pkgCache::VerIterator &ver = m_cache.findCandidateVer(pkg);
if (!ver.end()) {
updating.push_back(ver);
}
@@ -1593,16 +1587,17 @@ void AptIntf::populateInternalPackages(AptCacheFile &cache)
for (pkgCache::PkgIterator pkg = cache->PkgBegin(); ! pkg.end(); ++pkg) {
if (cache[pkg].NewInstall() == true) {
// installing
- m_pkgs.push_back(findCandidateVer(pkg));
+ m_pkgs.push_back(m_cache.findCandidateVer(pkg));
} else if (cache[pkg].Delete() == true) {
// removing
m_pkgs.push_back(findVer(pkg));
} else if (cache[pkg].Upgrade() == true) {
// updating
- m_pkgs.push_back(findCandidateVer(pkg));
+ m_pkgs.push_back(m_cache.findCandidateVer(pkg));
} else if (cache[pkg].Downgrade() == true) {
// downgrading
- m_pkgs.push_back(findCandidateVer(pkg));
+ // TODO shouldn't be the current version?
+ m_pkgs.push_back(m_cache.findCandidateVer(pkg));
}
}
}
@@ -1629,7 +1624,7 @@ void AptIntf::emitTransactionPackage(string name, PkInfoEnum state)
emitPackage(ver, state);
}
- const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg);
+ const pkgCache::VerIterator &candidateVer = m_cache.findCandidateVer(pkg);
// check to see if we found the package
if (candidateVer.end() == false) {
emitPackage(candidateVer, state);
@@ -2010,7 +2005,7 @@ PkgList AptIntf::resolvePackageIds(gchar **package_ids, PkBitfield filters)
ret.push_back(ver);
}
- const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg);
+ const pkgCache::VerIterator &candidateVer = m_cache.findCandidateVer(pkg);
// check to see if the provided package isn't virtual too
if (candidateVer.end() == false) {
ret.push_back(candidateVer);
@@ -2029,7 +2024,7 @@ PkgList AptIntf::resolvePackageIds(gchar **package_ids, PkBitfield filters)
ret.push_back(ver);
}
- const pkgCache::VerIterator &candidateVer = findCandidateVer(pkg);
+ const pkgCache::VerIterator &candidateVer = m_cache.findCandidateVer(pkg);
// check to see if the provided package isn't virtual too
if (candidateVer.end() == false) {
ret.push_back(candidateVer);
@@ -2439,7 +2434,7 @@ bool AptIntf::installPackages(AptCacheFile &cache, bool simulating)
}
pkgCache::VerIterator ver = cache[pkg].InstVerIter(cache);
- if (ver.end() && (ver = findCandidateVer(pkg))) {
+ if (ver.end() && (ver = m_cache.findCandidateVer(pkg))) {
// Ignore invalid versions
continue;
}
diff --git a/backends/aptcc/apt-intf.h b/backends/aptcc/apt-intf.h
index 48839982..a2edd588 100644
--- a/backends/aptcc/apt-intf.h
+++ b/backends/aptcc/apt-intf.h
@@ -65,12 +65,6 @@ public:
pkgCache::VerIterator findVer(const pkgCache::PkgIterator &pkg);
/**
- * Tries to find the candidate version of a package
- * @returns pkgCache::VerIterator, if .end() is true the version could not be found
- */
- pkgCache::VerIterator findCandidateVer(const pkgCache::PkgIterator &pkg);
-
- /**
* Tries to find a list of packages mathing the package ids
* @returns a list of pkgCache::VerIterator, if the list is empty no package was found
*/
diff --git a/backends/aptcc/apt-utils.cpp b/backends/aptcc/apt-utils.cpp
index 497e5935..5f784b73 100644
--- a/backends/aptcc/apt-utils.cpp
+++ b/backends/aptcc/apt-utils.cpp
@@ -24,139 +24,6 @@
#include <fstream>
#include <sys/stat.h>
-static string debParser(string descr);
-
-string get_default_short_description(const pkgCache::VerIterator &ver,
- pkgRecords *records)
-{
- if(ver.end() || ver.FileList().end() || records == NULL) {
- return string();
- }
-
- pkgCache::VerFileIterator vf = ver.FileList();
-
- if (vf.end()) {
- return string();
- } else {
- return records->Lookup(vf).ShortDesc();
- }
-}
-
-string get_short_description(const pkgCache::VerIterator &ver,
- pkgRecords *records)
-{
- if (ver.end() || ver.FileList().end() || records == NULL) {
- return string();
- }
-
- pkgCache::DescIterator d = ver.TranslatedDescription();
-
- if (d.end()) {
- return string();
- }
-
- pkgCache::DescFileIterator df = d.FileList();
-
- if (df.end()) {
- return string();
- } else {
- return records->Lookup(df).ShortDesc();
- }
-}
-
-string get_long_description(const pkgCache::VerIterator &ver,
- pkgRecords *records)
-{
- if (ver.end() || ver.FileList().end() || records == NULL) {
- return string();
- }
-
- pkgCache::DescIterator d = ver.TranslatedDescription();
-
- if (d.end()) {
- return string();
- }
-
- pkgCache::DescFileIterator df = d.FileList();
-
- if (df.end()) {
- return string();
- } else {
- return records->Lookup(df).LongDesc();
- }
-}
-
-string get_long_description_parsed(const pkgCache::VerIterator &ver,
- pkgRecords *records)
-{
- return debParser(get_long_description(ver, records));
-}
-
-string get_default_long_description(const pkgCache::VerIterator &ver,
- pkgRecords *records)
-{
- if(ver.end() || ver.FileList().end() || records == NULL) {
- return string();
- }
-
- pkgCache::VerFileIterator vf = ver.FileList();
-
- if (vf.end()) {
- return string();
- } else {
- return records->Lookup(vf).LongDesc();
- }
-}
-
-static string debParser(string descr)
-{
- // Policy page on package descriptions
- // http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
- unsigned int i;
- string::size_type nlpos=0;
-
- nlpos = descr.find('\n');
- // delete first line
- if (nlpos != string::npos) {
- descr.erase(0, nlpos + 2); // del "\n " too
- }
-
- // avoid replacing '\n' for a ' ' after a '.\n' is found
- bool removedFullStop = false;
- while (nlpos < descr.length()) {
- // find the new line position
- nlpos = descr.find('\n', nlpos);
- if (nlpos == string::npos) {
- // if it could not find the new line
- // get out of the loop
- break;
- }
-
- i = nlpos;
- // erase the char after '\n' which is always " "
- descr.erase(++i, 1);
-
- // remove lines likes this: " .", making it a \n
- if (descr[i] == '.') {
- descr.erase(i, 1);
- nlpos = i;
- // don't permit the next round to replace a '\n' to a ' '
- removedFullStop = true;
- continue;
- } else if (descr[i] != ' ' && removedFullStop == false) {
- // it's not a line to be verbatim displayed
- // So it's a paragraph let's replace '\n' with a ' '
- // replace new line with " "
- descr.replace(nlpos, 1, " ");
- }
-
- removedFullStop = false;
- nlpos++;
- }
-
- return descr;
-}
-
PkGroupEnum get_enum_group(string group)
{
if (group.compare ("admin") == 0) {
diff --git a/backends/aptcc/apt-utils.h b/backends/aptcc/apt-utils.h
index 122f32de..4b07d564 100644
--- a/backends/aptcc/apt-utils.h
+++ b/backends/aptcc/apt-utils.h
@@ -62,37 +62,6 @@ public:
}
};
-/** \return a short description string corresponding to the given
- * version.
- */
-string get_default_short_description(const pkgCache::VerIterator &ver,
- pkgRecords *records);
-
-/** \return a short description string corresponding to the given
- * version.
- */
-string get_short_description(const pkgCache::VerIterator &ver,
- pkgRecords *records);
-
-
-/** \return a short description string corresponding to the given
- * version.
- */
-string get_default_long_description(const pkgCache::VerIterator &ver,
- pkgRecords *records);
-
-/** \return a short description string corresponding to the given
- * version.
- */
-string get_long_description(const pkgCache::VerIterator &ver,
- pkgRecords *records);
-
-/** \return a short description string corresponding to the given
- * version.
- */
-string get_long_description_parsed(const pkgCache::VerIterator &ver,
- pkgRecords *records);
-
/**
* Return the PkEnumGroup of the give group string.
*/
diff --git a/backends/aptcc/pk-backend-aptcc.cpp b/backends/aptcc/pk-backend-aptcc.cpp
index c43ac887..209cb325 100644
--- a/backends/aptcc/pk-backend-aptcc.cpp
+++ b/backends/aptcc/pk-backend-aptcc.cpp
@@ -405,19 +405,19 @@ static gboolean backend_get_or_update_system_thread (PkBackend *backend)
if (getUpdates) {
PkgList updates;
PkgList kept;
- for (pkgCache::PkgIterator pkg = cache.GetPkgCache()->PkgBegin();
+ for (pkgCache::PkgIterator pkg = cache->PkgBegin();
!pkg.end();
++pkg) {
if (cache[pkg].Upgrade() == true &&
cache[pkg].NewInstall() == false) {
- const pkgCache::VerIterator &ver = m_apt->findCandidateVer(pkg);
+ const pkgCache::VerIterator &ver = cache.findCandidateVer(pkg);
if (!ver.end()) {
updates.push_back(ver);
}
} else if (cache[pkg].Upgradable() == true &&
pkg->CurrentVer != 0 &&
cache[pkg].Delete() == false) {
- const pkgCache::VerIterator &ver = m_apt->findCandidateVer(pkg);
+ const pkgCache::VerIterator &ver = cache.findCandidateVer(pkg);
if (!ver.end()) {
kept.push_back(ver);
}