Somebody used libapt or libept to list packages and get informations about package in a debian-like system?
Libapt is not well-documented at all, and i've found few examples and tutorials about libept. Can someone explain me best methods to
Work directly with apt internal files is quite simple, but i want to use a library to respect apt specifications.
In debian there is a package called libapt-pkg-doc
which contains some documentation (like an API reference). Once installed, you can access it at file:///usr/share/doc/libapt-pkg-doc/html/index.xhtml.
I only just had a look at libapt and here is what I have learned so far:
How to list all packages:
#include <apt-pkg/cachefile.h>
#include <apt-pkg/pkgcache.h>
int main() {
// _config and _system are defined in the libapt header files
pkgInitConfig(*_config);
pkgInitSystem(*_config, _system);
pkgCacheFile cache_file;
pkgCache* cache = cache_file.GetPkgCache();
for (pkgCache::PkgIterator package = cache->PkgBegin(); !package.end(); package++) {
std::cout << package.Name() << std::endl;
}
return 0;
}
Take a look at how apt-cache(8) is implemented. Obtaining the source with apt is easy:
# apt-get source apt
In the source file cmdline/apt-cache.cc
theres is a function called DumpPackage()
which extracts information from a named file in the cache.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With