1*7078Smjnelson#! /usr/bin/python 2*7078Smjnelson# 3*7078Smjnelson# CDDL HEADER START 4*7078Smjnelson# 5*7078Smjnelson# The contents of this file are subject to the terms of the 6*7078Smjnelson# Common Development and Distribution License (the "License"). 7*7078Smjnelson# You may not use this file except in compliance with the License. 8*7078Smjnelson# 9*7078Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7078Smjnelson# or http://www.opensolaris.org/os/licensing. 11*7078Smjnelson# See the License for the specific language governing permissions 12*7078Smjnelson# and limitations under the License. 13*7078Smjnelson# 14*7078Smjnelson# When distributing Covered Code, include this CDDL HEADER in each 15*7078Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7078Smjnelson# If applicable, add the following below this CDDL HEADER, with the 17*7078Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying 18*7078Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner] 19*7078Smjnelson# 20*7078Smjnelson# CDDL HEADER END 21*7078Smjnelson# 22*7078Smjnelson 23*7078Smjnelson# 24*7078Smjnelson# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25*7078Smjnelson# Use is subject to license terms. 26*7078Smjnelson# 27*7078Smjnelson# ident "%Z%%M% %I% %E% SMI" 28*7078Smjnelson# 29*7078Smjnelson 30*7078Smjnelson# 31*7078Smjnelson# Mercurial (lack of) keyword checks 32*7078Smjnelson# 33*7078Smjnelson 34*7078Smjnelsonimport re, sys 35*7078Smjnelson 36*7078Smjnelson# A general 'ident'-style decleration, to allow for leniency. 37*7078Smjnelsonident = re.compile(r'((\%Z\%(\%M\%)\s+\%I\%|\%W\%)\s+\%E\% SMI)') 38*7078Smjnelson 39*7078Smjnelson# 40*7078Smjnelson# Absolutely anything that appears to be an SCCS keyword. 41*7078Smjnelson# It's impossible to programatically differentiate between these 42*7078Smjnelson# and other, legitimate, uses of matching strings. 43*7078Smjnelson# 44*7078Smjnelsonanykword = re.compile(r'%[A-ILMP-UWYZ]%') 45*7078Smjnelson 46*7078Smjnelsondef keywords(fh, filename=None, lenient=False, verbose=False, 47*7078Smjnelson output=sys.stderr): 48*7078Smjnelson '''Search FH for SCCS keywords, which should not be present when 49*7078Smjnelson Mercurial is in use. 50*7078Smjnelson 51*7078Smjnelson If LENIENT, accept #ident-style declarations, for the purposes of 52*7078Smjnelson migration''' 53*7078Smjnelson 54*7078Smjnelson if not filename: 55*7078Smjnelson filename = fh.name 56*7078Smjnelson 57*7078Smjnelson ret = 0 58*7078Smjnelson lineno = 0 59*7078Smjnelson 60*7078Smjnelson for line in fh: 61*7078Smjnelson line = line.rstrip('\r\n') 62*7078Smjnelson lineno += 1 63*7078Smjnelson 64*7078Smjnelson if lenient and ident.search(line): 65*7078Smjnelson continue 66*7078Smjnelson 67*7078Smjnelson match = anykword.findall(line) 68*7078Smjnelson if match: 69*7078Smjnelson ret = 1 70*7078Smjnelson output.write('%s: %d: contains SCCS keywords "%s"\n' % 71*7078Smjnelson (filename, lineno, ', '.join(match))) 72*7078Smjnelson if verbose: 73*7078Smjnelson output.write(" %s\n" % line) 74*7078Smjnelson 75*7078Smjnelson return ret 76