blob: 698da8828e1d80508346155a0e7711ef58c5f51e [file] [log] [blame]
Chris Luke90f52bf2016-09-12 08:55:13 -04001#!/usr/bin/env python
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
20import os, sys, argparse, logging
21import siphon
22
23DEFAULT_LOGFILE = None
24DEFAULT_LOGLEVEL = "info"
25DEFAULT_SIPHON ="clicmd"
Chris Lukec3f92ad2016-10-05 15:45:19 -040026DEFAULT_FORMAT = "markdown"
Chris Luke90f52bf2016-09-12 08:55:13 -040027DEFAULT_OUTPUT = None
28DEFAULT_TEMPLATES = os.path.dirname(__file__) + "/siphon_templates"
29
30ap = argparse.ArgumentParser()
31ap.add_argument("--log-file", default=DEFAULT_LOGFILE,
32 help="Log file [%s]" % DEFAULT_LOGFILE)
33ap.add_argument("--log-level", default=DEFAULT_LOGLEVEL,
34 choices=["debug", "info", "warning", "error", "critical"],
35 help="Logging level [%s]" % DEFAULT_LOGLEVEL)
36
37ap.add_argument("--type", '-t', metavar="siphon_type", default=DEFAULT_SIPHON,
38 choices=siphon.process.siphons.keys(),
39 help="Siphon type to process [%s]" % DEFAULT_SIPHON)
Chris Lukec3f92ad2016-10-05 15:45:19 -040040ap.add_argument("--format", '-f', default=DEFAULT_FORMAT,
41 choices=siphon.process.formats.keys(),
42 help="Output format to generate [%s]" % DEFAULT_FORMAT)
Chris Luke90f52bf2016-09-12 08:55:13 -040043ap.add_argument("--output", '-o', metavar="file", default=DEFAULT_OUTPUT,
44 help="Output file (uses stdout if not defined) [%s]" % DEFAULT_OUTPUT)
45ap.add_argument("--templates", metavar="directory", default=DEFAULT_TEMPLATES,
46 help="Path to render templates directory [%s]" % DEFAULT_TEMPLATES)
47ap.add_argument("input", nargs='+', metavar="input_file",
48 help="Input .siphon files")
49args = ap.parse_args()
50
51logging.basicConfig(filename=args.log_file,
52 level=getattr(logging, args.log_level.upper(), None))
53log = logging.getLogger("siphon_process")
54
55# Determine where to send the generated output
56if args.output is None:
57 out = sys.stdout
58else:
59 out = open(args.output, "w+")
60
61# Get our processor
62klass = siphon.process.siphons[args.type]
Chris Lukec3f92ad2016-10-05 15:45:19 -040063processor = klass(template_directory=args.templates, format=args.format)
Chris Luke90f52bf2016-09-12 08:55:13 -040064
65# Load the input files
66processor.load_json(args.input)
67
68# Process the data
69processor.process(out=out)
70
71# All done