本文整理汇总了Python中apt.cache.Cache.open方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.open方法的具体用法?Python Cache.open怎么用?Python Cache.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apt.cache.Cache
的用法示例。
在下文中一共展示了Cache.open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_update
# 需要导入模块: from apt.cache import Cache [as 别名]
# 或者: from apt.cache.Cache import open [as 别名]
def do_update(mark_only):
_, progress = query_verbosity()
log.info("Getting list of eligible packages...")
cache = Cache(progress)
f_cache = FilteredCache(cache)
f_cache.set_filter(NvidiaFilter())
names = f_cache.keys()
with unhold(names, cache):
# mark_only means we just want the side-effects of exiting the
# unhold() context manager.
if mark_only:
return False
log.info("Updating package list...")
try:
cache.update()
except FetchFailedException, err:
log.warn(err)
cache.open(progress) # Refresh package list
old_versions = {name: cache[name].installed for name in names}
log.info("Updating all packages...")
for name in names:
if cache[name].is_upgradable:
cache[name].mark_upgrade()
cache.commit(None, None)
log.info("Refreshing package cache...")
cache.open(progress)
new_versions = {name: cache[name].installed for name in names}
log.info("Checking whether packages were upgraded...")
for name in old_versions:
if old_versions[name] != new_versions[name]:
log.info("Kernel module changed")
return True
return False
示例2: do_install
# 需要导入模块: from apt.cache import Cache [as 别名]
# 或者: from apt.cache.Cache import open [as 别名]
def do_install(self, to_install, langpacks=False):
self.nested_progress_start()
if langpacks:
self.db.progress('START', 0, 10, 'ubiquity/langpacks/title')
else:
self.db.progress('START', 0, 10, 'ubiquity/install/title')
self.db.progress('INFO', 'ubiquity/install/find_installables')
self.progress_region(0, 1)
fetchprogress = DebconfAcquireProgress(
self.db, 'ubiquity/install/title',
'ubiquity/install/apt_indices_starting',
'ubiquity/install/apt_indices')
cache = Cache()
if cache._depcache.broken_count > 0:
syslog.syslog(
'not installing additional packages, since there are broken '
'packages: %s' % ', '.join(broken_packages(cache)))
self.db.progress('STOP')
self.nested_progress_end()
return
for pkg in to_install:
mark_install(cache, pkg)
self.db.progress('SET', 1)
self.progress_region(1, 10)
if langpacks:
fetchprogress = DebconfAcquireProgress(
self.db, 'ubiquity/langpacks/title', None,
'ubiquity/langpacks/packages')
installprogress = DebconfInstallProgress(
self.db, 'ubiquity/langpacks/title',
'ubiquity/install/apt_info')
else:
fetchprogress = DebconfAcquireProgress(
self.db, 'ubiquity/install/title', None,
'ubiquity/install/fetch_remove')
installprogress = DebconfInstallProgress(
self.db, 'ubiquity/install/title',
'ubiquity/install/apt_info',
'ubiquity/install/apt_error_install')
chroot_setup(self.target)
commit_error = None
try:
try:
if not self.commit_with_verify(cache,
fetchprogress, installprogress):
fetchprogress.stop()
installprogress.finishUpdate()
self.db.progress('STOP')
self.nested_progress_end()
return
except IOError:
for line in traceback.format_exc().split('\n'):
syslog.syslog(syslog.LOG_ERR, line)
fetchprogress.stop()
installprogress.finishUpdate()
self.db.progress('STOP')
self.nested_progress_end()
return
except SystemError, e:
for line in traceback.format_exc().split('\n'):
syslog.syslog(syslog.LOG_ERR, line)
commit_error = str(e)
finally:
chroot_cleanup(self.target)
self.db.progress('SET', 10)
cache.open(None)
if commit_error or cache._depcache.broken_count > 0:
if commit_error is None:
commit_error = ''
brokenpkgs = broken_packages(cache)
self.warn_broken_packages(brokenpkgs, commit_error)
self.db.progress('STOP')
self.nested_progress_end()
示例3: _AptChangelog
# 需要导入模块: from apt.cache import Cache [as 别名]
# 或者: from apt.cache.Cache import open [as 别名]
class _AptChangelog():
def __init__(self, interactive:bool=False):
self.interactive = interactive
# constants
# apt uses MB rather than MiB, so let's stay consistent
self.MB = 1000 ** 2
# downloads larger than this require confirmation or fail
self.max_download_size_default = 1.5 * self.MB
self.max_download_size = self.max_download_size_default
max_download_size_msg_template = "\
To retrieve the full changelog, %s MB have to be downloaded.\n%s\
\n\
Proceed with the download?"
self.max_download_size_msg_lc = max_download_size_msg_template % ("%.1f",
"Otherwise we will try to retrieve just the last change.\n")
self.max_download_size_msg = max_download_size_msg_template % ("%.1f","")
self.max_download_size_msg_unknown = max_download_size_msg_template % ("an unknown amount of", "")
self.apt_cache = None
self.apt_cache_date = None
self.candidate = None
# get apt's configuration
apt_pkg.init_config()
if apt_pkg.config.exists("Acquire::Changelogs::URI::Origin"):
self.apt_origins = apt_pkg.config.subtree("Acquire::Changelogs::URI::Origin")
else:
self.apt_origins = None
if apt_pkg.config.exists("Dir::Cache::pkgcache"):
self.apt_cache_path = apt_pkg.config.find_dir("Dir::Cache")
self.pkgcache = apt_pkg.config.find_file("Dir::Cache::pkgcache")
else:
self.apt_cache = "invalid"
if (self.apt_cache or
not os.path.isdir(self.apt_cache_path) or
not os.path.isfile(self.pkgcache)
):
print("E: Invalid APT configuration found, try to run `apt update` first",
file=sys.stderr)
self.close(99)
def get_cache_date(self):
if os.path.isfile(self.pkgcache):
return os.path.getmtime(self.pkgcache)
return None
def refresh_cache(self):
cache_date = self.get_cache_date()
if not self.apt_cache:
self.apt_cache = Cache()
self.apt_cache_date = cache_date
elif cache_date != self.apt_cache_date:
self.apt_cache.open(None)
self.apt_cache_date = cache_date
def drop_cache(self):
if self.candidate:
self.candidate = None
self.apt_cache = None
def get_changelog(self, pkg_name:str, no_local:bool=False):
self.refresh_cache()
self.candidate = self.parse_package_metadata(pkg_name)
# parse the package's origin
if not self.candidate.downloadable:
origin = "local_package"
elif self.candidate.origin == "linuxmint":
origin = "linuxmint"
elif self.candidate.origin.startswith("LP-PPA-"):
origin = "LP-PPA"
elif self.apt_origins and self.candidate.origin in self.apt_origins.list():
origin = "APT"
else:
origin = "unsupported"
# Check for changelog of installed package first
has_local_changelog = False
uri = None
if not no_local and self.candidate.is_installed:
if _DEBUG: print("Package is installed...")
uri = self.get_changelog_from_filelist(
self.candidate.installed_files, local=True)
# Ubuntu kernel workarounds
if self.candidate.origin == "Ubuntu":
if self.candidate.source_name == "linux-signed":
uri = uri.replace("linux-image","linux-modules")
if self.candidate.source_name == "linux-meta":
uri = None
if uri and not os.path.isfile(uri):
uri = None
# Do nothing if local changelog exists
if uri:
has_local_changelog = True
# all origins that APT supports
elif origin == 'APT':
#.........这里部分代码省略.........