:python apt_pkg를 사용하여 개별적인 패키지 정보를 얻으시겠습니까?
package.name
package.installedVersion
package.description
package.homepage
package.priority
나는 완전히 확실하지 않다하는, 나는 다음과 같은 방식으로 필요한 것을 얻을 수 있었다 이 결과를 얻는 최선의 방법입니다 :
import apt_pkg, apt
apt_pkg.InitConfig()
apt_pkg.InitSystem()
aptpkg_cache = apt_pkg.GetCache() #Low level
apt_cache = apt.Cache() #High level
apt_cache.update()
apt_cache.open()
pkgs = {}
list_pkgs = []
for package in aptpkg_cache.Packages:
try:
#I use this to pass in the pkg name from the apt_pkg.packages
#to the high level apt_cache which allows me to obtain the
#details I need. Is it better to just stick to one library here?
#In other words, can I obtain this with just apt_pkg instead of using apt?
selected_package = apt_cache[package.name]
#Verify that the package can be upgraded
if check_pkg_status(package) == "upgradable":
pkgs["name"] = selected_package.name
pkgs["version"] = selected_package.installedVersion
pkgs["desc"] = selected_package.description
pkgs["homepage"] = selected_package.homepage
pkgs["severity"] = selected_package.prority
list_pkgs.append(pkgs)
else:
print "Package: " + package.name + " does not exist"
pass #Not upgradable?
except:
pass #This is one of the main reasons why I want to try a different method.
#I'm using this Try/Catch because there are a lot of times that when
#I pass in package.name to apt_cache[], I get error that package does not
#exists...
def check_pkg_status(package):
versions = package.VersionList
version = versions[0]
for other_version in versions:
if apt_pkg.VersionCompare(version.VerStr, other_version.VerStr)<0:
version = other_version
if package.CurrentVer:
current = package.CurrentVer
if apt_pkg.VersionCompare(current.VerStr, version.VerStr)<0:
return "upgradable"
else:
return "current"
else:
return "uninstalled"
나는 가능한 업그레이드/업데이트 후보의 각 패키지에 대한 세부 정보를 얻기 위해 APT apt_pkg를/사용하는 좋은 방법을 찾으려면? 데비안 용 업데이트 관리자가 내 시스템에없는 패키지를 보여준 것을 알고 있습니다. 데비안 용 업데이트 관리자가 내 시스템에없는 패키지를 보여준 것을보고 있지만, 현재 시스템에서 이미 패키지에 대한 업데이트/업그레이드 만 제공합니다.
이를 볼 수있다/3092983/29489 and checkout python-apt doc http://apt.alioth.debian.org/python-apt-doc/library/apt.cache.html – number5
나는이 문서를 연구 해왔다. 잠시 전에 링크를 달았습니다. (\t AttributeError : 'Package'객체에는 'isUpgradeable'속성이 없습니다 ... - Dayan Jan 3 at 20:55),하지만 고마워요. – Dayan