1cdf0c1d5Smjnelson#! /usr/bin/python 2cdf0c1d5Smjnelson# 3cdf0c1d5Smjnelson# CDDL HEADER START 4cdf0c1d5Smjnelson# 5cdf0c1d5Smjnelson# The contents of this file are subject to the terms of the 6cdf0c1d5Smjnelson# Common Development and Distribution License (the "License"). 7cdf0c1d5Smjnelson# You may not use this file except in compliance with the License. 8cdf0c1d5Smjnelson# 9cdf0c1d5Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10cdf0c1d5Smjnelson# or http://www.opensolaris.org/os/licensing. 11cdf0c1d5Smjnelson# See the License for the specific language governing permissions 12cdf0c1d5Smjnelson# and limitations under the License. 13cdf0c1d5Smjnelson# 14cdf0c1d5Smjnelson# When distributing Covered Code, include this CDDL HEADER in each 15cdf0c1d5Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16cdf0c1d5Smjnelson# If applicable, add the following below this CDDL HEADER, with the 17cdf0c1d5Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying 18cdf0c1d5Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner] 19cdf0c1d5Smjnelson# 20cdf0c1d5Smjnelson# CDDL HEADER END 21cdf0c1d5Smjnelson# 22cdf0c1d5Smjnelson 23cdf0c1d5Smjnelson# 24861a9162SJohn Beck# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 25cdf0c1d5Smjnelson# 26cdf0c1d5Smjnelson 27*2f54b716SRichard Lowe# Copyright 2008, 2010, Richard Lowe 28*2f54b716SRichard Lowe 29*2f54b716SRichard Lowe# Make sure there is a copyright claim for the current year. 30cdf0c1d5Smjnelson 31cdf0c1d5Smjnelsonimport time, re, sys 32cdf0c1d5Smjnelson 33*2f54b716SRichard Lowedef err(stream, msg, fname): 34cdf0c1d5Smjnelson stream.write("%s: %s\n" % (fname, msg)) 35cdf0c1d5Smjnelson 36*2f54b716SRichard Lowedef is_copyright(line): 37*2f54b716SRichard Lowe return re.search(r'Copyright (?!\[yyyy\])', line) 38cdf0c1d5Smjnelson 39*2f54b716SRichard Lowedef is_current_copyright(line): 40*2f54b716SRichard Lowe return re.search(r'Copyright.*\b%s\b' % time.strftime('%Y'), line) 41861a9162SJohn Beck 42cdf0c1d5Smjnelsondef copyright(fh, filename=None, output=sys.stderr): 43*2f54b716SRichard Lowe ret = rights = goodrights = 0 44cdf0c1d5Smjnelson 45cdf0c1d5Smjnelson if not filename: 46cdf0c1d5Smjnelson filename = fh.name 47cdf0c1d5Smjnelson 48cdf0c1d5Smjnelson for line in fh: 49*2f54b716SRichard Lowe if is_copyright(line): 50cdf0c1d5Smjnelson rights += 1 51*2f54b716SRichard Lowe if is_current_copyright(line): 52*2f54b716SRichard Lowe goodrights += 1 53*2f54b716SRichard Lowe break 54cdf0c1d5Smjnelson 55cdf0c1d5Smjnelson if rights == 0: 56cdf0c1d5Smjnelson err(output, "no copyright message found", filename) 57cdf0c1d5Smjnelson ret = 1 58*2f54b716SRichard Lowe elif goodrights == 0: 59*2f54b716SRichard Lowe err(output, "no copyright claim for current year found", 60*2f54b716SRichard Lowe filename) 61*2f54b716SRichard Lowe ret = 1 62cdf0c1d5Smjnelson 63cdf0c1d5Smjnelson return ret 64