如何在debian-like系统中使用libapt(或libept)来列出软件包并获取他们的信息? [英] How to use libapt (or libept) in debian-like system to list packages and get their infos?

查看:164
本文介绍了如何在debian-like系统中使用libapt(或libept)来列出软件包并获取他们的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在类似debian的系统中使用libapt或libept列出软件包并获取有关软件包的信息?



Libapt没有详细记录,发现了几个关于libept的例子和教程。有人可以解释我最好的方法


  1. 获取apt系统中的每个包的列表


  2. 获取单个软件包安装的文件列表

获取有关单个软件包的信息(例如名称,版本,依赖性,描述等)

直接使用apt内部文件很简单,但我想使用一个库来遵循apt规范。

解决方案

在debian中有一个名为 libapt-pkg-doc 的包,其中包含一些文档(如API参考)它在file:///usr/share/doc/libapt-pkg-doc/html/index.xhtml。



我只是看看libapt和这里

 <$ c 

$ c> #include< apt-pkg / cachefile.h>
#include< apt-pkg / pkgcache.h>

int main(){
// _config和_system在libapt头文件中定义
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;
}


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

  1. get a list of every packages in the apt-system
  2. get informations about single packages (like name, version, dependences, description, etc.
  3. get list of files installed by a single package

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;
}

这篇关于如何在debian-like系统中使用libapt(或libept)来列出软件包并获取他们的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆