Nva*_*ion 2 python linux apt yum
有没有办法让python显示服务器上安装的所有apt/yum包?我有一个程序,只能抓取我指定的一个包,但我想知道是否在python中有一个apt-show-versions/yum check-update模块,因为python-yum和python-apt只做单个包.
谢谢.
编辑:
这是我目前的代码:
# For finding the package version and using the package name -i
def aptpkg(package_name):
cache = apt.Cache()
pkg = cache[package_name]
host = subprocess.Popen('hostname', stdout=subprocess.PIPE, universal_newlines=True).stdout.read().strip()
if pkg.is_installed:
print host
print 'Current ' + package_name + ' installed:', pkg.installed.version
con.execute("insert into ansible_packagelist(date, host, package_name, installed_version) values (current_timestamp,%s,%s,%s)", (host, package_name, pkg.installed.version,))
else:
print host, package_name + ' is not installed on this system.\n'
if pkg.is_upgradable:
print 'Upgradeable version of ' + package_name + ' :', pkg.candidate.version
con.execute("update ansible_packagelist set upgradeable_version = %s where package_name = %s", (pkg.candidate.version, package_name))
db.commit()
Run Code Online (Sandbox Code Playgroud)
这是pythonic方式:
import apt
cache = apt.Cache()
for mypkg in apt.Cache():
if cache[mypkg.name].is_installed:
print mypkg.name
Run Code Online (Sandbox Code Playgroud)
对于yum,我首先需要登录RH/Centos系统.但你可以看一下yum库,你会找到像'rpmdb.searchNevra'这样的东西.
| 归档时间: |
|
| 查看次数: |
5550 次 |
| 最近记录: |