diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-04-17 17:12:35 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-04-17 17:12:35 +0200 |
| commit | 5b6ecbeef7e5a2dbc02e026f086ac2d9f185a546 (patch) | |
| tree | 095297a1818fa21606fdb60bceab6711a84cc470 | |
| parent | 43605018bd3b0f6b0bf26736b7e13c170131883a (diff) | |
| download | python-apt-5b6ecbeef7e5a2dbc02e026f086ac2d9f185a546.tar.gz | |
* apt/cache.py, apt/package.py: Rename the remaining arguments and variables.
| -rw-r--r-- | apt/cache.py | 176 | ||||
| -rw-r--r-- | apt/package.py | 92 |
2 files changed, 148 insertions, 120 deletions
diff --git a/apt/cache.py b/apt/cache.py index 928322d2..05d8d1a9 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -24,7 +24,8 @@ import weakref import apt_pkg from apt import Package -from apt.deprecation import AttributeDeprecatedBy, function_deprecated_by +from apt.deprecation import (AttributeDeprecatedBy, function_deprecated_by, + deprecated_args) import apt.progress @@ -132,18 +133,22 @@ class Cache(object): def get_changes(self): """ Get the marked changes """ changes = [] - for p in self: - if p.marked_upgrade or p.marked_install or p.marked_delete or \ - p.marked_downgrade or p.marked_reinstall: - changes.append(p) + for pkg in self: + if (pkg.marked_upgrade or pkg.marked_install or pkg.marked_delete + or pkg.marked_downgrade or pkg.marked_reinstall): + changes.append(pkg) return changes - def upgrade(self, distUpgrade=False): - """ Upgrade the all package, DistUpgrade will also install - new dependencies + @deprecated_args + def upgrade(self, dist_upgrade=False): + """Upgrade all packages. + + If the parameter *dist_upgrade* is True, new dependencies will be + installed as well (and conflicting packages may be removed). The + default value is False. """ self.cache_pre_change() - self._depcache.Upgrade(distUpgrade) + self._depcache.Upgrade(dist_upgrade) self.cache_post_change() @property @@ -177,22 +182,22 @@ class Cache(object): # now check the result (this is the code from apt-get.cc) failed = False transient = False - errMsg = "" + err_msg = "" for item in fetcher.Items: if item.Status == item.StatDone: continue if item.StatIdle: transient = True continue - errMsg += "Failed to fetch %s %s\n" % (item.DescURI, + err_msg += "Failed to fetch %s %s\n" % (item.DescURI, item.ErrorText) failed = True # we raise a exception if the download failed or it was cancelt if res == fetcher.ResultCancelled: - raise FetchCancelledException(errMsg) + raise FetchCancelledException(err_msg) elif failed: - raise FetchFailedException(errMsg) + raise FetchFailedException(err_msg) return res def _fetch_archives(self, fetcher, pm): @@ -241,34 +246,57 @@ class Cache(object): providers.append(pkg) return providers - def update(self, fetchProgress=None): - " run the equivalent of apt-get update " + @deprecated_args + def update(self, fetch_progress=None): + """Run the equivalent of apt-get update. + + The first parameter *fetch_progress* may be set to an instance of + apt.progress.FetchProgress, the default is apt.progress.FetchProgress() + . + """ lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock" lock = apt_pkg.GetLock(lockfile) if lock < 0: raise LockFailedException("Failed to lock %s" % lockfile) try: - if fetchProgress is None: - fetchProgress = apt.progress.FetchProgress() - return self._cache.Update(fetchProgress, self._list) + if fetch_progress is None: + fetch_progress = apt.progress.FetchProgress() + return self._cache.Update(fetch_progress, self._list) finally: os.close(lock) - def install_archives(self, pm, installProgress): + @deprecated_args + def install_archives(self, pm, install_progress): + """ + The first parameter *pm* refers to an object returned by + apt_pkg.GetPackageManager(). + + The second parameter *install_progress* refers to an InstallProgress() + object of the module apt.progress. + """ try: - installProgress.start_update() + install_progress.start_update() except AttributeError: - installProgress.startUpdate() - res = installProgress.run(pm) + install_progress.startUpdate() + res = install_progress.run(pm) try: - installProgress.finish_update() + install_progress.finish_update() except AttributeError: - installProgress.finishUpdate() + install_progress.finishUpdate() return res - def commit(self, fetchProgress=None, installProgress=None): - """ Apply the marked changes to the cache """ + @deprecated_args + def commit(self, fetch_progress=None, install_progress=None): + """Apply the marked changes to the cache. + + The first parameter, *fetch_progress*, refers to a FetchProgress() + object as found in apt.progress, the default being + apt.progress.FetchProgress(). + + The second parameter, *install_progress*, is a + apt.progress.InstallProgress() object. + """ # FIXME: # use the new acquire/pkgmanager interface here, # raise exceptions when a download or install fails @@ -276,19 +304,19 @@ class Cache(object): # Current a failed download will just display "error" # which is less than optimal! - if fetchProgress is None: - fetchProgress = apt.progress.FetchProgress() - if installProgress is None: - installProgress = apt.progress.InstallProgress() + if fetch_progress is None: + fetch_progress = apt.progress.FetchProgress() + if install_progress is None: + install_progress = apt.progress.InstallProgress() pm = apt_pkg.GetPackageManager(self._depcache) - fetcher = apt_pkg.GetAcquire(fetchProgress) + fetcher = apt_pkg.GetAcquire(fetch_progress) while True: # fetch archives first res = self._fetch_archives(fetcher, pm) # then install - res = self.install_archives(pm, installProgress) + res = self.install_archives(pm, install_progress) if res == pm.ResultCompleted: break if res == pm.ResultFailed: @@ -442,59 +470,57 @@ def _test(): """Internal test code.""" print "Cache self test" apt_pkg.init() - c = Cache(apt.progress.OpTextProgress()) - c.connect("cache_pre_change", cache_pre_changed) - c.connect("cache_post_change", cache_post_changed) - print ("aptitude" in c) - p = c["aptitude"] - print p.name - print len(c) - - for pkg in c.keys(): - x= c[pkg].name - - c.upgrade() - changes = c.get_changes() + cache = Cache(apt.progress.OpTextProgress()) + cache.connect("cache_pre_change", cache_pre_changed) + cache.connect("cache_post_change", cache_post_changed) + print ("aptitude" in cache) + pkg = cache["aptitude"] + print pkg.name + print len(cache) + + for pkgname in cache.keys(): + assert cache[pkgname].name == pkgname + + cache.upgrade() + changes = cache.get_changes() print len(changes) - for p in changes: - #print p.name - x = p.name + for pkg in changes: + assert pkg.name + # see if fetching works - for d in ["/tmp/pytest", "/tmp/pytest/partial"]: - if not os.path.exists(d): - os.mkdir(d) + for dir in ["/tmp/pytest", "/tmp/pytest/partial"]: + if not os.path.exists(dir): + os.mkdir(dir) apt_pkg.Config.Set("Dir::Cache::Archives", "/tmp/pytest") - pm = apt_pkg.GetPackageManager(c._depcache) + pm = apt_pkg.GetPackageManager(cache._depcache) fetcher = apt_pkg.GetAcquire(apt.progress.TextFetchProgress()) - c._fetch_archives(fetcher, pm) + cache._fetch_archives(fetcher, pm) #sys.exit(1) print "Testing filtered cache (argument is old cache)" - f = FilteredCache(c) - f.cache.connect("cache_pre_change", cache_pre_changed) - f.cache.connect("cache_post_change", cache_post_changed) - f.cache.upgrade() - f.set_filter(MarkedChangesFilter()) - print len(f) - for pkg in f.keys(): - #print c[pkg].name - x = f[pkg].name - - print len(f) + filtered = FilteredCache(cache) + filtered.cache.connect("cache_pre_change", cache_pre_changed) + filtered.cache.connect("cache_post_change", cache_post_changed) + filtered.cache.upgrade() + filtered.set_filter(MarkedChangesFilter()) + print len(filtered) + for pkgname in filtered.keys(): + assert pkgname == filtered[pkg].name + + print len(filtered) print "Testing filtered cache (no argument)" - f = FilteredCache(progress=apt.progress.OpTextProgress()) - f.cache.connect("cache_pre_change", cache_pre_changed) - f.cache.connect("cache_post_change", cache_post_changed) - f.cache.upgrade() - f.set_filter(MarkedChangesFilter()) - print len(f) - for pkg in f.keys(): - #print c[pkg].name - x = f[pkg].name - - print len(f) + filtered = FilteredCache(progress=apt.progress.OpTextProgress()) + filtered.cache.connect("cache_pre_change", cache_pre_changed) + filtered.cache.connect("cache_post_change", cache_post_changed) + filtered.cache.upgrade() + filtered.set_filter(MarkedChangesFilter()) + print len(filtered) + for pkgname in filtered.keys(): + assert pkgname == filtered[pkgname].name + + print len(filtered) if __name__ == '__main__': _test() diff --git a/apt/package.py b/apt/package.py index 70997383..cf1ff2ae 100644 --- a/apt/package.py +++ b/apt/package.py @@ -31,7 +31,8 @@ import warnings import apt_pkg import apt.progress -from apt.deprecation import function_deprecated_by, AttributeDeprecatedBy +from apt.deprecation import (function_deprecated_by, AttributeDeprecatedBy, + deprecated_args) __all__ = ('BaseDependency', 'Dependency', 'Origin', 'Package', 'Record', 'Version') @@ -123,15 +124,15 @@ class Origin(object): trusted - Boolean value whether this is trustworthy. """ - def __init__(self, pkg, VerFileIter): - self.archive = VerFileIter.Archive - self.component = VerFileIter.Component - self.label = VerFileIter.Label - self.origin = VerFileIter.Origin - self.site = VerFileIter.Site - self.not_automatic = VerFileIter.NotAutomatic + def __init__(self, pkg, packagefile): + self.archive = packagefile.Archive + self.component = packagefile.Component + self.label = packagefile.Label + self.origin = packagefile.Origin + self.site = packagefile.Site + self.not_automatic = packagefile.NotAutomatic # check the trust - indexfile = pkg._pcache._list.FindIndex(VerFileIter) + indexfile = pkg._pcache._list.FindIndex(packagefile) if indexfile and indexfile.IsTrusted: self.trusted = True else: @@ -266,7 +267,7 @@ class Version(object): return self._cand.Section @property - def description(self, format=True, useDots=False): + def description(self): """Return the formatted long description. Return the formated long description according to the Debian policy @@ -276,7 +277,6 @@ class Version(object): """ self.summary # This does the lookup for us. desc = '' - dsc = self.package._pcache._records.LongDesc try: if not isinstance(dsc, unicode): @@ -339,11 +339,11 @@ class Version(object): depends = self._cand.DependsList for t in ["PreDepends", "Depends"]: try: - for depVerList in depends[t]: + for dep_ver_list in depends[t]: base_deps = [] - for depOr in depVerList: - base_deps.append(BaseDependency(depOr.TargetPkg.Name, - depOr.CompType, depOr.TargetVer, + for dep_or in dep_ver_list: + base_deps.append(BaseDependency(dep_or.TargetPkg.Name, + dep_or.CompType, dep_or.TargetVer, (t == "PreDepends"))) depends_list.append(Dependency(base_deps)) except KeyError: @@ -354,8 +354,8 @@ class Version(object): def origins(self): """Return a list of origins for the package version.""" origins = [] - for (verFileIter, index) in self._cand.FileList: - origins.append(Origin(self.package, verFileIter)) + for (packagefile, index) in self._cand.FileList: + origins.append(Origin(self.package, packagefile)) return origins @property @@ -566,21 +566,21 @@ class Package(object): return self._pkg.ID @DeprecatedProperty - def installedVersion(self): + def installedVersion(self): #pylint: disable-msg=C0103 """Return the installed version as string. .. deprecated:: 0.7.9""" return getattr(self.installed, 'version', None) @DeprecatedProperty - def candidateVersion(self): + def candidateVersion(self): #pylint: disable-msg=C0103 """Return the candidate version as string. .. deprecated:: 0.7.9""" return getattr(self.candidate, "version", None) @DeprecatedProperty - def candidateDependencies(self): + def candidateDependencies(self): #pylint: disable-msg=C0103 """Return a list of candidate dependencies. .. deprecated:: 0.7.9 @@ -588,7 +588,7 @@ class Package(object): return getattr(self.candidate, "dependencies", None) @DeprecatedProperty - def installedDependencies(self): + def installedDependencies(self): #pylint: disable-msg=C0103 """Return a list of installed dependencies. .. deprecated:: 0.7.9 @@ -604,7 +604,7 @@ class Package(object): return getattr(self.candidate, "architecture", None) @DeprecatedProperty - def candidateDownloadable(self): + def candidateDownloadable(self): #pylint: disable-msg=C0103 """Return ``True`` if the candidate is downloadable. .. deprecated:: 0.7.9 @@ -612,7 +612,7 @@ class Package(object): return getattr(self.candidate, "downloadable", None) @DeprecatedProperty - def installedDownloadable(self): + def installedDownloadable(self): #pylint: disable-msg=C0103 """Return ``True`` if the installed version is downloadable. .. deprecated:: 0.7.9 @@ -620,7 +620,7 @@ class Package(object): return getattr(self.installed, 'downloadable', False) @DeprecatedProperty - def sourcePackageName(self): + def sourcePackageName(self): #pylint: disable-msg=C0103 """Return the source package name as string. .. deprecated:: 0.7.9 @@ -655,7 +655,7 @@ class Package(object): return getattr(self.candidate, "priority", None) @DeprecatedProperty - def installedPriority(self): + def installedPriority(self): #pylint: disable-msg=C0103 """Return the priority (of the installed version). .. deprecated:: 0.7.9 @@ -684,21 +684,21 @@ class Package(object): return getattr(self.candidate, "description", None) @DeprecatedProperty - def rawDescription(self): + def rawDescription(self): #pylint: disable-msg=C0103 """return the long description (raw). .. deprecated:: 0.7.9""" return getattr(self.candidate, "raw_description", None) @DeprecatedProperty - def candidateRecord(self): + def candidateRecord(self): #pylint: disable-msg=C0103 """Return the Record of the candidate version of the package. .. deprecated:: 0.7.9""" return getattr(self.candidate, "record", None) @DeprecatedProperty - def installedRecord(self): + def installedRecord(self): #pylint: disable-msg=C0103 """Return the Record of the candidate version of the package. .. deprecated:: 0.7.9""" @@ -761,7 +761,7 @@ class Package(object): # sizes @DeprecatedProperty - def packageSize(self): + def packageSize(self): #pylint: disable-msg=C0103 """Return the size of the candidate deb package. .. deprecated:: 0.7.9 @@ -769,7 +769,7 @@ class Package(object): return getattr(self.candidate, "size", None) @DeprecatedProperty - def installedPackageSize(self): + def installedPackageSize(self): #pylint: disable-msg=C0103 """Return the size of the installed deb package. .. deprecated:: 0.7.9 @@ -777,7 +777,7 @@ class Package(object): return getattr(self.installed, 'size', 0) @DeprecatedProperty - def candidateInstalledSize(self): + def candidateInstalledSize(self): #pylint: disable-msg=C0103 """Return the size of the candidate installed package. .. deprecated:: 0.7.9 @@ -785,7 +785,7 @@ class Package(object): return getattr(self.candidate, "installed_size", None) @DeprecatedProperty - def installedSize(self): + def installedSize(self): #pylint: disable-msg=C0103 """Return the size of the currently installed package. @@ -964,7 +964,7 @@ class Package(object): return self._changelog @DeprecatedProperty - def candidateOrigin(self): + def candidateOrigin(self): #pylint: disable-msg=C0103 """Return a list of `Origin()` objects for the candidate version. .. deprecated:: 0.7.9 @@ -987,10 +987,11 @@ class Package(object): self._pcache._depcache.MarkKeep(self._pkg) self._pcache.cache_post_change() - def mark_delete(self, autoFix=True, purge=False): + @deprecated_args + def mark_delete(self, auto_fix=True, purge=False): """Mark a package for install. - If *autoFix* is ``True``, the resolver will be run, trying to fix + If *auto_fix* is ``True``, the resolver will be run, trying to fix broken packages. This is the default. If *purge* is ``True``, remove the configuration files of the package @@ -999,16 +1000,17 @@ class Package(object): self._pcache.cache_pre_change() self._pcache._depcache.MarkDelete(self._pkg, purge) # try to fix broken stuffsta - if autoFix and self._pcache._depcache.BrokenCount > 0: - Fix = apt_pkg.GetPkgProblemResolver(self._pcache._depcache) - Fix.Clear(self._pkg) - Fix.Protect(self._pkg) - Fix.Remove(self._pkg) - Fix.InstallProtect() - Fix.Resolve() + if auto_fix and self._pcache._depcache.BrokenCount > 0: + fix = apt_pkg.GetPkgProblemResolver(self._pcache._depcache) + fix.Clear(self._pkg) + fix.Protect(self._pkg) + fix.Remove(self._pkg) + fix.InstallProtect() + fix.Resolve() self._pcache.cache_post_change() - def mark_install(self, autoFix=True, autoInst=True, fromUser=True): + @deprecated_args + def mark_install(self, auto_fix=True, auto_inst=True, from_user=True): """Mark a package for install. If *autoFix* is ``True``, the resolver will be run, trying to fix @@ -1023,9 +1025,9 @@ class Package(object): when no other package depends on it. """ self._pcache.cache_pre_change() - self._pcache._depcache.MarkInstall(self._pkg, autoInst, fromUser) + self._pcache._depcache.MarkInstall(self._pkg, auto_inst, from_user) # try to fix broken stuff - if autoFix and self._pcache._depcache.BrokenCount > 0: + if auto_fix and self._pcache._depcache.BrokenCount > 0: fixer = apt_pkg.GetPkgProblemResolver(self._pcache._depcache) fixer.Clear(self._pkg) fixer.Protect(self._pkg) |
