diff options
| -rw-r--r-- | apt/cache.py | 21 | ||||
| -rw-r--r-- | doc/source/whatsnew/0.8.0.rst | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/apt/cache.py b/apt/cache.py index 8590510c..16dfc011 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -347,6 +347,27 @@ class Cache(object): self._callbacks[name] = [] self._callbacks[name].append(callback) + def actiongroup(self): + """Return an ActionGroup() object for the current cache. + + Action groups can be used to speedup actions. The action group is + active as soon as it is created, and disabled when the object is + deleted or when release() is called. + + You can use the action group as a context manager, this is the + recommended way:: + + with cache.actiongroup(): + for package in my_selected_packages: + package.mark_install() + + This way, the ActionGroup is automatically released as soon as the + with statement block is left. It also has the benefit of making it + clear which parts of the code run with a action group and which + don't. + """ + return apt_pkg.ActionGroup(self._depcache) + if apt_pkg._COMPAT_0_7: _runCallbacks = function_deprecated_by(_run_callbacks) getChanges = function_deprecated_by(get_changes) diff --git a/doc/source/whatsnew/0.8.0.rst b/doc/source/whatsnew/0.8.0.rst index d507e82a..b2236e44 100644 --- a/doc/source/whatsnew/0.8.0.rst +++ b/doc/source/whatsnew/0.8.0.rst @@ -70,7 +70,7 @@ action group, and is just cooler:: This also works for :class:`apt.Cache`:: - with cache.action_group(): # cache is an Instance of apt.Cache + with cache.actiongroup(): # cache is an Instance of apt.Cache for package in my_selected_packages: package.mark_install() # Instance of apt.Package |
