Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/copyright_header.py
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | def get_filenames_to_examine(): | ||||
return sorted([filename for filename in filenames if | return sorted([filename for filename in filenames if | ||||
applies_to_file(filename)]) | applies_to_file(filename)]) | ||||
################################################################################ | ################################################################################ | ||||
# define and compile regexes for the patterns we are looking for | # define and compile regexes for the patterns we are looking for | ||||
################################################################################ | ################################################################################ | ||||
COPYRIGHT_WITH_C = 'Copyright \(c\)' | COPYRIGHT_WITH_C = r'Copyright \(c\)' | ||||
COPYRIGHT_WITHOUT_C = 'Copyright' | COPYRIGHT_WITHOUT_C = 'Copyright' | ||||
ANY_COPYRIGHT_STYLE = '({}|{})'.format(COPYRIGHT_WITH_C, COPYRIGHT_WITHOUT_C) | ANY_COPYRIGHT_STYLE = '({}|{})'.format(COPYRIGHT_WITH_C, COPYRIGHT_WITHOUT_C) | ||||
YEAR = "20[0-9][0-9]" | YEAR = "20[0-9][0-9]" | ||||
YEAR_RANGE = '({})(-{})?'.format(YEAR, YEAR) | YEAR_RANGE = '({})(-{})?'.format(YEAR, YEAR) | ||||
YEAR_LIST = '({})(, {})+'.format(YEAR, YEAR) | YEAR_LIST = '({})(, {})+'.format(YEAR, YEAR) | ||||
ANY_YEAR_STYLE = '({}|{})'.format(YEAR_RANGE, YEAR_LIST) | ANY_YEAR_STYLE = '({}|{})'.format(YEAR_RANGE, YEAR_LIST) | ||||
ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE = ( | ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE = ( | ||||
"{} {}".format(ANY_COPYRIGHT_STYLE, ANY_YEAR_STYLE)) | "{} {}".format(ANY_COPYRIGHT_STYLE, ANY_YEAR_STYLE)) | ||||
ANY_COPYRIGHT_COMPILED = re.compile(ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE) | ANY_COPYRIGHT_COMPILED = re.compile(ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE) | ||||
def compile_copyright_regex(copyright_style, year_style, name): | def compile_copyright_regex(copyright_style, year_style, name): | ||||
return re.compile('{} {} {}'.format(copyright_style, year_style, name)) | return re.compile('{} {} {}'.format(copyright_style, year_style, name)) | ||||
EXPECTED_HOLDER_NAMES = [ | EXPECTED_HOLDER_NAMES = [ | ||||
"Satoshi Nakamoto\n", | r"Satoshi Nakamoto\n", | ||||
"The Bitcoin Core developers\n", | r"The Bitcoin Core developers\n", | ||||
"The Bitcoin Core developers \n", | r"The Bitcoin Core developers \n", | ||||
"Bitcoin Core Developers\n", | r"Bitcoin Core Developers\n", | ||||
"the Bitcoin Core developers\n", | r"the Bitcoin Core developers\n", | ||||
"The Bitcoin developers\n", | r"The Bitcoin developers\n", | ||||
"The LevelDB Authors\. All rights reserved\.\n", | r"The LevelDB Authors\. All rights reserved\.\n", | ||||
"BitPay Inc\.\n", | r"BitPay Inc\.\n", | ||||
"BitPay, Inc\.\n", | r"BitPay, Inc\.\n", | ||||
"University of Illinois at Urbana-Champaign\.\n", | r"University of Illinois at Urbana-Champaign\.\n", | ||||
"MarcoFalke\n", | r"MarcoFalke\n", | ||||
"Pieter Wuille\n", | r"Pieter Wuille\n", | ||||
"Pieter Wuille +\*\n", | r"Pieter Wuille +\*\n", | ||||
"Pieter Wuille, Gregory Maxwell +\*\n", | r"Pieter Wuille, Gregory Maxwell +\*\n", | ||||
"Pieter Wuille, Andrew Poelstra +\*\n", | r"Pieter Wuille, Andrew Poelstra +\*\n", | ||||
"Andrew Poelstra +\*\n", | r"Andrew Poelstra +\*\n", | ||||
"Wladimir J. van der Laan\n", | r"Wladimir J. van der Laan\n", | ||||
"Jeff Garzik\n", | r"Jeff Garzik\n", | ||||
"Diederik Huys, Pieter Wuille +\*\n", | r"Diederik Huys, Pieter Wuille +\*\n", | ||||
"Thomas Daede, Cory Fields +\*\n", | r"Thomas Daede, Cory Fields +\*\n", | ||||
"Jan-Klaas Kollhof\n", | r"Jan-Klaas Kollhof\n", | ||||
"Sam Rushing\n", | r"Sam Rushing\n", | ||||
"ArtForz -- public domain half-a-node\n", | r"ArtForz -- public domain half-a-node\n", | ||||
"Amaury SÉCHET\n", | r"Amaury SÉCHET\n", | ||||
"Jeremy Rubin\n", | r"Jeremy Rubin\n", | ||||
] | ] | ||||
DOMINANT_STYLE_COMPILED = {} | DOMINANT_STYLE_COMPILED = {} | ||||
YEAR_LIST_STYLE_COMPILED = {} | YEAR_LIST_STYLE_COMPILED = {} | ||||
WITHOUT_C_STYLE_COMPILED = {} | WITHOUT_C_STYLE_COMPILED = {} | ||||
for holder_name in EXPECTED_HOLDER_NAMES: | for holder_name in EXPECTED_HOLDER_NAMES: | ||||
DOMINANT_STYLE_COMPILED[holder_name] = ( | DOMINANT_STYLE_COMPILED[holder_name] = ( | ||||
▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | def write_file_lines(filename, file_lines): | ||||
f.write(''.join(file_lines)) | f.write(''.join(file_lines)) | ||||
f.close() | f.close() | ||||
################################################################################ | ################################################################################ | ||||
# update header years execution | # update header years execution | ||||
################################################################################ | ################################################################################ | ||||
COPYRIGHT = 'Copyright \(c\)' | COPYRIGHT = r'Copyright \(c\)' | ||||
YEAR = "20[0-9][0-9]" | YEAR = "20[0-9][0-9]" | ||||
YEAR_RANGE = '({})(-{})?'.format(YEAR, YEAR) | YEAR_RANGE = '({})(-{})?'.format(YEAR, YEAR) | ||||
HOLDER = 'The Bitcoin developers' | HOLDER = 'The Bitcoin developers' | ||||
UPDATEABLE_LINE_COMPILED = re.compile( | UPDATEABLE_LINE_COMPILED = re.compile( | ||||
' '.join([COPYRIGHT, YEAR_RANGE, HOLDER])) | ' '.join([COPYRIGHT, YEAR_RANGE, HOLDER])) | ||||
def get_updatable_copyright_line(file_lines): | def get_updatable_copyright_line(file_lines): | ||||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |