python이 서버에 설치된 모든 apt/yum 패키지를 표시 할 수있는 방법이 있습니까? 파이썬 - yum과 python-apt가 단일 패키지 만하기 때문에 파이썬에서 모듈과 비슷한 apt-show-versions/yum 확인 업데이트가 있는지 알고 싶습니다. .Python은 설치된 모든 패키지를 표시합니다
감사합니다.
편집 :
# 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()
현재 가지고있는 코드를 붙여 넣을 수 있습니까? –
'[p.is_installed이면 apt_pkg.packages in p] 해 보셨습니까? ' http://apt.alioth.debian.org/python-apt-doc/library/apt_pkg.html#apt_pkg.packages – Dunes