From f4007e63ceb819430a0ac6abcc206d3de21113ec Mon Sep 17 00:00:00 2001 From: Alexey Polyudov Date: Thu, 4 Jun 2020 15:25:44 -0700 Subject: [PATCH] Improve copyrihgt header detection Signed-off-by: Alexey Polyudov Change-Id: Ib1c0928bc1323dc9b76e0f1fc64d4cb50b520ea6 --- script/oss.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/script/oss.py b/script/oss.py index bcf835bf..cd0199d8 100755 --- a/script/oss.py +++ b/script/oss.py @@ -17,6 +17,7 @@ import argparse import os +import re import shutil import sys @@ -34,6 +35,8 @@ 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.""".split("\n") +headline_match=".*Copyright [0-9,\- ]+ Google.*" + MISSING = 0 HEADLINE = 1 PARTIAL = 2 @@ -41,20 +44,24 @@ FULL = 3 def has_copyright(lines, max_lookup=3): pos = 0 + result = MISSING + headline = re.compile(headline_match) for line in lines: pos += 1 # points to the next line - if line.find(copy_header[0]) >= 0: + if headline.match(line) != None: + result = HEADLINE break if pos > max_lookup: - return MISSING - - result = HEADLINE + return result for line in copy_header[1:]: + if pos >= len(lines): + return result if lines[pos].find(line) < 0: return result else: result = PARTIAL + pos += 1 return FULL