forked from danmar/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastyle_server.py
More file actions
44 lines (31 loc) · 1.06 KB
/
astyle_server.py
File metadata and controls
44 lines (31 loc) · 1.06 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
42
43
import logging
import socket
import subprocess
from astyle_client import receive_data
logger = logging.getLogger()
def server(port):
socket.setdefaulttimeout(30)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_address = ('', port)
sock.bind(server_address)
sock.listen(1)
while True:
# Wait for a connection
connection, client_address = sock.accept()
# Read data from client
try:
data = receive_data(connection)
except socket.error:
connection.close()
continue
# Format
process = subprocess.Popen(['astyle', '--options=.astylerc'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
comm = process.communicate(input=data)
connection.sendall(comm[0] + '\nDONE')
connection.close()
if __name__ == "__main__":
server(port=18000)