diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..d0ddf15 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# check basic sanity +./tools/rstcheck.py -d specs diff --git a/tools/rstcheck.py b/tools/rstcheck.py new file mode 100755 index 0000000..8a02cbe --- /dev/null +++ b/tools/rstcheck.py @@ -0,0 +1,68 @@ +#!/usr/bin/python + +# Copyright 2014 Samsung Electronics +# All Rights Reserved. +# +# 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. + +import argparse +import fileinput +import os +import re +import sys + +ERRORS = 0 + +def error(msg): + global ERRORS + ERRORS += 1 + print(msg) + +def get_options(): + parser = argparse.ArgumentParser( + description='RST sanity checker') + parser.add_argument('-d', '--dir', help="Specifications Directory", + default="specs") + return parser.parse_args() + +def find_rst_files(dirname): + files = [] + for root, dirnames, filenames in os.walk(dirname): + for f in filenames: + if f != ".keep": + files.append("%s/%s" % (root, f)) + return files + +def ensure_files_end_in_rst(files): + for fname in files: + if not re.search("\.rst$", fname): + error("E001: Filename %s does not end in .rst" % fname) + +def ensure_lt80(files): + for fname in files: + for line in fileinput.input(fname): + if len(line) > 80: + error("E002: File %s exceeds 80 columns" % fname) + +def main(): + opts = get_options() + files = find_rst_files(opts.dir) + ensure_files_end_in_rst(files) + ensure_lt80(files) + if ERRORS > 0: + return 1 + return 0 + + +if __name__ == "__main__": + sys.exit(main())