51 branding regression for boot menu
[illumos-gate.git] / usr / src / tools / onbld / Checks / Copyright.py
blobda1dcb6eb73f06a58c50fd1aa75a9b146bdd57e0
1 #! /usr/bin/python
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 # Make sure there is a correctly formed copyright message containing
29 # the current year.
31 # We treat extant but incorrect copyrights of known format as present
32 # for the purposes of the "no copyright found" messages to avoid
33 # treating every otherwise incorrect copyright as also not present
36 import time, re, sys
38 def err(stream, msg, fname, line=None):
39 if line:
40 stream.write("%s: %d: %s\n" % (fname, line, msg))
41 else:
42 stream.write("%s: %s\n" % (fname, msg))
44 # pre-2002 copyright with '(c)'
45 oldcopyright = re.compile(r'Copyright \(c\) .* Sun Microsystems, Inc\.')
47 # pre-2002 copyright with 'by'
48 oldcopyright1 = re.compile(r'Copyright .* by Sun Microsystems, Inc\.')
50 # last valid Sun copyright
51 suncopyright = re.compile(r'Copyright ([\d, -]+) Sun Microsystems, Inc\.' +
52 r'(\s+)(All rights reserved\.)?')
54 # old, check to make sure no longer present
55 licterms = 'Use is subject to license terms.'
57 # initial Oracle copyright
58 goodcopyright = re.compile(r'Copyright \(c\) (\d\d\d\d, )?(\d\d\d\d)(,)? ' +
59 r'Oracle and/or its affiliates\.(\s+)' +
60 r'All rights reserved\.')
62 def copyright(fh, filename=None, output=sys.stderr):
63 ret = lineno = rights = 0
64 check_license = False
66 if not filename:
67 filename = fh.name
69 for line in fh:
70 lineno += 1
72 if check_license:
73 check_license = False
74 if licterms in line:
75 err(output, "old '%s' message found" % licterms,
76 filename, lineno)
77 ret = 1
78 continue
80 if oldcopyright.search(line):
81 err(output, "ancient Sun copyright", filename,
82 lineno)
83 rights += 1
84 ret = 1
85 check_license = True
86 continue
87 elif oldcopyright1.search(line):
88 err(output, "pre-2002 Sun copyright", filename, lineno)
89 rights += 1
90 ret = 1
91 check_license = True
92 continue
93 elif suncopyright.search(line):
94 err(output, "old Sun copyright", filename, lineno)
95 rights += 1
96 ret = 1
97 check_license = True
98 continue
101 # group 1 = optional initial year
102 # group 2 = current year
103 # group 3 = comma after current year
104 # group 4 = spacing between phrases
106 match = goodcopyright.search(line)
107 if match:
108 # only check for the old license message on the line
109 # following a copyright match
110 check_license = True
111 rights += 1
113 year = time.strftime('%Y')
114 if match.group(2) != year:
115 err(output, "wrong copyright year %s, should "
116 "be %s" %
117 (match.group(2), year), filename, lineno)
118 ret = 1
120 if match.group(3) != ',':
121 err(output, "need comma after current year",
122 filename, lineno)
123 ret = 1
125 if match.group(4) != ' ':
126 err(output, "need one space between copyright "
127 "and all rights reserved phrases",
128 filename, lineno)
129 ret = 1
131 if rights == 0:
132 err(output, "no copyright message found", filename)
133 ret = 1
135 return ret