#!/usr/bin/env python3 # vim: sw=4 ts=4 et si: import sys from optparse import OptionParser from suse_git import header if __name__ == "__main__": parser = OptionParser(usage="%prog [options] [files] -- check patch header correctness") parser.add_option('', '--stdin', action="store_true", help="pass patch contents via stdin", default=False) parser.add_option('', '--update', action="store_true", help="use more relaxed checks for already-commited patches", default=False) (options, args) = parser.parse_args() if not args and not options.stdin: parser.error("Must either provide filename(s) or use --stdin") sys.exit(128) if options.stdin and len(args) > 1 : parser.error("Only one filename can be used with --stdin") sys.exit(128) errors = 0 if options.stdin: if args: fn = args[0] else: fn = "" try: checker = header.Checker(sys.stdin, options.update, fn) except header.HeaderException as e: print(e.error_message(fn), file=sys.stderr) if not fn.startswith("patches.xen/"): errors += 1 else: for fn in args: try: f = open(fn) checker = header.Checker(f, options.update, fn) f.close() except header.HeaderException as e: print(e.error_message(fn), file=sys.stderr) if not fn.startswith("patches.xen/"): errors += 1 if errors > 1: print("", file=sys.stderr) if errors: print("Please check README file for patch tag rules.", file=sys.stderr) sys.exit(1)