blob: cbee1e90786a724262253579d098fe7042a7dff1 [file] [log] [blame]
Paul Vinciguerra464e5e02019-11-01 15:07:32 -04001#!/usr/bin/env python3
Chris Luke90f52bf2016-09-12 08:55:13 -04002# 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
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040020import argparse
21import logging
22import os
23import sys
24
Chris Luke90f52bf2016-09-12 08:55:13 -040025import siphon
26
27DEFAULT_LOGFILE = None
28DEFAULT_LOGLEVEL = "info"
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040029DEFAULT_SIPHON = "clicmd"
Chris Lukec3f92ad2016-10-05 15:45:19 -040030DEFAULT_FORMAT = "markdown"
Chris Luke90f52bf2016-09-12 08:55:13 -040031DEFAULT_OUTPUT = None
32DEFAULT_TEMPLATES = os.path.dirname(__file__) + "/siphon_templates"
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020033DEFAULT_OUTPUT_DIR = os.path.dirname(__file__) + "/siphon_docs"
34DEFAULT_REPO_LINK = "https://github.com/FDio/vpp/blob/master/"
Chris Luke90f52bf2016-09-12 08:55:13 -040035
36ap = argparse.ArgumentParser()
37ap.add_argument("--log-file", default=DEFAULT_LOGFILE,
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040038 help="Log file [%s]" % DEFAULT_LOGFILE)
Chris Luke90f52bf2016-09-12 08:55:13 -040039ap.add_argument("--log-level", default=DEFAULT_LOGLEVEL,
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040040 choices=["debug", "info", "warning", "error", "critical"],
41 help="Logging level [%s]" % DEFAULT_LOGLEVEL)
Chris Luke90f52bf2016-09-12 08:55:13 -040042
43ap.add_argument("--type", '-t', metavar="siphon_type", default=DEFAULT_SIPHON,
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040044 choices=siphon.process.siphons.keys(),
45 help="Siphon type to process [%s]" % DEFAULT_SIPHON)
Chris Lukec3f92ad2016-10-05 15:45:19 -040046ap.add_argument("--format", '-f', default=DEFAULT_FORMAT,
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040047 choices=siphon.process.formats.keys(),
48 help="Output format to generate [%s]" % DEFAULT_FORMAT)
Chris Luke90f52bf2016-09-12 08:55:13 -040049ap.add_argument("--output", '-o', metavar="file", default=DEFAULT_OUTPUT,
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040050 help="Output file (uses stdout if not defined) [%s]" %
51 DEFAULT_OUTPUT)
Chris Luke90f52bf2016-09-12 08:55:13 -040052ap.add_argument("--templates", metavar="directory", default=DEFAULT_TEMPLATES,
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040053 help="Path to render templates directory [%s]" %
54 DEFAULT_TEMPLATES)
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020055ap.add_argument("--outdir", metavar="directory", default=DEFAULT_OUTPUT_DIR,
56 help="Path to output rendered parts [%s]" %
57 DEFAULT_OUTPUT_DIR)
58ap.add_argument("--repolink", metavar="repolink", default=DEFAULT_REPO_LINK,
59 help="Link to public repository [%s]" %
60 DEFAULT_REPO_LINK)
Chris Luke90f52bf2016-09-12 08:55:13 -040061ap.add_argument("input", nargs='+', metavar="input_file",
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040062 help="Input .siphon files")
Chris Luke90f52bf2016-09-12 08:55:13 -040063args = ap.parse_args()
64
65logging.basicConfig(filename=args.log_file,
Paul Vinciguerra464e5e02019-11-01 15:07:32 -040066 level=getattr(logging, args.log_level.upper(), None))
Chris Luke90f52bf2016-09-12 08:55:13 -040067log = logging.getLogger("siphon_process")
68
69# Determine where to send the generated output
70if args.output is None:
71 out = sys.stdout
72else:
73 out = open(args.output, "w+")
74
75# Get our processor
76klass = siphon.process.siphons[args.type]
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020077processor = klass(
78 template_directory=args.templates,
79 format=args.format,
80 outdir=args.outdir,
81 repository_link=args.repolink
82)
Chris Luke90f52bf2016-09-12 08:55:13 -040083
84# Load the input files
85processor.load_json(args.input)
86
87# Process the data
88processor.process(out=out)
89
90# All done