forked from standardebooks/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint
executable file
·81 lines (61 loc) · 2.07 KB
/
lint
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
import argparse
import os
import se
from termcolor import colored
from se.se_epub import SeEpub
def main():
parser = argparse.ArgumentParser(description="Check for various Standard Ebooks style errors.")
parser.add_argument("-v", "--verbose", action="store_true", help="increase output verbosity")
parser.add_argument("-p", "--plain", action="store_true", help="print plain output")
parser.add_argument("directories", metavar="DIRECTORY", nargs="+", help="a Standard Ebooks source directory")
args = parser.parse_args()
first_output = True
for directory in args.directories:
try:
se_epub = SeEpub(directory, os.path.dirname(os.path.realpath(__file__)))
except Exception as ex:
se.print_error(ex)
exit(1)
messages = se_epub.lint()
table_data = []
# Print a separator newline if more than one table is printed
if not first_output and (args.verbose or messages):
print("")
elif first_output:
first_output = False
# Print the table header
if args.verbose or (messages and len(args.directories) > 1):
if args.plain:
print(se_epub.directory)
else:
print(colored(se_epub.directory, "white", attrs=["reverse"]))
# Print the table
if messages:
if args.plain:
for message in messages:
if message.is_submessage:
print("\t" + message.text)
else:
label = "Manual Review:"
if message.message_type == se.MESSAGE_TYPE_ERROR:
label = "Error:"
print(label, message.filename, message.text)
else:
for message in messages:
if message.is_submessage:
table_data.append([" ", "→", "{}".format(message.text)])
else:
alert = colored("Manual Review", "yellow")
if message.message_type == se.MESSAGE_TYPE_ERROR:
alert = colored("Error", "red")
table_data.append([alert, message.filename, message.text])
se.print_table(table_data, 2)
if args.verbose and not messages:
if args.plain:
print("OK")
else:
table_data.append([colored("OK", "green", attrs=["reverse"])])
se.print_table(table_data)
if __name__ == "__main__":
main()