本文整理汇总了Python中apt.cache.Cache.keys方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.keys方法的具体用法?Python Cache.keys怎么用?Python Cache.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apt.cache.Cache
的用法示例。
在下文中一共展示了Cache.keys方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_blacklist
# 需要导入模块: from apt.cache import Cache [as 别名]
# 或者: from apt.cache.Cache import keys [as 别名]
def generate_blacklist(self):
manifest_remove = os.path.join(self.casper_path,
'filesystem.manifest-remove')
manifest_desktop = os.path.join(self.casper_path,
'filesystem.manifest-desktop')
manifest = os.path.join(self.casper_path, 'filesystem.manifest')
if os.path.exists(manifest_remove) and os.path.exists(manifest):
difference = set()
with open(manifest_remove) as manifest_file:
for line in manifest_file:
if line.strip() != '' and not line.startswith('#'):
pkg = line.split(':')[0]
difference.add(pkg.split()[0])
live_packages = set()
with open(manifest) as manifest_file:
for line in manifest_file:
if line.strip() != '' and not line.startswith('#'):
pkg = line.split(':')[0]
live_packages.add(pkg.split()[0])
desktop_packages = live_packages - difference
elif os.path.exists(manifest_desktop) and os.path.exists(manifest):
desktop_packages = set()
with open(manifest_desktop) as manifest_file:
for line in manifest_file:
if line.strip() != '' and not line.startswith('#'):
pkg = line.split(':')[0]
desktop_packages.add(pkg.split()[0])
live_packages = set()
with open(manifest) as manifest_file:
for line in manifest_file:
if line.strip() != '' and not line.startswith('#'):
pkg = line.split(':')[0]
live_packages.add(pkg.split()[0])
difference = live_packages - desktop_packages
else:
difference = set()
cache = Cache()
use_restricted = True
try:
if self.db.get('apt-setup/restricted') == 'false':
use_restricted = False
except debconf.DebconfError:
pass
if not use_restricted:
for pkg in cache.keys():
if (cache[pkg].is_installed and
cache[pkg].section.startswith('restricted/')):
difference.add(pkg)
# Keep packages we explicitly installed.
keep = install_misc.query_recorded_installed()
arch, subarch = install_misc.archdetect()
# Less than ideal. Since we cannot know which bootloader we'll need
# at file copy time, we should figure out why grub still fails when
# apt-install-direct is present during configure_bootloader (code
# removed).
if arch in ('amd64', 'i386'):
if subarch == 'efi':
keep.add('grub-efi')
keep.add('grub-efi-amd64')
keep.add('grub-efi-amd64-signed')
keep.add('shim-signed')
keep.add('mokutil')
keep.add('fwupdate-signed')
install_misc.record_installed(['fwupdate-signed'])
try:
altmeta = self.db.get(
'base-installer/kernel/altmeta')
if altmeta:
altmeta = '-%s' % altmeta
except debconf.DebconfError:
altmeta = ''
keep.add('linux-signed-generic%s' % altmeta)
else:
keep.add('grub')
keep.add('grub-pc')
elif (arch in ('armel', 'armhf') and
subarch in ('omap', 'omap4', 'mx5')):
keep.add('flash-kernel')
keep.add('u-boot-tools')
elif arch == 'powerpc':
keep.add('yaboot')
keep.add('hfsutils')
# Even adding ubiquity as a depends to oem-config-{gtk,kde} doesn't
# appear to force ubiquity and libdebian-installer4 to copy all of
# their files, so this does the trick.
try:
if self.db.get('oem-config/enable') == 'true':
keep.add('ubiquity')
except (debconf.DebconfError, IOError):
pass
difference -= install_misc.expand_dependencies_simple(
cache, keep, difference)
# Consider only packages that don't have a prerm, and which can
#.........这里部分代码省略.........
示例2: _AptChangelog
# 需要导入模块: from apt.cache import Cache [as 别名]
# 或者: from apt.cache.Cache import keys [as 别名]
#.........这里部分代码省略.........
raise ValueError('No changelog in source package')
except Exception as e:
_generic_exception_handler(e)
self.exit_on_fail(520)
if 'tmpFile' in vars():
try:
tmpFile.close()
except Exception as e:
_generic_exception_handler(e)
# ALL DONE
return changelog
def parse_package_metadata(self, pkg_name:str):
""" Creates the self.candidate object based on package name=version/release
Wildcard matching is only used for version and release, and only the
first match is processed.
"""
# parse =version declaration
if "=" in pkg_name:
(pkg_name, pkg_version) = pkg_name.split("=", 1)
pkg_release = None
# parse /release declaration (only if no version specified)
elif "/" in pkg_name:
(pkg_name, pkg_release) = pkg_name.split("/", 1)
pkg_version = None
else:
pkg_version = None
pkg_release = None
# check if pkg_name exists
# unlike apt no pattern matching, a single exact match only
if pkg_name in self.apt_cache.keys():
pkg = self.apt_cache[pkg_name]
else:
print("E: Unable to locate package %s" % pkg_name, file=sys.stderr)
self.close(13)
# get package data
_candidate = None
candidate = None
if pkg_release or pkg_version:
match_found = False
for _pkg in pkg.versions:
if pkg_version:
if fnmatch.fnmatch(_pkg.version, pkg_version):
match_found = True
else:
for _origin in _pkg.origins:
if fnmatch.fnmatch(_origin.archive, pkg_release):
match_found = True
if match_found:
_candidate = _pkg
break
if not match_found:
if pkg_release:
print('E: Release "%s" is unavailable for "%s"' %
(pkg_release, pkg.name), file=sys.stderr)
else:
print('E: Version "%s" is unavailable for "%s"' %
(pkg_version, pkg.name), file=sys.stderr)
self.close(14)
else:
_candidate = pkg.candidate
candidate = _Package(
示例3: GDebiCommon
# 需要导入模块: from apt.cache import Cache [as 别名]
# 或者: from apt.cache.Cache import keys [as 别名]
class GDebiCommon(object):
# cprogress may be different in child classes
def __init__(self, datadir, options, file=""):
self.cprogress = None
self._cache = None
self.deps = ""
self.version_info_title = ""
self.version_info_msg = ""
self._deb = None
self._options = options
self.install = []
self.remove = []
self.unauthenticated = 0
def openCache(self):
self._cache = Cache(self.cprogress)
if self._cache._depcache.broken_count > 0:
self.error_header = _("Broken dependencies")
self.error_body = _("Your system has broken dependencies. "
"This application can not continue until "
"this is fixed. "
"To fix it run 'gksudo synaptic' or "
"'sudo apt-get install -f' "
"in a terminal window.")
return False
return True
def open(self, file, downloaded=False):
file = os.path.abspath(file)
klass = DebPackage
if file.endswith(".click"):
klass = ClickPackage
try:
self._deb = klass(file, self._cache, downloaded)
except (IOError, SystemError, ValueError) as e:
logging.debug("open failed with %s" % e)
mimetype=guess_type(file)
if (mimetype[0] != None and
mimetype[0] != "application/vnd.debian.binary-package"):
self.error_header = _("'%s' is not a Debian package") % os.path.basename(file)
self.error_body = _("The MIME type of this file is '%s' "
"and can not be installed on this system.") % mimetype[0]
return False
else:
self.error_header = _("Could not open '%s'") % os.path.basename(file)
self.error_body = _("The package might be corrupted or you are not "
"allowed to open the file. Check the permissions "
"of the file.")
return False
def compareDebWithCache(self):
# check if the package is available in the normal sources as well
res = self._deb.compare_to_version_in_cache(use_installed=False)
if not self._options.non_interactive and res != DebPackage.VERSION_NONE:
try:
pkg = self._cache[self._deb.pkgname]
except (KeyError, TypeError):
return
if self._deb.downloaded:
self.version_info_title = ""
self.version_info_msg = ""
return
# FIXME: make this strs better
if res == DebPackage.VERSION_SAME:
if pkg.candidate and pkg.candidate.downloadable:
self.version_info_title = _("Same version is available in a software channel")
self.version_info_msg = _("You are recommended to install the software "
"from the channel instead.")
elif res == DebPackage.VERSION_NEWER:
if pkg.candidate and pkg.candidate.downloadable:
self.version_info_title = _("An older version is available in a software channel")
self.version_info_msg = _("Generally you are recommended to install "
"the version from the software channel, since "
"it is usually better supported.")
elif res == DebPackage.VERSION_OUTDATED:
if pkg.candidate and pkg.candidate.downloadable:
self.version_info_title = _("A later version is available in a software "
"channel")
self.version_info_msg = _("You are strongly advised to install "
"the version from the software channel, since "
"it is usually better supported.")
def compareProvides(self):
provides = set()
broken_provides = set()
try:
pkg = self._cache[self._deb.pkgname].installed
except (KeyError, TypeError):
pkg = None
if pkg:
if pkg.provides:
for p in self._deb.provides:
for i in p:
provides.add(i[0])
provides = set(pkg.provides).difference(provides)
if provides:
for package in list(self._cache.keys()):
#.........这里部分代码省略.........
示例4: generate_blacklist
# 需要导入模块: from apt.cache import Cache [as 别名]
# 或者: from apt.cache.Cache import keys [as 别名]
def generate_blacklist(self):
manifest_remove = os.path.join(self.casper_path, "filesystem.manifest-remove")
manifest_desktop = os.path.join(self.casper_path, "filesystem.manifest-desktop")
manifest = os.path.join(self.casper_path, "filesystem.manifest")
if os.path.exists(manifest_remove) and os.path.exists(manifest):
difference = set()
with open(manifest_remove) as manifest_file:
for line in manifest_file:
if line.strip() != "" and not line.startswith("#"):
difference.add(line.split()[0])
live_packages = set()
with open(manifest) as manifest_file:
for line in manifest_file:
if line.strip() != "" and not line.startswith("#"):
live_packages.add(line.split()[0])
desktop_packages = live_packages - difference
elif os.path.exists(manifest_desktop) and os.path.exists(manifest):
desktop_packages = set()
with open(manifest_desktop) as manifest_file:
for line in manifest_file:
if line.strip() != "" and not line.startswith("#"):
desktop_packages.add(line.split()[0])
live_packages = set()
with open(manifest) as manifest_file:
for line in manifest_file:
if line.strip() != "" and not line.startswith("#"):
live_packages.add(line.split()[0])
difference = live_packages - desktop_packages
else:
difference = set()
cache = Cache()
use_restricted = True
try:
if self.db.get("apt-setup/restricted") == "false":
use_restricted = False
except debconf.DebconfError:
pass
if not use_restricted:
for pkg in cache.keys():
if cache[pkg].is_installed and cache[pkg].section.startswith("restricted/"):
difference.add(pkg)
# Keep packages we explicitly installed.
keep = install_misc.query_recorded_installed()
arch, subarch = install_misc.archdetect()
# Less than ideal. Since we cannot know which bootloader we'll need
# at file copy time, we should figure out why grub still fails when
# apt-install-direct is present during configure_bootloader (code
# removed).
if arch in ("amd64", "i386"):
if subarch == "efi":
keep.add("grub-efi")
keep.add("grub-efi-amd64")
efi_vars = "/sys/firmware/efi/vars"
sb_var = os.path.join(efi_vars, "SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c", "data")
if os.path.exists(sb_var):
with open(sb_var, "rb") as sb_var_file:
if sb_var_file.read(1) == b"\x01":
keep.add("grub-efi-amd64-signed")
keep.add("shim-signed")
try:
altmeta = self.db.get("base-installer/kernel/altmeta")
if altmeta:
altmeta = "-%s" % altmeta
except debconf.DebconfError:
altmeta = ""
keep.add("linux-signed-generic%s" % altmeta)
else:
keep.add("grub")
keep.add("grub-pc")
elif arch in ("armel", "armhf") and subarch in ("omap", "omap4", "mx5"):
keep.add("flash-kernel")
keep.add("u-boot-tools")
elif arch == "powerpc":
keep.add("yaboot")
keep.add("hfsutils")
# Even adding ubiquity as a depends to oem-config-{gtk,kde} doesn't
# appear to force ubiquity and libdebian-installer4 to copy all of
# their files, so this does the trick.
try:
if self.db.get("oem-config/enable") == "true":
keep.add("ubiquity")
except (debconf.DebconfError, IOError):
pass
difference -= install_misc.expand_dependencies_simple(cache, keep, difference)
# Consider only packages that don't have a prerm, and which can
# therefore have their files removed without any preliminary work.
difference = {x for x in difference if not os.path.exists("/var/lib/dpkg/info/%s.prerm" % x)}
confirmed_remove = set()
with cache.actiongroup():
for pkg in sorted(difference):
if pkg in confirmed_remove:
continue
#.........这里部分代码省略.........