[Pgp-tools-commit] r640 - in trunk/keyart: . doc

Aaron Toponce atoponce-guest at moszumanska.debian.org
Fri Jun 13 14:23:10 UTC 2014


Author: atoponce-guest
Date: 2014-06-13 14:23:10 +0000 (Fri, 13 Jun 2014)
New Revision: 640

Modified:
   trunk/keyart/doc/keyart.1
   trunk/keyart/keyart
Log:
Much code update and many manpage update

The '-i|--id' and '-k|--keyring' options are now mutually exclusive, require at
least one argument, and one of them is required to be passed to the command.
Currently, '-k|--keyring' code is not implemented- coming soon.

Did some code changing to introduce a 'test_env()' function and moved logic
around a bit making it easier to work with. Also micro-optimized creating the
little endian array.

Updated the keyart.1 manpage to reflect the new options.



Modified: trunk/keyart/doc/keyart.1
===================================================================
--- trunk/keyart/doc/keyart.1	2014-06-12 12:20:33 UTC (rev 639)
+++ trunk/keyart/doc/keyart.1	2014-06-13 14:23:10 UTC (rev 640)
@@ -5,12 +5,12 @@
 .B keyart
 \- Create ASCII art of an OpenPGP key.
 .SH SYNOPSIS
-.B keyart [-a|--ansi] KEYID
+.B keyart [-a|--ansi] (-i|--id KEYID [KEYID ...] | -k|--keyring KEYRING [KEYRING ...])
 .SH DESCRIPTION
 .B keyart
-creates an ASCII art representation of a public OpenPGP key in your keyring. The
-art is an implementation of the Drunken Bishop by Dirk Loss. Documentation about
-the algorithm can be found /usr/share/doc/keyart/, or as appropriate for your
+creates an ASCII art representation of a public OpenPGP key. The art is an
+implementation of the Drunken Bishop by Dirk Loss. Documentation about the
+algorithm can be found /usr/share/doc/keyart/, or as appropriate for your
 distribution.
 
 .B keyart
@@ -21,11 +21,19 @@
 color to printed character.
 .SH OPTIONS
 .TP 8
-.B -a | --ansi
-\- Print the ASCII art using ANSI color to the terminal.
-.B KEYID
-\- Required. Can be any string that uniquely identifies a key, such as name,
-email, short key ID, long key ID, fingerprint, etc.
+.B \-a \fR|\fI \-\-ansi
+Print the ASCII art using ANSI color to the terminal.
+.TP 8
+.B \-i \fR|\fI \-\-id KEYID [KEYID ...]
+A key identifier. Can be an email, fingerprint, keyid, name, etc. Either \-i or
+\-k are required.
+.TP 8
+.B \-k \fR|\fI \-\-keyring KEYRING [KEYRING ...]
+A pubic GPG keyring file. Code currently not implemented. Either \-i or \-k are
+required.
+.TP 8
+.B \-h \fR|\fI \-\-help
+Print the help message and quit.
 .SH SEE ALSO
 .BR gpg (1)
 .SH AUTHOR

Modified: trunk/keyart/keyart
===================================================================
--- trunk/keyart/keyart	2014-06-12 12:20:33 UTC (rev 639)
+++ trunk/keyart/keyart	2014-06-13 14:23:10 UTC (rev 640)
@@ -8,36 +8,25 @@
 
 parser = argparse.ArgumentParser(description='Create an ASCII art of a PGP key.')
 group = parser.add_mutually_exclusive_group(required=True)
-parser.add_argument('-a','--ansi', help='Print the art with ANSI color.', action='store_true')
-group.add_argument('-i', '--id', action='store_false', help='A key identifier.')
-#group.add_argument('-k', '--keyring', action='store_true', help='A GPG keyring.')
-parser.add_argument('KEYID', nargs='+')
+parser.add_argument('-a','--ansi', help='Print the art with ANSI color.')
+group.add_argument('-i', '--id', type=str, nargs='+', metavar=('KEID'),
+    help='A key identifier.')
+group.add_argument('-k', '--keyring', type=str, nargs='+', metavar=('KEYRING'),
+    help='A GPG keyring.')
 args = parser.parse_args()
 
-def draw_art(key):
+def test_env():
     try:
         if os.access('/usr/bin/gpg',os.X_OK):
             gpg_bin = '/usr/bin/gpg'
         else:
             gpg_bin = '/usr/bin/gpg2'
-
-        DEVNULL = open(os.devnull, 'wb')
-        gpg = subprocess.Popen(('gpg', '--fingerprint', '--with-colons', key),stdout=subprocess.PIPE, stderr=DEVNULL)
-        out = gpg.communicate()
-        DEVNULL.close()
+        return gpg_bin
     except OSError:
         print "Please install GnuPG before using this script."
         sys.exit(4)
 
-    try:
-        key_size = out[0].split('\n')[1].split(':')[2]
-        key_algo = out[0].split('\n')[1].split(':')[3]
-        key_fpr =  out[0].split('\n')[2].split(':')[9]
-
-    except IndexError:
-        print "It appears that {0} is not an exported public PGP key.".format(key)
-        sys.exit(5)
-
+def draw_art(key_size, key_algo, key_fpr):
     art = ''
     f_bytes = []
     pos = 104
@@ -52,12 +41,10 @@
             f_bytes.append(temp)
             temp = ''
 
-    for i,c in enumerate(f_bytes):
-        if i % 4 == 0:
-            f_bytes[i],f_bytes[i+3] = f_bytes[i+3],f_bytes[i]
-        if i % 4 == 1:
-            f_bytes[i],f_bytes[i+1] = f_bytes[i+1],f_bytes[i]
-            i += 2
+    # create a little-endian bit-pair array
+    for i in xrange(0, len(f_bytes), 4):
+        f_bytes[i],f_bytes[i+3] = f_bytes[i+3],f_bytes[i]
+        f_bytes[i+1],f_bytes[i+2] = f_bytes[i+2],f_bytes[i+1]
 
     for d in f_bytes:
         if (20 <= pos <=  36 or  39 <= pos <=  55 or  58 <= pos <=  74 or
@@ -205,6 +192,26 @@
     return '{}{}{}'.format(color, coin, reset)
 
 if __name__ == '__main__':
-    if args.KEYID:
-        for key in args.KEYID:
-            print draw_art(key)
+    gpg_bin = test_env()
+    DEVNULL = open(os.devnull, 'wb')
+
+    if args.id:
+        for key in args.id:
+            gpg = subprocess.Popen((gpg_bin, '--fingerprint',
+                '--with-colons', key),stdout=subprocess.PIPE, stderr=DEVNULL)
+            out = gpg.communicate()
+
+            key_size = out[0].split('\n')[1].split(':')[2]
+            key_algo = out[0].split('\n')[1].split(':')[3]
+            key_fpr =  out[0].split('\n')[2].split(':')[9]
+
+            print draw_art(key_size, key_algo, key_fpr)
+
+    if args.keyring:
+        print "This code isn't ready."
+        #for keyring in args.keyring:
+        #    gpg = subprocess.Popen((gpg_bin, '--with-fingerprint',
+        #        '--with-colons', key),stdout=subprocess.PIPE, stderr=DEVNULL)
+        #    out = gpg.communicate()
+
+    DEVNULL.close()




More information about the Pgp-tools-commit mailing list