summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-04-19 15:57:07 +0200
committerJulian Andres Klode <jak@debian.org>2009-04-19 15:57:07 +0200
commita7026989dd1ea3b70cbfc80cf92077efb2f52ba3 (patch)
tree4a79e7bc14003da0451e55da507add14989811c9
parent45cdd4f2c6b04bfdfd37ef0e1a6358b29680afb8 (diff)
downloadpython-apt-a7026989dd1ea3b70cbfc80cf92077efb2f52ba3.tar.gz
ActionGroups can be used as a context manager for the 'with' statement.
-rw-r--r--debian/changelog1
-rw-r--r--python/depcache.cc32
2 files changed, 28 insertions, 5 deletions
diff --git a/debian/changelog b/debian/changelog
index e8e14306..30d54a29 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ python-apt (0.7.91) UNRELEASED; urgency=low
* Rename all methods,functions,attributes to conform to PEP 8 (Closes: #481061)
* Where possible, derive apt.package.Record from collections.Mapping.
+ * ActionGroups can be used as a context manager for the 'with' statement.
-- Julian Andres Klode <jak@debian.org> Fri, 17 Apr 2009 17:48:27 +0200
diff --git a/python/depcache.cc b/python/depcache.cc
index 0cadee64..70d5af4e 100644
--- a/python/depcache.cc
+++ b/python/depcache.cc
@@ -852,9 +852,24 @@ static PyObject *PkgActionGroupRelease(PyObject *Self,PyObject *Args)
return HandleErrors(Py_None);
}
+static PyObject *PkgActionGroupEnter(PyObject *Self,PyObject *Args) {
+ if (PyArg_ParseTuple(Args,"") == 0)
+ return 0;
+ return Self;
+}
+static PyObject *PkgActionGroupExit(PyObject *Self,PyObject *Args) {
+ pkgDepCache::ActionGroup *ag = GetCpp<pkgDepCache::ActionGroup*>(Self);
+ ag->release();
+ Py_RETURN_FALSE;
+}
+
static PyMethodDef PkgActionGroupMethods[] =
{
{"release", PkgActionGroupRelease, METH_VARARGS, "release()"},
+ {"__exit__", PkgActionGroupExit, METH_VARARGS, "__exit__(...) -> "
+ "Release the action group, for 'with' statement."},
+ {"__enter__", PkgActionGroupEnter, METH_VARARGS, "__enter__() -> "
+ "Enter, for the 'with' statement. Does nothing."},
{}
};
@@ -879,11 +894,18 @@ static PyObject *PkgActionGroupNew(PyTypeObject *type,PyObject *Args,PyObject *k
}
static const char *doc_PkgActionGroup = "ActionGroup(depcache)\n\n"
- "Create a new ActionGroup() object. ActionGroups disable certain cleanup\n"
- "actions, so modifying many packages is much faster.\n\n"
- "Creating an ActionGroup() makes it active, use release() to disable it\n"
- "again.\n\n"
- "The parameter *depcache* refers to an apt_pkg.DepCache() object.";
+ "Create a new ActionGroup() object. The parameter *depcache* refers to an\n"
+ "apt_pkg.DepCache() object.\n\n"
+ "ActionGroups disable certain cleanup actions, so modifying many packages\n"
+ "is much faster.\n\n"
+ "ActionGroup() can also be used with the 'with' statement, but be aware\n"
+ "that the ActionGroup() is active as soon as it is created, and not just\n"
+ "when entering the context. This means you can write::\n\n"
+ " with apt_pkg.ActionGroup(depcache):\n"
+ " depcache.markInstall(pkg)\n\n"
+ "Once the block of the with statement is left, the action group is \n"
+ "automatically released from the cache.";
+
PyTypeObject PkgActionGroupType =
{