Improve copyrihgt header detection

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: Ib1c0928bc1323dc9b76e0f1fc64d4cb50b520ea6
This commit is contained in:
Alexey Polyudov
2020-06-04 16:17:04 -07:00
parent f307784c97
commit f4007e63ce
+11 -4
View File
@@ -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