-
Notifications
You must be signed in to change notification settings - Fork 20
/
whitespace.py
51 lines (38 loc) · 1.34 KB
/
whitespace.py
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
49
50
51
import sys
import re
import os
import subprocess
def extension(file):
return file.split(".")[-1]
def process_file(fullname):
content = ""
with open(fullname, "r") as f:
content = f.read()
new_content = ""
for line in content.replace("\n\r", "\n").replace("\r\n", "\n").split("\n"):
new_line = ""
for c in line:
if c != '\t':
new_line += c
continue
tab_len = 4 - (len(new_line) % 4)
for i in range(0, tab_len):
new_line += " "
new_content += new_line + "\n"
new_content = new_content.strip() + "\n\n"
if new_content != content:
with open(fullname, "w") as f:
f.write(new_content)
def process_files(folders):
for proj in folders:
for root, dirs, files in os.walk(proj):
for file in files:
if extension(file) not in {"h", "cpp", "inl", "glsl", "frag", "vert", "geom", "comp"}:
continue
fullname = root + "/" + file
print("Starting", file)
process_file(fullname)
print(file, "Done")
print()
projects = {"y", "yave", "editor", "shaders"}
process_files(projects)