forked from danmar/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastyle_client.py
More file actions
49 lines (42 loc) · 1.21 KB
/
astyle_client.py
File metadata and controls
49 lines (42 loc) · 1.21 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
44
45
46
47
48
import os
import socket
import sys
import time
def receive_data(conn):
data = ''
for t in range(1000):
d = conn.recv(8196)
if d:
data += d
if data.endswith('\nDONE'):
return data[:-5]
time.sleep(0.01)
return ''
def astyle(server_address, code):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(server_address)
sock.sendall(code + '\nDONE')
return receive_data(sock)
except socket.error as err:
print('Network error: ' + str(err))
sock.close()
return None
if __name__ == "__main__":
server_address = ('cppcheck.osuosl.org', 18000)
for filename in sorted(sys.argv[1:]):
if not (filename.endswith('.cpp') or filename.endswith('.h')):
continue
f = open(filename, 'rt')
code = f.read()
f.close()
formatted_code = astyle(server_address, code)
if formatted_code is None:
break
if code != formatted_code:
print('Changed: ' + filename)
f = open(filename, 'wt')
f.write(formatted_code)
f.close()
else:
print('Unchanged: ' + filename)