summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-06-05 19:29:17 +0200
committerJulian Andres Klode <jak@debian.org>2009-06-05 19:29:17 +0200
commitcef966b55a04ad09f38857aa1a3bff3e49b8f6a4 (patch)
tree3b0dcb7758312c33794f0b260a7cf1b73e2924cd
parent994a13b252f97f6ae77872b5d5118ac1366b2a24 (diff)
downloadpython-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.py21
-rw-r--r--doc/source/whatsnew/0.8.0.rst2
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