1
0
mirror of https://github.com/rtbrick/bngblaster.git synced 2024-05-06 15:54:57 +00:00

fix cli.py lint warning

This commit is contained in:
Christian Giese
2021-03-23 09:36:14 +01:00
parent 751707f0ae
commit 935df1eda2

21
cli.py
View File

@ -1,4 +1,14 @@
#!/usr/bin/env python3
"""
BNG Blaster Control Socket Client
Simple script to interact with the BNG Blaster
control socket JSON RPC API.
Christian Giese, January 2021
Copyright (C) 2020-2021, RtBrick, Inc.
"""
import sys
import socket
import os
@ -21,11 +31,13 @@ Examples:
sys.exit(1)
def error(*args, **kwargs):
"""print error and exit"""
print(*args, file=sys.stderr, **kwargs)
sys.exit(1)
def main():
"""main function"""
request = {}
if(len(sys.argv)) < 3:
usage()
@ -34,15 +46,18 @@ def main():
request["command"] = sys.argv[2]
if(len(sys.argv)) > 4:
request["arguments"] = {}
request["arguments"] = {}
for i in range(3, len(sys.argv), 2):
arg = sys.argv[i+1]
try:
try:
# integer arguments like "session-id 1"
request["arguments"][sys.argv[i]] = int(arg)
except:
try:
# list arguments like "sessions [1,2]""
request["arguments"][sys.argv[i]] = ast.literal_eval(arg)
except:
except:
# string arguments like "group 239.0.0.1"
request["arguments"][sys.argv[i]] = arg
#print(json.dumps(request).encode('utf-8'))
if os.path.exists(socket_path):