improved warnings; check cli argument count
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Sun, 27 Jul 2014 06:17:24 +0000 (02:17 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 17:46:48 +0000 (12:46 -0500)
warnings now include the program name and print to stderr.

there must be no arguments aside from the program name.

edward-bot

index aec4b6cb2ed11d78b95683f1f48d87196aad5ec4..39d7f8f4396418e9f8feceaffe279772eb2e5465 100755 (executable)
@@ -37,8 +37,9 @@ import time
 
 def main ():
 
-    txt = sys.stdin.read()
+    handle_args()
 
+    txt = sys.stdin.read()
     msg = email.parser.Parser().parsestr(txt)
 
     print("From: " + msg['From'])
@@ -80,8 +81,8 @@ def msg_walk (msg):
         if conttype == "application/pgp-encrypted":
             if descript == 'PGP/MIME version identification':
                 if payload.strip() != "Version: 1":
-                    print("*** Warning... unknown pgp/mime version: " \
-                            + payload.strip())
+                    print(progname + ": Warning: unknown " + descript + ": " \
+                            + payload.strip(), file=sys.stderr)
             continue
 
         elif (filename == "encrypted.asc") or (conttype == "pgp/mime"):
@@ -196,5 +197,17 @@ def decrypt_block (block):
     return (plain, sigs)
 
 
+def handle_args ():
+    if __name__ == "__main__":
+
+        global progname
+        progname = sys.argv[0]
+
+        if len(sys.argv) > 1:
+            print(progname + ": error, this program doesn't " \
+                    "need any arguments.", file=sys.stderr)
+            exit(1)
+
+
 main()