python: Add convenience functions for the home directory.

* NEWS: Update.
* lang/python/gpg/core.py (Context.__init__): Add 'home_dir' argument.
(__repr__): Include 'home_dir'.
(Context.home_dir): New property.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2017-02-14 13:43:01 +01:00
parent 30a603580e
commit 99b7f4f34d
No known key found for this signature in database
GPG Key ID: DD1A52F9DA8C9020
2 changed files with 14 additions and 2 deletions

2
NEWS
View File

@ -13,6 +13,8 @@ Noteworthy changes in version 1.8.1 (unreleased)
cpp: Key::addUid() NEW.
qt: CryptoConfig::stringValueList() NEW.
gpgme_data_rewind UN-DEPRECATE.
py: Context.__init__ EXTENDED: New keyword argument home_dir.
py: Context.home_dir NEW.
Noteworthy changes in version 1.8.0 (2016-11-16)

View File

@ -176,7 +176,7 @@ class Context(GpgmeWrapper):
def __init__(self, armor=False, textmode=False, offline=False,
signers=[], pinentry_mode=constants.PINENTRY_MODE_DEFAULT,
protocol=constants.PROTOCOL_OpenPGP,
wrapped=None):
wrapped=None, home_dir=None):
"""Construct a context object
Keyword arguments:
@ -186,6 +186,7 @@ class Context(GpgmeWrapper):
signers -- list of keys used for signing (default [])
pinentry_mode -- pinentry mode (default PINENTRY_MODE_DEFAULT)
protocol -- protocol to use (default PROTOCOL_OpenPGP)
home_dir -- state directory (default is the engine default)
"""
if wrapped:
@ -203,13 +204,14 @@ class Context(GpgmeWrapper):
self.signers = signers
self.pinentry_mode = pinentry_mode
self.protocol = protocol
self.home_dir = home_dir
def __repr__(self):
return (
"Context(armor={0.armor}, "
"textmode={0.textmode}, offline={0.offline}, "
"signers={0.signers}, pinentry_mode={0.pinentry_mode}, "
"protocol={0.protocol}"
"protocol={0.protocol}, home_dir={0.home_dir}"
")").format(self)
def encrypt(self, plaintext, recipients=[], sign=True, sink=None,
@ -610,6 +612,14 @@ class Context(GpgmeWrapper):
errorcheck(gpgme.gpgme_engine_check_version(value))
self.set_protocol(value)
@property
def home_dir(self):
"""Engine's home directory"""
return self.engine_info.home_dir
@home_dir.setter
def home_dir(self, value):
self.set_engine_info(self.protocol, home_dir=value)
_ctype = 'gpgme_ctx_t'
_cprefix = 'gpgme_'