forked from standardebooks/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint
executable file
·61 lines (44 loc) · 1.58 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
#!/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("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):
print(colored(se_epub.directory, "white", attrs=["reverse"]))
#Print the table
if messages:
for message in messages:
if message.is_submessage:
table_data.append([" ", "→", "{}".format(message.text)])
else:
alert = colored("Warning", "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:
table_data.append([colored("OK", "green", attrs=["reverse"])])
se.print_table(table_data)
if __name__ == "__main__":
main()