python apt-get列表升级 [英] python apt-get list upgrades
本文介绍了python apt-get列表升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取可用的升级软件包列表,并使用python将其写入文件?
How can I get a list of upgrade packages available and write it to file using python?
当我运行apt-get upgrade > output
它在bash中工作.我想我必须在python程序中发送陷阱信号( Ctrl + C ).
When I run apt-get upgrade > output
it works in bash. I think I have to send the trap signal (Ctrl+C) in the python program.
关于如何实现这一目标的任何建议?
Any suggestions on how to achieve this?
我现在在代码上尝试过:
I tried this on the code now:
#!/usr/bin/env python
import subprocess
apt = subprocess.Popen([r"apt-get", "-V", "upgrade", ">", "/usr/src/python/upgrade.log"], stdin=subprocess.PIPE)
apt_stdin = apt.communicate()[0]
但它会退出并且不会写入文件.
but it exits and does not write to the file.
这可行,但是将其移植到其他Debian系统时出现错误:
This works but I am getting error when I port this to other Debian systems:
import apt
cache=apt.Cache()
cache.update()
cache.open(None)
cache.upgrade()
for pkg in cache.get_changes():
# print pkg.name, pkg.summary
fileHandle = open('/tmp/upgrade.log', 'a')
fileHandle.write(pkg.name + " - " + pkg.summary + "\n")
和错误....
/usr/lib/python2.5/site-packages/apt/__init__.py:18: FutureWarning: apt API not stable yet
warnings.warn("apt API not stable yet", FutureWarning)
Traceback (most recent call last):
File "apt-notify.py", line 13, in <module>
for pkg in cache.get_changes():
AttributeError: 'Cache' object has no attribute 'get_changes'
推荐答案
为什么不使用python-apt模块例如
Why not use the python-apt module eg.
import apt
cache=apt.Cache()
cache.update()
cache.open(None)
cache.upgrade()
for pkg in cache.getChanges():
print pkg.sourcePackageName, pkg.isUpgradeable
还阅读了badp评论中的链接
also read the link in badp's comment
这篇关于python apt-get列表升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文