7 from pprint import pprint
9 from jsonschema import validate
11 from subprocess import run, PIPE
13 # VPP feature JSON schema
15 "$schema": "http://json-schema.org/schema#",
18 "name": {"type": "string"},
19 "description": { "type": "string" },
20 "maintainer": { "type": "string" },
21 "state": {"type": "string",
22 "enum": ["production", "experimental"]},
23 "features": { "$ref": "#/definitions/features" },
24 "missing": { "$ref": "#/definitions/features" },
25 "properties": { "type": "array",
26 "items": { "type": "string",
27 "enum": ["API", "CLI", "STATS", "MULTITHREAD"] },
30 "additionalProperties": False,
34 "patternProperties": {
35 "^.*$": { "$ref": "#/definitions/features" },
40 "items": {"anyOf": [{ "$ref": "#/definitions/featureobject" },
50 def filelist_from_git_status():
52 git_status = 'git status --porcelain */FEATURE.yaml'
53 rv = run(git_status.split(), stdout=PIPE, stderr=PIPE)
54 if rv.returncode != 0:
55 sys.exit(rv.returncode)
57 for l in rv.stdout.decode('ascii').split('\n'):
59 filelist.append(l.split()[1])
62 def filelist_from_git_ls():
64 git_ls = 'git ls-files :(top)*/FEATURE.yaml'
65 rv = run(git_ls.split(), stdout=PIPE, stderr=PIPE)
66 if rv.returncode != 0:
67 sys.exit(rv.returncode)
69 for l in rv.stdout.decode('ascii').split('\n'):
74 def output_features(indent, fl):
78 print('{}- {}'.format(' ' * indent, k))
79 output_features(indent + 2, v)
81 print('{}- {}'.format(' ' * indent, f))
83 def output_markdown(features):
84 for k,v in features.items():
85 print('# {}'.format(v['name']))
86 print('Maintainer: {} '.format(v['maintainer']))
87 print('State: {}\n'.format(v['state']))
88 print('{}\n'.format(v['description']))
89 output_features(0, v['features'])
92 output_features(0, v['missing'])
96 parser = argparse.ArgumentParser(description='VPP Feature List.')
97 parser.add_argument('--validate', dest='validate', action='store_true',
98 help='validate the FEATURE.yaml file')
99 parser.add_argument('--git-status', dest='git_status', action='store_true',
100 help='Get filelist from git status')
101 parser.add_argument('--all', dest='all', action='store_true',
102 help='Validate all files in repository')
103 parser.add_argument('--markdown', dest='markdown', action='store_true',
104 help='Output feature table in markdown')
105 parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
107 args = parser.parse_args()
112 filelist = filelist_from_git_status()
114 filelist = filelist_from_git_ls()
116 filelist = args.infile
118 for featurefile in filelist:
119 featurefile = featurefile.rstrip()
121 # Load configuration file
122 with open(featurefile) as f:
124 validate(instance=cfg, schema=schema)
125 features[featurefile] = cfg
128 output_markdown(features)
130 if __name__ == '__main__':