-
Notifications
You must be signed in to change notification settings - Fork 0
/
quality.py
executable file
·61 lines (52 loc) · 1.7 KB
/
quality.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
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.dirname(MODULE_DIR))
# import linuxpreinstall.logging2 as logging
# from linuxpreinstall.logging2 import getLogger
from linuxpreinstall import (
echo0,
)
FLAG_NAME = "api.rc"
REPO_DIR = os.path.realpath(".")
FLAG_PATH = os.path.join(REPO_DIR, FLAG_NAME)
issuesByType = {}
if not os.path.isfile(FLAG_NAME):
# Can't just use sys.path.insert, since rc needs to be found by scripts
echo0("You must run {} from the linux-preinstall directory."
" {} is not here.".format(sys.argv[0], FLAG_NAME))
sys.exit(1)
def check_sh_quality(path):
executable = os.access(path, os.X_OK)
issues = issuesByType.get("sh")
if issues is None:
issuesByType["sh"] = []
issues = issuesByType["sh"]
if not executable:
msg = "{}: not marked executable".format(path)
issues.append(msg)
def check_parent(parent):
for sub in os.listdir(parent):
subPath = os.path.join(parent, sub)
if os.path.isdir(subPath):
check_parent(subPath)
continue
if sub.endswith(".sh"):
check_sh_quality(subPath)
check_parent(REPO_DIR)
issueCount = 0
for key,issues in issuesByType.items():
echo0("#{} files:".format(key))
for issue in issues:
echo0(issue)
issueCount += 1
if len(issuesByType.keys()) > 0:
echo0(
"There were {} issue(s) in {} files"
" (Checking any other file types"
" in this directory tree is not implemented)."
.format(issueCount, issuesByType.keys()))
else:
echo0("No files matching the types were found.")