diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-06-05 19:29:17 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-06-05 19:29:17 +0200 |
| commit | cef966b55a04ad09f38857aa1a3bff3e49b8f6a4 (patch) | |
| tree | 3b0dcb7758312c33794f0b260a7cf1b73e2924cd | |
| parent | 994a13b252f97f6ae77872b5d5118ac1366b2a24 (diff) | |
| download | python-apt-cef966b55a04ad09f38857aa1a3bff3e49b8f6a4.tar.gz | |
apt/cache.py: Introduce Cache.actiongroup()
This is a short function which creates an actiongroup on the current
depcache.
| -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 |
