python: Improve engine information handling.
authorJustus Winter <justus@g10code.com>
Thu, 28 Jul 2016 09:16:35 +0000 (11:16 +0200)
committerJustus Winter <justus@g10code.com>
Thu, 28 Jul 2016 09:16:35 +0000 (11:16 +0200)
* 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@g10code.com>
lang/python/gpgme.i
lang/python/pyme/core.py
lang/python/pyme/results.py

index 2b186c4..a372edd 100644 (file)
 
 // 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,
   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);
+  }
+}
+
 \f
 
 // Include mapper for edit callbacks
index 3ca4747..216e26f 100644 (file)
@@ -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.
index aa9b38e..374d982 100644 (file)
@@ -113,3 +113,6 @@ class KeylistResult(Result):
 
 class VFSMountResult(Result):
     pass
+
+class EngineInfo(Result):
+    pass