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