aboutsummaryrefslogtreecommitdiff
path: root/client.py
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2014-12-28 00:33:01 +0800
committerDeterminant <ted.sybil@gmail.com>2014-12-28 00:33:01 +0800
commitdbfcc4082aa20ec7b3661a2dbd9716e91a4a34cc (patch)
treeb5a01b33d19ba3c90343ad101320f9ad328d2e11 /client.py
parente2ffca3d814f18b24497a7ed7b30d7c921e6f3c3 (diff)
...
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()