-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdoc_validate.py
100 lines (67 loc) · 2.07 KB
/
doc_validate.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
"""
.. module:: validate_document.py
:license: GPL/CeCIL
:platform: Unix, Windows
:synopsis: Validates a document held upon local file system.
.. moduleauthor:: Mark Conway-Greenslade <momipsl@ipsl.jussieu.fr>
"""
import datetime
from tornado.options import define, options
import pyesdoc
# Define command line options.
define("file", help="Path to file to be validated.")
define("outfile", help="Path to validation report output file.", default=None)
# Report banner.
_BANNER = "--------------------------------------\n"
def _emit(stream, report):
"""Emits report to an I/O stream.
"""
def _write_header():
"""Writes report header.
"""
stream(_BANNER)
stream("ES-DOC Documentation Validation Report\n")
stream(_BANNER)
stream("Generated @ {0}\n".format(datetime.datetime.now()))
stream("Target = {0}\n".format(options.file))
stream(_BANNER)
def _write_body():
"""Writes report body.
"""
stream("------ VALIDATION REPORT BEGINS ------\n")
stream("\n")
for err in report:
stream(str(err) + "\n")
stream("\n")
stream("\n------ VALIDATION REPORT ENDS --------")
_write_header()
_write_body()
def _emit_to_stdout(report):
"""Emits report to stdout.
"""
_emit(pyesdoc.log_warning, report)
def _emit_to_file_system(report):
"""Emits report to file system.
"""
with open(options.outfile, 'w') as ofile:
_emit(ofile.write, report)
pyesdoc.log("Validation report written to ---> {0}.".format(options.outfile))
def _main():
"""Main entry point.
"""
# Open document & validate.
doc = pyesdoc.read(options.file)
report = pyesdoc.validate(doc)
# Inform user of validation result.
if report:
if options.outfile:
_emit_to_file_system(report)
else:
_emit_to_stdout(report)
else:
pyesdoc.log("Documemt is valid.")
# Entry point.
if __name__ == '__main__':
options.parse_command_line()
_main()