doc: python bindings HOWTO
authorBen McGinnes <ben@adversary.org>
Fri, 9 Mar 2018 09:45:14 +0000 (20:45 +1100)
committerBen McGinnes <ben@adversary.org>
Fri, 9 Mar 2018 09:45:14 +0000 (20:45 +1100)
* Added instructions and code to count the number of public and secret
  keys available since it was quick and easy.

lang/python/docs/GPGMEpythonHOWTOen.org

index 0b882b5..4385bc9 100644 (file)
    #+end_src
 
 
+* Working with keys
+  :PROPERTIES:
+  :CUSTOM_ID: howto-keys
+  :END:
+
+** Counting keys
+   :PROPERTIES:
+   :CUSTOM_ID: howto-basic-verification
+   :END:
+
+   Counting the number of keys in your public keybox (=pubring.kbx=),
+   the format shich has superceded the old keyring format
+   (=pubring.gpg= and =secring.gpg=) is a very simple task.
+
+   #+begin_src python
+     import gpg
+
+     c = gpg.Context()
+     seckeys = c.keylist(pattern=None, secret=True)
+     pubkeys = c.keylist(pattern=None, secret=False)
+
+     seclist = list(seckeys)
+     secnum = len(seclist)
+
+     publist = list(pubkeys)
+     pubnum = len(publist)
+
+     print("""
+     Number of secret keys:  {0}
+     Number of public keys:  {1}
+     """.format(secnum, pubnum)
+   #+end_src
+
 * Copyright and Licensing
   :PROPERTIES:
   :CUSTOM_ID: copyright-and-license