我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用apt_pkg.init()。
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)
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
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())
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
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
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)