Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/copyright_header.py
Show All 40 Lines | EXCLUDE_COMPILED = re.compile( | ||||
'|'.join([fnmatch.translate(m) for m in EXCLUDE])) | '|'.join([fnmatch.translate(m) for m in EXCLUDE])) | ||||
INCLUDE = ['*.h', '*.cpp', '*.cc', '*.c', '*.py'] | INCLUDE = ['*.h', '*.cpp', '*.cc', '*.c', '*.py'] | ||||
INCLUDE_COMPILED = re.compile( | INCLUDE_COMPILED = re.compile( | ||||
'|'.join([fnmatch.translate(m) for m in INCLUDE])) | '|'.join([fnmatch.translate(m) for m in INCLUDE])) | ||||
def applies_to_file(filename): | def applies_to_file(filename): | ||||
return ((EXCLUDE_COMPILED.match(filename) is None) and | return ((EXCLUDE_COMPILED.match(filename) is None) | ||||
(INCLUDE_COMPILED.match(filename) is not None)) | and (INCLUDE_COMPILED.match(filename) is not None)) | ||||
################################################################################ | ################################################################################ | ||||
# obtain list of files in repo according to INCLUDE and EXCLUDE | # obtain list of files in repo according to INCLUDE and EXCLUDE | ||||
################################################################################ | ################################################################################ | ||||
GIT_LS_CMD = 'git ls-files' | GIT_LS_CMD = 'git ls-files' | ||||
▲ Show 20 Lines • Show All 348 Lines • ▼ Show 20 Lines | def create_updated_copyright_line(line, last_git_change_year): | ||||
before_copyright = copyright_split[0] | before_copyright = copyright_split[0] | ||||
after_copyright = copyright_split[1] | after_copyright = copyright_split[1] | ||||
space_split = after_copyright.split(' ') | space_split = after_copyright.split(' ') | ||||
year_range = space_split[0] | year_range = space_split[0] | ||||
start_year, end_year = parse_year_range(year_range) | start_year, end_year = parse_year_range(year_range) | ||||
if end_year == last_git_change_year: | if end_year == last_git_change_year: | ||||
return line | return line | ||||
return (before_copyright + copyright_splitter + | return (before_copyright + copyright_splitter | ||||
year_range_to_str(start_year, last_git_change_year) + ' ' + | + year_range_to_str(start_year, last_git_change_year) + ' ' | ||||
' '.join(space_split[1:])) | + ' '.join(space_split[1:])) | ||||
def update_updatable_copyright(filename): | def update_updatable_copyright(filename): | ||||
file_lines = read_file_lines(filename) | file_lines = read_file_lines(filename) | ||||
index, line = get_updatable_copyright_line(file_lines) | index, line = get_updatable_copyright_line(file_lines) | ||||
if not line: | if not line: | ||||
print_file_action_message(filename, "No updatable copyright.") | print_file_action_message(filename, "No updatable copyright.") | ||||
return | return | ||||
last_git_change_year = get_most_recent_git_change_year(filename) | now = datetime.datetime.now() | ||||
new_line = create_updated_copyright_line(line, last_git_change_year) | current_year = now.year | ||||
new_line = create_updated_copyright_line(line, current_year) | |||||
if line == new_line: | if line == new_line: | ||||
print_file_action_message(filename, "Copyright up-to-date.") | print_file_action_message(filename, "Copyright up-to-date.") | ||||
return | return | ||||
file_lines[index] = new_line | file_lines[index] = new_line | ||||
write_file_lines(filename, file_lines) | write_file_lines(filename, file_lines) | ||||
print_file_action_message(filename, | print_file_action_message(filename, | ||||
"Copyright updated! -> {}".format( | "Copyright updated! -> {}".format( | ||||
last_git_change_year)) | current_year)) | ||||
def exec_update_header_year(base_directory): | def exec_update_header_year(base_directory): | ||||
original_cwd = os.getcwd() | original_cwd = os.getcwd() | ||||
os.chdir(base_directory) | os.chdir(base_directory) | ||||
for filename in get_filenames_to_examine(): | for filename in get_filenames_to_examine(): | ||||
update_updatable_copyright(filename) | update_updatable_copyright(filename) | ||||
os.chdir(original_cwd) | os.chdir(original_cwd) | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |