aboutsummaryrefslogtreecommitdiff
path: root/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'client.py')
-rw-r--r--client.py53
1 files changed, 27 insertions, 26 deletions
diff --git a/client.py b/client.py
index 6af884c..194b927 100644
--- a/client.py
+++ b/client.py
@@ -20,31 +20,32 @@ def check_id(val):
print('invalid mid value')
exit(1)
-if args.create:
- cmd = {'action': 'create'}
- if len(args.create) >= 1:
- cmd["name"] = args.create
- if args.type is None:
- print('please specify a type')
+if __name__ == '__main__':
+ if args.create:
+ cmd = {'action': 'create'}
+ if len(args.create) >= 1:
+ cmd["name"] = args.create
+ if args.type is None:
+ print('please specify a type')
+ exit(1)
+ cmd["metadata"] = {'type' : args.type}
+ elif args.add:
+ cmd = {'action': 'add', 'jid': check_id(args.add), 'record' : args.col}
+ elif args.clear:
+ cmd = {'action': 'clear', 'jid': check_id(args.clear)}
+ elif args.drop:
+ cmd = {'action': 'drop', 'jid': check_id(args.drop)}
+ elif args.alter:
+ cmd = {'action': 'alter', 'jid': check_id(args.alter),
+ 'records' : [l[:-1].split() for l in stdin.readlines()]}
+ else:
+ print('please specify an action')
exit(1)
- cmd["metadata"] = {'type' : args.type}
-elif args.add:
- cmd = {'action': 'add', 'jid': check_id(args.add), 'record' : args.col}
-elif args.clear:
- cmd = {'action': 'clear', 'jid': check_id(args.clear)}
-elif args.drop:
- cmd = {'action': 'drop', 'jid': check_id(args.drop)}
-elif args.alter:
- cmd = {'action': 'alter', 'jid': check_id(args.alter),
- 'records' : [l[:-1].split() for l in stdin.readlines()]}
-else:
- print('please specify an action')
- exit(1)
-s = socket(AF_UNIX)
-s.connect("./lab_monitor.socket")
-mesg = json.dumps(cmd)
-mesg = pack("<i", len(mesg)) + mesg
-s.send(mesg)
-stdout.write(s.recv(1024))
-s.close()
+ s = socket(AF_UNIX)
+ s.connect("./lab_monitor.socket")
+ mesg = json.dumps(cmd)
+ mesg = pack("<i", len(mesg)) + mesg
+ s.send(mesg)
+ stdout.write(s.recv(1024))
+ s.close()