本文整理匯總了Python中apt_pkg.Cache方法的典型用法代碼示例。如果您正苦於以下問題:Python apt_pkg.Cache方法的具體用法?Python apt_pkg.Cache怎麽用?Python apt_pkg.Cache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類apt_pkg
的用法示例。
在下文中一共展示了apt_pkg.Cache方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cmp_pkgrevno
# 需要導入模塊: import apt_pkg [as 別名]
# 或者: from apt_pkg import Cache [as 別名]
def cmp_pkgrevno(package, revno, pkgcache=None):
"""Compare supplied revno with the revno of the installed package
* 1 => Installed revno is greater than supplied arg
* 0 => Installed revno is the same as supplied arg
* -1 => Installed revno is less than supplied arg
This function imports apt_cache function from charmhelpers.fetch if
the pkgcache argument is None. Be sure to add charmhelpers.fetch if
you call this function, or pass an apt_pkg.Cache() instance.
"""
import apt_pkg
if not pkgcache:
from charmhelpers.fetch import apt_cache
pkgcache = apt_cache()
pkg = pkgcache[package]
return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
示例2: cmp_pkgrevno
# 需要導入模塊: import apt_pkg [as 別名]
# 或者: from apt_pkg import Cache [as 別名]
def cmp_pkgrevno(package, revno, pkgcache=None):
"""Compare supplied revno with the revno of the installed package.
* 1 => Installed revno is greater than supplied arg
* 0 => Installed revno is the same as supplied arg
* -1 => Installed revno is less than supplied arg
This function imports apt_cache function from charmhelpers.fetch if
the pkgcache argument is None. Be sure to add charmhelpers.fetch if
you call this function, or pass an apt_pkg.Cache() instance.
"""
import apt_pkg
if not pkgcache:
from charmhelpers.fetch import apt_cache
pkgcache = apt_cache()
pkg = pkgcache[package]
return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
示例3: install_maas_cli
# 需要導入模塊: import apt_pkg [as 別名]
# 或者: from apt_pkg import Cache [as 別名]
def install_maas_cli(self):
"""Ensure maas-cli is installed
Fallback to MAAS stable PPA when needed.
"""
apt.init()
cache = apt.Cache()
try:
pkg = cache['maas-cli']
except KeyError:
cmd = ['add-apt-repository', '-y', MAAS_STABLE_PPA]
subprocess.check_call(cmd)
cmd = ['apt-get', 'update']
subprocess.check_call(cmd)
self.install_maas_cli()
return
if not pkg.current_ver:
apt_install('maas-cli', fatal=True)