-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanity-check.py
45 lines (37 loc) · 1.5 KB
/
sanity-check.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
#!/usr/bin/python
import os
import sys
LICENSE_DELIMIT = "///////////////////////////////////////////////////////////////////////////////L"
LICENSE = """// The MIT License (MIT)
// Copyright (c) 2021 [untitled os] Team
// See LICENSE.txt and CREDITS.txt for details"""
problems = {}
# validate license headers
for root, dirs, files in os.walk("kernel"):
for file in files:
if file.endswith(".rs"):
text = ""
with open(os.path.join(root, file), "rt") as f:
text = f.read()
if not text.startswith("{}\n{}\n{}".format(LICENSE_DELIMIT, LICENSE, LICENSE_DELIMIT)):
pathkey = os.path.join(root, file).replace("\\", "/")
# try auto update
split = text.split(LICENSE_DELIMIT)
if len(split) == 3:
with open(os.path.join(root, file), "wt") as f:
f.write("{}\n{}\n{}{}".format(LICENSE_DELIMIT, LICENSE, LICENSE_DELIMIT, split[2]))
print("Updated license header in {}".format(pathkey))
else:
if pathkey not in problems:
problems[pathkey] = []
problems[pathkey].append("Needs license header fixed")
if len(problems) == 0:
print("No issues found.")
sys.exit(0)
print("Issues:")
longestName = 0
for k in problems:
longestName = max(longestName, len(k))
for k, v in problems.items():
for p in v:
print("{} | {}".format(k.ljust(longestName), p))