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",
31 "additionalProperties": False,
35 "patternProperties": {
36 "^.*$": {"$ref": "#/definitions/features"},
41 "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])
63 def filelist_from_git_ls():
65 git_ls = 'git ls-files :(top)*/FEATURE.yaml'
66 rv = run(git_ls.split(), stdout=PIPE, stderr=PIPE)
67 if rv.returncode != 0:
68 sys.exit(rv.returncode)
70 for l in rv.stdout.decode('ascii').split('\n'):
76 def output_features(indent, fl):
79 for k, v in f.items():
80 print('{}- {}'.format(' ' * indent, k))
81 output_features(indent + 2, v)
83 print('{}- {}'.format(' ' * indent, f))
86 def output_markdown(features):
87 for k, v in features.items():
88 print('# {}'.format(v['name']))
89 print('Maintainer: {} '.format(v['maintainer']))
90 print('State: {}\n'.format(v['state']))
91 print('{}\n'.format(v['description']))
92 output_features(0, v['features'])
95 output_features(0, v['missing'])
100 parser = argparse.ArgumentParser(description='VPP Feature List.')
101 parser.add_argument('--validate', dest='validate', action='store_true',
102 help='validate the FEATURE.yaml file')
103 parser.add_argument('--git-status', dest='git_status', action='store_true',
104 help='Get filelist from git status')
105 parser.add_argument('--all', dest='all', action='store_true',
106 help='Validate all files in repository')
107 parser.add_argument('--markdown', dest='markdown', action='store_true',
108 help='Output feature table in markdown')
109 parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
111 args = parser.parse_args()
116 filelist = filelist_from_git_status()
118 filelist = filelist_from_git_ls()
120 filelist = args.infile
122 for featurefile in filelist:
123 featurefile = featurefile.rstrip()
125 # Load configuration file
126 with open(featurefile) as f:
127 cfg = yaml.load(f, Loader=yaml.SafeLoader)
128 validate(instance=cfg, schema=schema)
129 features[featurefile] = cfg
132 output_markdown(features)
135 if __name__ == '__main__':