docs: better docs, mv doxygen to sphinx
[vpp.git] / docs / _scripts / siphon-process
1 #!/usr/bin/env python3
2 # Copyright (c) 2016 Comcast Cable Communications Management, LLC.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Filter for .siphon files that are generated by other filters.
17 # The idea is to siphon off certain initializers so that we can better
18 # auto-document the contents of that initializer.
19
20 import argparse
21 import logging
22 import os
23 import sys
24
25 import siphon
26
27 DEFAULT_LOGFILE = None
28 DEFAULT_LOGLEVEL = "info"
29 DEFAULT_SIPHON = "clicmd"
30 DEFAULT_FORMAT = "markdown"
31 DEFAULT_OUTPUT = None
32 DEFAULT_TEMPLATES = os.path.dirname(__file__) + "/siphon_templates"
33 DEFAULT_OUTPUT_DIR = os.path.dirname(__file__) + "/siphon_docs"
34 DEFAULT_REPO_LINK = "https://github.com/FDio/vpp/blob/master/"
35
36 ap = argparse.ArgumentParser()
37 ap.add_argument("--log-file", default=DEFAULT_LOGFILE,
38                 help="Log file [%s]" % DEFAULT_LOGFILE)
39 ap.add_argument("--log-level", default=DEFAULT_LOGLEVEL,
40                 choices=["debug", "info", "warning", "error", "critical"],
41                 help="Logging level [%s]" % DEFAULT_LOGLEVEL)
42
43 ap.add_argument("--type", '-t', metavar="siphon_type", default=DEFAULT_SIPHON,
44                 choices=siphon.process.siphons.keys(),
45                 help="Siphon type to process [%s]" % DEFAULT_SIPHON)
46 ap.add_argument("--format", '-f', default=DEFAULT_FORMAT,
47                 choices=siphon.process.formats.keys(),
48                 help="Output format to generate [%s]" % DEFAULT_FORMAT)
49 ap.add_argument("--output", '-o', metavar="file", default=DEFAULT_OUTPUT,
50                 help="Output file (uses stdout if not defined) [%s]" %
51                      DEFAULT_OUTPUT)
52 ap.add_argument("--templates", metavar="directory", default=DEFAULT_TEMPLATES,
53                 help="Path to render templates directory [%s]" %
54                      DEFAULT_TEMPLATES)
55 ap.add_argument("--outdir", metavar="directory", default=DEFAULT_OUTPUT_DIR,
56                 help="Path to output rendered parts [%s]" %
57                      DEFAULT_OUTPUT_DIR)
58 ap.add_argument("--repolink", metavar="repolink", default=DEFAULT_REPO_LINK,
59                 help="Link to public repository [%s]" %
60                      DEFAULT_REPO_LINK)
61 ap.add_argument("input", nargs='+', metavar="input_file",
62                 help="Input .siphon files")
63 args = ap.parse_args()
64
65 logging.basicConfig(filename=args.log_file,
66                     level=getattr(logging, args.log_level.upper(), None))
67 log = logging.getLogger("siphon_process")
68
69 # Determine where to send the generated output
70 if args.output is None:
71     out = sys.stdout
72 else:
73     out = open(args.output, "w+")
74
75 # Get our processor
76 klass = siphon.process.siphons[args.type]
77 processor = klass(
78     template_directory=args.templates,
79     format=args.format,
80     outdir=args.outdir,
81     repository_link=args.repolink
82 )
83
84 # Load the input files
85 processor.load_json(args.input)
86
87 # Process the data
88 processor.process(out=out)
89
90 # All done