2Copyright 2011 Google Inc.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
12 """Returns a Parser as appropriate for the file at this filepath.
14 if (filepath.endswith(
'.cpp')
or
15 filepath.endswith(
'.h')
or
16 filepath.endswith(
'.c')):
23 """Base class for all language-specific parsers.
29 'copyright.*\D(\d{4})\W*(\w.*[\w.])', re.IGNORECASE)
32 """Given a list of comment block strings, return the one that seems
33 like the most likely copyright block.
35 Returns None if comment_blocks was empty, or if we couldn't find
36 a comment block that contains copyright info."""
37 if not comment_blocks:
39 for block
in comment_blocks:
44 """Given a comment block, return a tuple of attributes: (year, holder).
46 If comment_block is None, or none of the attributes are found,
47 this will return (None, None)."""
53 first_match = matches[0]
54 return (first_match[0], first_match[1])
58 """Parser that knows how to parse C/C++ files.
61 DEFAULT_YEAR = datetime.date.today().year
62 DEFAULT_HOLDER =
'Google Inc.'
63 COPYRIGHT_BLOCK_FORMAT =
'''
67 * Use of this source code is governed by a BSD-style license that can be
68 * found in the LICENSE file.
77 """Returns a list of all comment blocks within these file contents.
82 """Returns a copyright block suitable for this language, with the
85 @param year year in which to hold copyright (defaults to DEFAULT_YEAR)
86 @param holder holder of copyright (defaults to DEFAULT_HOLDER)
FindAllCommentBlocks(self, file_contents)
str COPYRIGHT_BLOCK_FORMAT
CreateCopyrightBlock(self, year, holder)
FindCopyrightBlock(self, comment_blocks)
GetCopyrightBlockAttributes(self, comment_block)