diff options
author | murgatroid99 <mlumish@google.com> | 2016-01-13 11:42:18 -0800 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2016-01-13 11:42:18 -0800 |
commit | b70206fe52ee6509f3f965bf2a95b2cbd321088d (patch) | |
tree | fa59a43171854465c89af72734d45350070b7366 /tools/distrib/check_copyright.py | |
parent | 295a7ce511f1a2145f70942f826d0e225c00ba62 (diff) | |
parent | 7149ca6bd0ce73a08fa512415d3f641a06a15a75 (diff) |
Merge branch 'master' into release-0_12_master_merge
Diffstat (limited to 'tools/distrib/check_copyright.py')
-rwxr-xr-x | tools/distrib/check_copyright.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py index 2fb0d82bb0..7378ddc4c0 100755 --- a/tools/distrib/check_copyright.py +++ b/tools/distrib/check_copyright.py @@ -54,6 +54,9 @@ argp.add_argument('-a', '--ancient', default=0, action='store_const', const=1) +argp.add_argument('-f', '--fix', + default=False, + action='store_true'); args = argp.parse_args() # open the license text @@ -90,7 +93,7 @@ KNOWN_BAD = set([ ]) -RE_YEAR = r'Copyright (?:[0-9]+\-)?([0-9]+), Google Inc\.' +RE_YEAR = r'Copyright (?P<first_year>[0-9]+\-)?(?P<last_year>[0-9]+), Google Inc\.' RE_LICENSE = dict( (k, r'\n'.join( LICENSE_PREFIX[k] + @@ -103,6 +106,9 @@ def load(name): with open(name) as f: return '\n'.join(line.rstrip() for line in f.read().splitlines()) +def save(name, text): + with open(name, 'w') as f: + f.write(text) assert(re.search(RE_LICENSE['LICENSE'], load('LICENSE'))) assert(re.search(RE_LICENSE['Makefile'], load('Makefile'))) @@ -117,6 +123,7 @@ def log(cond, why, filename): # scan files, validate the text +ok = True for filename in subprocess.check_output('git ls-tree -r --name-only -r HEAD', shell=True).splitlines(): if filename in KNOWN_BAD: continue @@ -130,14 +137,25 @@ for filename in subprocess.check_output('git ls-tree -r --name-only -r HEAD', log(args.skips, 'skip', filename) continue text = load(filename) - ok = True m = re.search(re_license, text) if m: + gdict = m.groupdict() last_modified = int(subprocess.check_output('git log -1 --format="%ad" --date=short -- ' + filename, shell=True)[0:4]) - latest_claimed = int(m.group(1)) + latest_claimed = int(gdict['last_year']) if last_modified > latest_claimed: print '%s modified %d but copyright only extends to %d' % (filename, last_modified, latest_claimed) ok = False + if args.fix: + span_start, span_end = m.span(2) + if not gdict['first_year']: + # prepend the old year to the current one. + text = '{}-{}{}'.format(text[:span_end], last_modified, text[span_end:]) + else: # already a year range + # simply update the last year + text = '{}{}{}'.format(text[:span_start], last_modified, text[span_end:]) + save(filename, text) + print 'Fixed!' + ok = True elif 'DO NOT EDIT' not in text and 'AssemblyInfo.cs' not in filename and filename != 'src/boringssl/err_data.c': log(1, 'copyright missing', filename) ok = False |