-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsocket_client.py
More file actions
executable file
·41 lines (31 loc) · 1.19 KB
/
socket_client.py
File metadata and controls
executable file
·41 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import argparse
import socket
import sys
SOCKET_FILENAME = './glados_sock'
def main():
parser = argparse.ArgumentParser(description='Send data to GLaDOS')
parser.add_argument('--plugin', dest='plugin_name',
help='Plugin to send the data to', required=True)
parser.add_argument('--data', dest='data',
help='Data to send to the plugin. '
'If not provided will accept from stdin.')
parser.add_argument('--no-data', dest='no_data', action='store_true',
help='Send no data to the plugin (overrides --data).')
args = parser.parse_args()
if args.no_data:
message_data = ''
elif args.data:
message_data = args.data
else:
message_data = ""
for line in sys.stdin:
message_data += line
message_contents = '{}:{}{}'.format(len(args.plugin_name),
args.plugin_name, message_data)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(SOCKET_FILENAME)
sock.sendall(message_contents.encode('utf8'))
sock.close()
if __name__ == '__main__':
main()