7 from pprint import pprint
9 from jsonschema import validate, exceptions
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": {"$ref": "#/definitions/maintainers"},
21 "state": {"type": "string",
22 "enum": ["production", "experimental", "development"]},
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,
36 "items": {"type": "string"},
43 "patternProperties": {
44 "^.*$": {"$ref": "#/definitions/features"},
49 "items": {"anyOf": [{"$ref": "#/definitions/featureobject"},
58 def filelist_from_git_status():
60 git_status = 'git status --porcelain */FEATURE.yaml'
61 rv = run(git_status.split(), stdout=PIPE, stderr=PIPE)
62 if rv.returncode != 0:
63 sys.exit(rv.returncode)
65 for l in rv.stdout.decode('ascii').split('\n'):
67 filelist.append(l.split()[1])
71 def filelist_from_git_ls():
73 git_ls = 'git ls-files :(top)*/FEATURE.yaml'
74 rv = run(git_ls.split(), stdout=PIPE, stderr=PIPE)
75 if rv.returncode != 0:
76 sys.exit(rv.returncode)
78 for l in rv.stdout.decode('ascii').split('\n'):
84 def output_features(indent, fl):
87 for k, v in f.items():
88 print('{}- {}'.format(' ' * indent, k))
89 output_features(indent + 2, v)
91 print('{}- {}'.format(' ' * indent, f))
94 def output_markdown(features):
95 for k, v in features.items():
96 print('# {}'.format(v['name']))
97 if type(v['maintainer']) is list:
98 print('Maintainers: ' +
99 ', '.join('{}'.format(m) for m in
100 v['maintainer']) + ' ')
102 print('Maintainer: {} '.format(v['maintainer']))
103 print('State: {} \n'.format(v['state']))
104 print('{}\n'.format(v['description']))
105 output_features(0, v['features'])
107 print('\n## Missing')
108 output_features(0, v['missing'])
113 parser = argparse.ArgumentParser(description='VPP Feature List.')
114 parser.add_argument('--validate', dest='validate', action='store_true',
115 help='validate the FEATURE.yaml file')
116 parser.add_argument('--git-status', dest='git_status', action='store_true',
117 help='Get filelist from git status')
118 parser.add_argument('--all', dest='all', action='store_true',
119 help='Validate all files in repository')
120 parser.add_argument('--markdown', dest='markdown', action='store_true',
121 help='Output feature table in markdown')
122 parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
124 args = parser.parse_args()
129 filelist = filelist_from_git_status()
131 filelist = filelist_from_git_ls()
133 filelist = args.infile
135 for featurefile in filelist:
136 featurefile = featurefile.rstrip()
138 # Load configuration file
139 with open(featurefile) as f:
140 cfg = yaml.load(f, Loader=yaml.SafeLoader)
142 validate(instance=cfg, schema=schema)
143 except exceptions.ValidationError:
144 print('File does not validate: {}'.format(featurefile),
147 features[featurefile] = cfg
150 output_markdown(features)
153 if __name__ == '__main__':