diff options
author | David Garcia Quintas <dgq@google.com> | 2016-01-12 15:44:30 -0800 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-01-12 15:44:30 -0800 |
commit | 57bc9d2b56c10b520817417a5ee89412221d677d (patch) | |
tree | aa94514573bca994c7b9b7ff5920b3825728bbf8 /tools/distrib | |
parent | 23f28a9b2cdecaff4a7f4a05bdffabcea47421cc (diff) | |
parent | fa58786f5f75f29775ce4f125c78ea1c24494d77 (diff) |
Merge branch 'copyright_fix' into grpclb_api
Diffstat (limited to 'tools/distrib')
-rwxr-xr-x | tools/distrib/check_copyright.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py index 5158c11417..5e948e2dee 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'))) @@ -133,11 +139,23 @@ for filename in subprocess.check_output('git ls-tree -r --name-only -r HEAD', text = load(filename) 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 |