On Fri, Aug 21, 2009 at 12:23:20AM +0200, Julian Andres Klode wrote: > On Wed, Aug 19, 2009 at 05:00:12PM +0200, Sebastian Heinlein wrote: > > Package: python-apt > > Version: 0.7.12.1 > > Severity: normal > > > > In PackageKit apt backend I use the problem resolver directly e.g. to make sure > > that all given packages are installed which are queued for a transaction. > > > > Just calling apt.Packagek.mark_install for each package could unmark the > > installation of a previous package during the resolver call (autoFix=True). > > So I have to protect all the to be installed packages in the resolver. > > > > The factory apt_pkg.GetPkgProblemResolver requires the private _depcache of > > an apt.Cache. Furthermore I need the IsInstBroken and IsNowBroken method for > > a more detailed error reporting. > > > > It would be nice to habe a stable API for this. > See the attached patch. This should probably do what you want. The file was created by cdiff, not by diff, sorry. The attached patch is the patch I will commit in a few hours, after checking that the docstrings correctly describe the behaviour. This also increases the version to 0.7.13.0 as it introduces a new class, which can be seen as a relatively large change. -- Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.
=== modified file 'apt/__init__.py' --- apt/__init__.py 2009-04-01 14:27:15 +0000 +++ apt/__init__.py 2009-08-20 22:20:41 +0000 @@ -23,7 +23,7 @@ import os # import some fancy classes from apt.package import Package -from apt.cache import Cache +from apt.cache import Cache, ProblemResolver from apt.progress import ( OpProgress, FetchProgress, InstallProgress, CdromProgress) from apt.cdrom import Cdrom === modified file 'apt/cache.py' --- apt/cache.py 2009-07-30 13:00:44 +0000 +++ apt/cache.py 2009-08-20 22:41:46 +0000 @@ -91,7 +91,6 @@ class Cache(object): for f in files: if not os.path.exists(rootdir+f): open(rootdir+f,"w") - def _runCallbacks(self, name): """ internal helper to run a callback """ @@ -363,6 +362,40 @@ class Cache(object): return self._depcache.keep_count +class ProblemResolver(object): + """Resolve problems due to dependencies and conflicts. + + The first argument 'cache' is an instance of apt.Cache. + """ + + def __init__(self, cache): + self._resolver = apt_pkg.GetPkgProblemResolver(cache._depcache) + + def clear(self, package): + """Remove the package (???)""" + self._resolver.Clear(package._pkg) + + def install_protect(self): + """Protect all installed packages so they won't be removed.""" + self._resolver.InstallProtect() + + def protect(self, package): + """Protect a package so it won't be removed.""" + self._resolver.Protect(package._pkg) + + def remove(self, package): + """Remove a package.""" + self._resolver.Remove(package._pkg) + + def resolve(self): + """Resolve dependencies, try to remove packages where needed.""" + self._resolver.Resolve() + + def resolve_by_keep(self): + """Resolve dependencies, do not try to remove packages.""" + self._resolver.ResolveByKeep() + + # ----------------------------- experimental interface === modified file 'apt/package.py' --- apt/package.py 2009-08-20 21:14:19 +0000 +++ apt/package.py 2009-08-20 22:37:30 +0000 @@ -1008,6 +1008,16 @@ class Package(object): """ return VersionList(self) + @property + def is_inst_broken(self): + """Return True if the to-be-installed package is broken.""" + return self._pcache._depcache.IsInstBroken(self._pkg) + + @property + def is_now_broken(self): + """Return True if the installed package is broken.""" + return self._pcache._depcache.IsNowBroken(self._pkg) + # depcache actions def markKeep(self): === modified file 'debian/changelog' --- debian/changelog 2009-08-20 21:14:19 +0000 +++ debian/changelog 2009-08-20 22:40:48 +0000 @@ -1,4 +1,4 @@ -python-apt (0.7.12.2) UNRELEASED; urgency=low +python-apt (0.7.13.0) UNRELEASED; urgency=low [ Michael Vogt ] * apt/package.py: @@ -9,8 +9,11 @@ python-apt (0.7.12.2) UNRELEASED; urgenc - Introduce Version.get_dependencies() which takes one or more types of dependencies and returns a list of Dependency objects. - Do not mark the package as manually installed on upgrade (Closes: #542699) + - Add Package.is_now_broken and Package.is_inst_broken. + * apt/cache.py: + - Introduce ProblemResolver class (Closes: #542705) - -- Julian Andres Klode <jak@debian.org> Thu, 20 Aug 2009 23:13:00 +0200 + -- Julian Andres Klode <jak@debian.org> Fri, 21 Aug 2009 00:40:37 +0200 python-apt (0.7.12.1) unstable; urgency=low
Attachment:
pgpcLV38uiAbf.pgp
Description: PGP signature