From 20f6e7c5d74891965e374b066af45f1a47d4b3b2 Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Sun, 27 Jul 2014 02:17:24 -0400 Subject: [PATCH] improved warnings; check cli argument count warnings now include the program name and print to stderr. there must be no arguments aside from the program name. --- edward-bot | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/edward-bot b/edward-bot index aec4b6c..39d7f8f 100755 --- a/edward-bot +++ b/edward-bot @@ -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() -- 2.25.1