Check chairs are in the 'correct' format as part of pep8

This add a simple tool to verify that the 'chair' in every yaml file
matches the canonical format.

Change-Id: I88b566cb23a5f350b603a1bb16415d335bbbbaed
This commit is contained in:
Tony Breeds 2016-07-26 13:16:39 -05:00
parent ffd4fe4d44
commit e751e92a6d
2 changed files with 67 additions and 0 deletions

66
tools/check_chair.py Normal file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function
import argparse
import re
from yaml2ical import meeting
BOOL_STR = {True: 'OK', False: 'Needs Fixing'}
def check_chair(chair):
if re.search(r',', chair):
chairs = chair.split(',')
else:
chairs = [chair]
all_good = True
msg = ''
for chair in chairs:
chair = chair.rstrip().lstrip()
ok = bool(re.match(r'^[\w .-]+\([\w\d_-]+\)$', chair))
all_good &= ok
msg += "\t%s: %s\n" % (chair, BOOL_STR[ok])
return (all_good, msg)
def main():
# build option parser:
description = """
A tool that checks a meeting chair matches the canonical format.
"""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=description)
parser.add_argument("-y", "--yamldir",
dest="yaml_dir",
required=True,
help="directory containing YAML to process")
args = parser.parse_args()
meetings = meeting.load_meetings(args.yaml_dir)
for m in meetings:
ok, msg = check_chair(m.chair)
if not ok:
print(m.filefrom)
print(msg.rstrip())
if __name__ == '__main__':
main()

View File

@ -29,6 +29,7 @@ commands =
whitelist_externals = bash
commands =
bash test_tools/flake8wrap.sh {posargs}
python tools/check_chair.py -y {toxinidir}
[flake8]
ignore =