如何使用python-apt获取软件包描述?


9

我正在尝试创建一个图形程序来为最终用户轻松处理软件包。但是,我在检索包装说明以及其他信息时遇到问题。

我在这里看到了python-apt API,我知道我必须处理apt.package.Version() 该类

但是当我尝试使用它时,我得到的只是一些错误,例如:

Traceback (most recent call last):
File "./myprogram", line 6, in <module>
print package.description
File "/usr/lib/python2.7/dist-packages/apt/package.py", line 374, in description
dsc = self._translated_records.long_desc
File "/usr/lib/python2.7/dist-packages/apt/package.py", line 315, in _translated_records
desc_iter = self._cand.translated_description
AttributeError: 'list' object has no attribute 'translated_description'

那么,请问有谁可以为apt.package.Version()类创建一个正在运行的示例?

谢谢!


确认您有完整的描述(apt-cache show对某些软件包而言)。该文档中有很长的描述,因此askubuntu.com/a/558389/158442可能是相关的。
muru

Answers:


8

可用时,以下python命令将为您提供详细说明:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt
>>> cache = apt.Cache()
>>> pkg = cache['python2.7']
>>> pkg
<Package: name:'python2.7' architecture='amd64' id:1247L>
>>> pkg.versions
<VersionList: ['2.7.6-8']>
>>> pkg.versions[0]
<Version: package:'python2.7' version:'2.7.6-8'>
>>> pkg.versions[0].description
u'Python is a high-level, interactive, object-oriented language. Its 2.7 version
includes an extensive class library with lots of goodies for network programming, 
system administration, sounds and graphics.'
>>> 

注意:我的语言环境设置为,LANG=en_US.UTF-8因此这里翻译的字符串可能不是问题。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.