GBP: Endpoints with VLAN tags and birdges that don't learn
[vpp.git] / doxygen / siphon-generate
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 # Looks for preprocessor macros with struct initializers and siphons them
17 # off into another file for later parsing; ostensibly to generate
18 # documentation from struct initializer data.
19
20 import os, sys, argparse, logging
21 import siphon
22
23 DEFAULT_LOGFILE = None
24 DEFAULT_LOGLEVEL = "info"
25 DEFAULT_OUTPUT = "build-root/docs/siphons"
26 DEFAULT_PREFIX = os.getcwd()
27
28 ap = argparse.ArgumentParser()
29 ap.add_argument("--log-file", default=DEFAULT_LOGFILE,
30         help="Log file [%s]" % DEFAULT_LOGFILE)
31 ap.add_argument("--log-level", default=DEFAULT_LOGLEVEL,
32         choices=["debug", "info", "warning", "error", "critical"],
33         help="Logging level [%s]" % DEFAULT_LOGLEVEL)
34
35 ap.add_argument("--output", '-o', metavar="directory", default=DEFAULT_OUTPUT,
36         help="Output directory for .siphon files [%s]" % DEFAULT_OUTPUT)
37 ap.add_argument("--input-prefix", metavar="path", default=DEFAULT_PREFIX,
38         help="Prefix to strip from input pathnames [%s]" % DEFAULT_PREFIX)
39 ap.add_argument("input", nargs='+', metavar="input_file",
40         help="Input C source files")
41 args = ap.parse_args()
42
43 logging.basicConfig(filename=args.log_file,
44         level=getattr(logging, args.log_level.upper(), None))
45 log = logging.getLogger("siphon_generate")
46
47
48 generate = siphon.generate.Generate(output_directory=args.output,
49     input_prefix=args.input_prefix)
50
51 # Pre-process file names in case they indicate a file with
52 # a list of files
53 files = []
54 for filename in args.input:
55     if filename.startswith('@'):
56         with open(filename[1:], 'r') as fp:
57             lines = fp.readlines()
58             for line in lines:
59                 file = line.strip()
60                 if file not in files:
61                     files.append(file)
62             lines = None
63     else:
64         if filename not in files:
65             files.append(filename)
66
67 # Iterate all the input files we've been given
68 for filename in files:
69     generate.parse(filename)
70
71 # Write the extracted data
72 generate.deliver()
73
74 # All done