python: Add convenience functions for the home directory.
authorJustus Winter <justus@g10code.com>
Tue, 14 Feb 2017 12:43:01 +0000 (13:43 +0100)
committerJustus Winter <justus@g10code.com>
Tue, 14 Feb 2017 15:33:19 +0000 (16:33 +0100)
* 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>
NEWS
lang/python/gpg/core.py

diff --git a/NEWS b/NEWS
index 4405f6c..7ec3dfb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
index 43856ab..79d1f53 100644 (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_'