2Copyright 2011 Google Inc.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
9Updates all copyright headers within our code:
10- For files that already have a copyright header, the header is modified
11 while keeping the year
and holder intact.
12- For files that don
't have a copyright header, we add one with the current
13 year and default holder.
15@author: epoger
@google.com
19from __future__ import print_function
26# Only modify copyright stanzas if the copyright holder is one of these.
27ALLOWED_COPYRIGHT_HOLDERS = [
30 'The Android Open Source Project',
36 @param root_directory root directory within which to modify all files
39 for filepath
in filepaths:
42 ReportWarning(
'cannot find a parser for file %s, skipping...' %
46 comment_blocks = parser.FindAllCommentBlocks(old_file_contents)
47 if not comment_blocks:
50 old_copyright_block = parser.FindCopyrightBlock(comment_blocks)
51 if not old_copyright_block:
52 ReportWarning(
'cannot find copyright block in file %s' % filepath)
53 (year, holder) = parser.GetCopyrightBlockAttributes(old_copyright_block)
56 'unrecognized copyright holder "%s" in file %s, skipping...' % (
59 new_copyright_block = parser.CreateCopyrightBlock(year, holder)
60 if old_copyright_block:
61 new_file_contents = old_file_contents.replace(
62 old_copyright_block, new_copyright_block, 1)
64 new_file_contents = new_copyright_block + old_file_contents
69 """Return a list of all files (absolute path for each one) within a tree.
71 @param root_directory root directory within which to find all files
74 for dirpath, _, filenames
in os.walk(root_directory):
75 for filename
in filenames:
76 path_list.append(os.path.abspath(os.path.join(dirpath, filename)))
81 """Report a warning, but continue.
83 print('warning: %s' % text)
87 """Report an error and raise an exception.
93 """Returns the full contents of this file as a string.
95 with open(filepath,
'r')
as file_handle:
96 contents = file_handle.read()
101 """Writes this string out to filepath, replacing the file if it already
104 with open(filepath,
'w')
as file_handle:
105 file_handle.write(string)
109 """Returns True if this is one of our allowed copyright holders.
111 @param holder copyright holder
as a string
113 return holder
in ALLOWED_COPYRIGHT_HOLDERS
def CreateParser(filepath)
def WriteStringToFile(string, filepath)
def ConfirmAllowedCopyrightHolder(holder)
def GetAllFilepaths(root_directory)
def ReadFileIntoString(filepath)
def print(*args, **kwargs)