[Debconf-devel] Bug#877096: Bug#877096: debconf: Please add a context manager to debconf.py
Colin Watson
cjwatson at debian.org
Sun Oct 15 10:34:54 UTC 2017
Control: tag -1 pending
On Thu, Sep 28, 2017 at 05:09:06PM +0100, Chris Lamb wrote:
> Please consider add a context manager to debconf.py. This would allow
> you to do someting like:
>
> with debconf() as db:
> print(db.get('password/username'))
>
> .. and everything is nicely cleaned up for you.
>
> Patch attached, although making this part of the Debconf class
> (ie. using __enter__ and __exit__) might be even nicer.
Thanks for the patch. I indeed took a somewhat different approach, as
exemplified by the new docstring:
"""A class that speaks the debconf protocol.
The simplest way to use this is as a context manager:
import debconf
with debconf.Debconf(run_frontend=True) as db:
print(db.get('debconf/frontend'))
Note that this will send the STOP command on exiting the context
manager, so you shouldn't expect to be able to use the same frontend
again after this. If you need to do that, then you should instantiate
the class directly instead:
import debconf
db = debconf.Debconf(run_frontend=True)
print(db.get('debconf/frontend'))
"""
This will be in debconf 1.5.64.
--
Colin Watson [cjwatson at debian.org]
More information about the Debconf-devel
mailing list