本文整理汇总了Python中apt_pkg.init方法的典型用法代码示例。如果您正苦于以下问题:Python apt_pkg.init方法的具体用法?Python apt_pkg.init怎么用?Python apt_pkg.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apt_pkg
的用法示例。
在下文中一共展示了apt_pkg.init方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_maas_cli
# 需要导入模块: import apt_pkg [as 别名]
# 或者: from apt_pkg import init [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)
示例2: openstack_upgrade_available
# 需要导入模块: import apt_pkg [as 别名]
# 或者: from apt_pkg import init [as 别名]
def openstack_upgrade_available(self, package=None, snap=None):
"""Check if an OpenStack upgrade is available
:param package: str Package name to use to check upgrade availability
:returns: bool
"""
if not package:
package = self.release_pkg
if not snap:
snap = self.release_snap
src = self.config['openstack-origin']
cur_vers = self.get_os_version_package(package)
avail_vers = os_utils.get_os_version_install_source(src)
if os_utils.snap_install_requested():
cur_vers = self.get_os_version_snap(snap)
else:
cur_vers = self.get_os_version_package(package)
apt.init()
return apt.version_compare(avail_vers, cur_vers) == 1
示例3: getDependencies
# 需要导入模块: import apt_pkg [as 别名]
# 或者: from apt_pkg import init [as 别名]
def getDependencies(self, packageName):
# Simulate a set using a hash (to a dummy value);
# sets were only added in Python 2.4
result = {}
if not self.cache:
import apt_pkg
apt_pkg.init()
self.cache = apt_pkg.Cache()
packages = self.cache.packages
for package in packages:
if package.name == packageName:
current = package.current_ver
if not current:
raise PackageNotFoundError(packageName)
depends = current.depends_list
list = depends['Depends']
for dependency in list:
name = dependency[0].target_pkg.name
# Add to the hash using a dummy value
result[name] = None
return list(result.keys())
示例4: openstack_upgrade_available
# 需要导入模块: import apt_pkg [as 别名]
# 或者: from apt_pkg import init [as 别名]
def openstack_upgrade_available(package):
"""
Determines if an OpenStack upgrade is available from installation
source, based on version of installed package.
:param package: str: Name of installed package.
:returns: bool: : Returns True if configured installation source offers
a newer version of package.
"""
import apt_pkg as apt
src = config('openstack-origin')
cur_vers = get_os_version_package(package)
if "swift" in package:
codename = get_os_codename_install_source(src)
avail_vers = get_os_version_codename_swift(codename)
else:
avail_vers = get_os_version_install_source(src)
apt.init()
if "swift" in package:
major_cur_vers = cur_vers.split('.', 1)[0]
major_avail_vers = avail_vers.split('.', 1)[0]
major_diff = apt.version_compare(major_avail_vers, major_cur_vers)
return avail_vers > cur_vers and (major_diff == 1 or major_diff == 0)
return apt.version_compare(avail_vers, cur_vers) == 1
示例5: openstack_upgrade_available
# 需要导入模块: import apt_pkg [as 别名]
# 或者: from apt_pkg import init [as 别名]
def openstack_upgrade_available(package):
"""
Determines if an OpenStack upgrade is available from installation
source, based on version of installed package.
:param package: str: Name of installed package.
:returns: bool: : Returns True if configured installation source offers
a newer version of package.
"""
import apt_pkg as apt
src = config('openstack-origin')
cur_vers = get_os_version_package(package)
if not cur_vers:
# The package has not been installed yet do not attempt upgrade
return False
if "swift" in package:
codename = get_os_codename_install_source(src)
avail_vers = get_os_version_codename_swift(codename)
else:
avail_vers = get_os_version_install_source(src)
apt.init()
if "swift" in package:
major_cur_vers = cur_vers.split('.', 1)[0]
major_avail_vers = avail_vers.split('.', 1)[0]
major_diff = apt.version_compare(major_avail_vers, major_cur_vers)
return avail_vers > cur_vers and (major_diff == 1 or major_diff == 0)
return apt.version_compare(avail_vers, cur_vers) == 1
示例6: apt_cache
# 需要导入模块: import apt_pkg [as 别名]
# 或者: from apt_pkg import init [as 别名]
def apt_cache(in_memory=True, progress=None):
"""Build and return an apt cache."""
from apt import apt_pkg
apt_pkg.init()
if in_memory:
apt_pkg.config.set("Dir::Cache::pkgcache", "")
apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
return apt_pkg.Cache(progress)