Add finduser -1 and adduser -v flags
authorRich Salz <rsalz@openssl.org>
Sun, 27 Aug 2017 13:02:21 +0000 (09:02 -0400)
committerRich Salz <rsalz@openssl.org>
Sun, 27 Aug 2017 13:03:00 +0000 (09:03 -0400)
license/approved
license/finduser

index c667a5ea44a1a90355078a22059550f18b0dccac..6d84dabe8fe384d3e606a4e9c9e6429ebfb36b88 100755 (executable)
@@ -5,6 +5,7 @@ Flags:
     -c text...  Comment to use
     -r          Reject not approve
     -h          This help
+    -v          List emails as processed
 
 Args is a list of email addresses.
 """
@@ -24,12 +25,15 @@ cursor = conn.cursor()
 # Parse JCL
 comment = 'From CLI';
 reply = 'y'
-opts, args = getopt.getopt(sys.argv[1:], "c:hr")
+verbose = 0
+opts, args = getopt.getopt(sys.argv[1:], "c:hrv")
 for o,a in opts:
     if o == '-c':
         comment = a
     elif o == '-r':
         reply = 'n'
+    elif o == '-v':
+        verbose = 1
     else:
         print __doc__
         raise SystemExit
@@ -44,3 +48,5 @@ for email in args:
     for uid in cursor:
         cursor.execute(update, (today, reply, comment, uid[0]))
         conn.commit()
+        if verbose:
+            print email, uid[0]
index 217d552b32dfe37080070f0e905a1a320ecd3151..cea3dc72995484d19558dba727acde27a5d6d216 100755 (executable)
@@ -1,10 +1,16 @@
 #! /usr/bin/env python
-"""Arguments is a list of SQL paterns (will get wrapped in wildcards, %),
-display uid email and name
+"""finduser [flags] pattern...
+
+Flags:
+    -1   Print just email
+
+Arguments is a list of SQL paterns (will get wrapped in wildcards, %),
+by default display full information as CSV.
 """
 
 import mysql.connector
 import datetime, os, re, subprocess, sys, string, random
+import getopt
 
 dbconfig = {
         'user': 'licensereader',
@@ -15,15 +21,27 @@ conn = mysql.connector.connect(**dbconfig)
 cursor = conn.cursor()
 raw = open("request-approval.txt").read()
 
+single = 0
+opts, args = getopt.getopt(sys.argv[1:], "1")
+for o,a in opts:
+    if o == '-1':
+        single = 1
+    else:
+        print __doc__
+        raise SystemExit
+
 # Get dict of matching users
-for email in sys.argv[1:]:
+for email in args:
     q = ('SELECT users.uid,email,reply,name,count(log.uid) FROM users'
             ' LEFT JOIN log ON log.uid = users.uid'
-            ' WHERE email like %s GROUP BY email' );
+            ' WHERE email like %s GROUP BY email' )
     pat = '%' + email + '%'
     cursor.execute(q, (pat,))
     for row in cursor:
         uid,email,reply,name,count = row
         if reply == None:
             reply = '-'
-        print '%d, %s, %s, %d, "%s"' % (uid, email, reply, count, name)
+        if single:
+            print email
+        else:
+            print '%d, %s, %s, %d, "%s"' % (uid, email, reply, count, name)