blob: ea9df96fe26e2e24b29510ccebedea2730ffae18 [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"
26DEFAULT_OUTPUT = None
27DEFAULT_TEMPLATES = os.path.dirname(__file__) + "/siphon_templates"
28
29ap = argparse.ArgumentParser()
30ap.add_argument("--log-file", default=DEFAULT_LOGFILE,
31 help="Log file [%s]" % DEFAULT_LOGFILE)
32ap.add_argument("--log-level", default=DEFAULT_LOGLEVEL,
33 choices=["debug", "info", "warning", "error", "critical"],
34 help="Logging level [%s]" % DEFAULT_LOGLEVEL)
35
36ap.add_argument("--type", '-t', metavar="siphon_type", default=DEFAULT_SIPHON,
37 choices=siphon.process.siphons.keys(),
38 help="Siphon type to process [%s]" % DEFAULT_SIPHON)
39ap.add_argument("--output", '-o', metavar="file", default=DEFAULT_OUTPUT,
40 help="Output file (uses stdout if not defined) [%s]" % DEFAULT_OUTPUT)
41ap.add_argument("--templates", metavar="directory", default=DEFAULT_TEMPLATES,
42 help="Path to render templates directory [%s]" % DEFAULT_TEMPLATES)
43ap.add_argument("input", nargs='+', metavar="input_file",
44 help="Input .siphon files")
45args = ap.parse_args()
46
47logging.basicConfig(filename=args.log_file,
48 level=getattr(logging, args.log_level.upper(), None))
49log = logging.getLogger("siphon_process")
50
51# Determine where to send the generated output
52if args.output is None:
53 out = sys.stdout
54else:
55 out = open(args.output, "w+")
56
57# Get our processor
58klass = siphon.process.siphons[args.type]
59processor = klass(template_directory=args.templates)
60
61# Load the input files
62processor.load_json(args.input)
63
64# Process the data
65processor.process(out=out)
66
67# All done