aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/distrib/check_copyright.py
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2016-01-12 15:31:40 -0800
committerGravatar David Garcia Quintas <dgq@google.com>2016-01-12 15:39:07 -0800
commitfa58786f5f75f29775ce4f125c78ea1c24494d77 (patch)
tree50217dc560aa9d668805bdf6af5071c6bfa2ac67 /tools/distrib/check_copyright.py
parent0ade2d415ff5dbc9fca7b942809ef7179db08ef7 (diff)
Added --fix flag to check_copyright.py
Diffstat (limited to 'tools/distrib/check_copyright.py')
-rwxr-xr-xtools/distrib/check_copyright.py22
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