[Pkg-gnupg-commit] [gpgme] 243/412: python: Improve engine information handling.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:55 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 355d7072863ac1f0f725e77141a59f3ed8a5e4af
Author: Justus Winter <justus at g10code.com>
Date:   Thu Jul 28 11:16:35 2016 +0200

    python: Improve engine information handling.
    
    * lang/python/gpgme.i (gpgme_engine_info_t): Wrap engine infos.
    * lang/python/pyme/core.py (Context.engine_info): New property.
    (Context.{g,s}et_engine_info): Improve docstrings.
    * lang/python/pyme/results.py (EngineInfo): New class.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 lang/python/gpgme.i         | 22 +++++++++++++++++++++-
 lang/python/pyme/core.py    | 38 ++++++++++++++++++++++++++++++--------
 lang/python/pyme/results.py |  3 +++
 3 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 2b186c4..a372edd 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -324,7 +324,7 @@
 
 // Make types containing 'next' field to be lists
 %ignore next;
-%typemap(out) gpgme_sig_notation_t, gpgme_engine_info_t, gpgme_subkey_t,
+%typemap(out) gpgme_sig_notation_t, gpgme_subkey_t,
    gpgme_key_sig_t, gpgme_user_id_t, gpgme_invalid_key_t,
    gpgme_recipient_t, gpgme_new_signature_t, gpgme_signature_t,
    gpgme_import_status_t, gpgme_conf_arg_t, gpgme_conf_opt_t,
@@ -409,6 +409,26 @@
   Py_DECREF(fragile);
 }
 
+%typemap(out) gpgme_engine_info_t {
+  int i;
+  int size = 0;
+  $1_ltype curr;
+  for (curr = $1; curr != NULL; curr = curr->next) {
+    size++;
+  }
+  $result = PyList_New(size);
+  for (i=0,curr=$1; i<size; i++,curr=curr->next) {
+    PyObject *fragile, *o;
+    fragile = SWIG_NewPointerObj(SWIG_as_voidptr(curr), $1_descriptor,
+                                 %newpointer_flags);
+    o = pygpgme_wrap_fragile_result(fragile, "EngineInfo");
+    if (o == NULL)
+      return NULL;	/* raise */
+    Py_DECREF(fragile);
+    PyList_SetItem($result, i, o);
+  }
+}
+
 

 
 // Include mapper for edit callbacks
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index 3ca4747..216e26f 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -666,17 +666,39 @@ class Context(GpgmeWrapper):
         if pygpgme.pygpgme_set_status_cb:
             self.set_status_cb(None)
 
+    @property
+    def engine_info(self):
+        """Configuration of the engine currently in use"""
+        p = self.protocol
+        infos = [i for i in self.get_engine_info() if i.protocol == p]
+        assert len(infos) == 1
+        return infos[0]
+
     def get_engine_info(self):
-        """Returns this context specific engine info"""
+        """Get engine configuration
+
+        Returns information about all configured and installed
+        engines.
+
+        Returns:
+        infos		-- a list of engine infos
+
+        """
         return pygpgme.gpgme_ctx_get_engine_info(self.wrapped)
 
-    def set_engine_info(self, proto, file_name, home_dir=None):
-        """Changes the configuration of the crypto engine implementing the
-    protocol 'proto' for the context. 'file_name' is the file name of
-    the executable program implementing this protocol. 'home_dir' is the
-    directory name of the configuration directory (engine's default is
-    used if omitted)."""
-        errorcheck(pygpgme.gpgme_ctx_set_engine_info(self.wrapped, proto, file_name, home_dir))
+    def set_engine_info(self, proto, file_name=None, home_dir=None):
+        """Change engine configuration
+
+        Changes the configuration of the crypto engine implementing
+        the protocol 'proto' for the context.
+
+        Keyword arguments:
+        file_name	-- engine program file name (unchanged if None)
+        home_dir	-- configuration directory (unchanged if None)
+
+        """
+        errorcheck(pygpgme.gpgme_ctx_set_engine_info(
+            self.wrapped, proto, file_name, home_dir))
 
     def wait(self, hang):
         """Wait for asynchronous call to finish. Wait forever if hang is True.
diff --git a/lang/python/pyme/results.py b/lang/python/pyme/results.py
index aa9b38e..374d982 100644
--- a/lang/python/pyme/results.py
+++ b/lang/python/pyme/results.py
@@ -113,3 +113,6 @@ class KeylistResult(Result):
 
 class VFSMountResult(Result):
     pass
+
+class EngineInfo(Result):
+    pass

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list