From 85f2964c6cce04b2b982bbe23adcc304f63be37e Mon Sep 17 00:00:00 2001 From: Terrtia Date: Mon, 17 Jun 2019 14:44:04 +0200 Subject: [PATCH] chg: [d4-analyzer-stdout] catch FileNotFoundError + only append one file + helper: fix required arguments --- server/analyzer/analyzer-d4-stdout/d4-stdout.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/server/analyzer/analyzer-d4-stdout/d4-stdout.py b/server/analyzer/analyzer-d4-stdout/d4-stdout.py index 695eb27..a761637 100755 --- a/server/analyzer/analyzer-d4-stdout/d4-stdout.py +++ b/server/analyzer/analyzer-d4-stdout/d4-stdout.py @@ -13,10 +13,10 @@ import logging.handlers if __name__ == "__main__": parser = argparse.ArgumentParser(description='Export d4 data to stdout') - parser.add_argument('-f', '--files', help='read data from files. trth', action="store_true") + parser.add_argument('-t', '--type', help='d4 type' , type=int, dest='type', required=True) + parser.add_argument('-u', '--uuid', help='queue uuid' , type=str, dest='uuid', required=True) + parser.add_argument('-f', '--files', help='read data from files. Append file to stdin', action="store_true") parser.add_argument('-n', '--newline', help='add new lines', action="store_true") - parser.add_argument('-t', '--type', help='d4 type' , type=int, dest='type') - parser.add_argument('-u', '--uuid', help='queue uuid' , type=str, dest='uuid') parser.add_argument('-i', '--ip',help='redis host' , type=str, default='127.0.0.1', dest='host_redis') parser.add_argument('-p', '--port',help='redis port' , type=int, default=6380, dest='port_redis') args = parser.parse_args() @@ -66,8 +66,14 @@ if __name__ == "__main__": time.sleep(1) continue if read_files: - with open(d4_data, 'rb') as f: - sys.stdout.buffer.write(f.read()) + try: + with open(d4_data, 'rb') as f: + sys.stdout.buffer.write(f.read()) + sys.exit(0) + except FileNotFoundError: + ## TODO: write logs file + continue + else: if newLines: sys.stdout.buffer.write(d4_data + b'\n')