diff options
author | Linus Nordberg <linus@nordu.net> | 2017-02-16 08:13:59 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-02-16 08:13:59 +0100 |
commit | 320e7346ab80feb58a75703e2fa79fb31887394d (patch) | |
tree | b7173bb0ae1ad4f7ed4c8ad74e6770b84fa6b23c /tools/plopcontrol.py | |
parent | 2de232899d668a04084fb361f5956a7f0052ed58 (diff) |
Replace use of nc(1) in getconfig.sh with new plopcontrol.py.
Diffstat (limited to 'tools/plopcontrol.py')
-rwxr-xr-x | tools/plopcontrol.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/plopcontrol.py b/tools/plopcontrol.py new file mode 100755 index 0000000..295f311 --- /dev/null +++ b/tools/plopcontrol.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2017, NORDUnet A/S. +# See LICENSE for licensing information. + +import socket +import sys +import signal + +def send_message(plopcontrolfile, message): + plopcontrolport = int(open(plopcontrolfile).read()) + print >>sys.stderr, "plopcontrolport", plopcontrolport + s = socket.socket(socket.AF_INET) + print >>sys.stderr, "opened socket" + s.connect(("127.0.0.1", plopcontrolport)) + print >>sys.stderr, "connected, sending message", message + s.sendall(message + "\n") + print >>sys.stderr, "sent message" + data = "" + while "\n" not in data: + data = data + s.recv(1024) + print >>sys.stderr, "received data" + data = data.rstrip("\n") + print >>sys.stderr, "received all data" + s.close() + return data + +def main(): + signal.alarm(5) + reply = send_message(sys.argv[1], sys.argv[2]) + print reply + +if __name__ == '__main__': + main() |