aboutsummaryrefslogtreecommitdiff
path: root/contrib/devtools
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2019-01-24 22:49:48 -0800
committerBen Woosley <ben.woosley@gmail.com>2019-01-24 23:46:06 -0800
commit2434ab5c2afd61aa0cf81f80b1b236ea52d1d20d (patch)
tree6fda93c7d503b93b596a4f9534ae2f83ccd0e91a /contrib/devtools
parent72bd4ab867e3be0d8410403d9641c08288d343e3 (diff)
downloadbitcoin-2434ab5c2afd61aa0cf81f80b1b236ea52d1d20d.tar.xz
Scripts and tools: Fix devtools/copyright_header.py to always honor exclusions
This script compared paths relative to the report directory to test for exclusion, meaning the directory exclusions did not work properly, as they were relative to the project root. Fix this by creating absolute paths through the combination of: 'git ls-files --full-name' and 'git rev-parse --show-toplevel'
Diffstat (limited to 'contrib/devtools')
-rwxr-xr-xcontrib/devtools/copyright_header.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/contrib/devtools/copyright_header.py b/contrib/devtools/copyright_header.py
index 6d7a592f01..1bc304c947 100755
--- a/contrib/devtools/copyright_header.py
+++ b/contrib/devtools/copyright_header.py
@@ -48,15 +48,22 @@ def applies_to_file(filename):
# obtain list of files in repo according to INCLUDE and EXCLUDE
################################################################################
-GIT_LS_CMD = 'git ls-files'
+GIT_LS_CMD = 'git ls-files --full-name'.split(' ')
+GIT_TOPLEVEL_CMD = 'git rev-parse --show-toplevel'.split(' ')
-def call_git_ls():
- out = subprocess.check_output(GIT_LS_CMD.split(' '))
+def call_git_ls(base_directory):
+ out = subprocess.check_output([*GIT_LS_CMD, base_directory])
return [f for f in out.decode("utf-8").split('\n') if f != '']
-def get_filenames_to_examine():
- filenames = call_git_ls()
- return sorted([filename for filename in filenames if
+def call_git_toplevel():
+ "Returns the absolute path to the project root"
+ return subprocess.check_output(GIT_TOPLEVEL_CMD).strip().decode("utf-8")
+
+def get_filenames_to_examine(base_directory):
+ "Returns an array of absolute paths to any project files in the base_directory that pass the include/exclude filters"
+ root = call_git_toplevel()
+ filenames = call_git_ls(base_directory)
+ return sorted([os.path.join(root, filename) for filename in filenames if
applies_to_file(filename)])
################################################################################
@@ -146,7 +153,7 @@ def file_has_without_c_style_copyright_for_holder(contents, holder_name):
################################################################################
def read_file(filename):
- return open(os.path.abspath(filename), 'r', encoding="utf8").read()
+ return open(filename, 'r', encoding="utf8").read()
def gather_file_info(filename):
info = {}
@@ -260,12 +267,9 @@ def print_report(file_infos, verbose):
print(SEPARATOR)
def exec_report(base_directory, verbose):
- original_cwd = os.getcwd()
- os.chdir(base_directory)
- filenames = get_filenames_to_examine()
+ filenames = get_filenames_to_examine(base_directory)
file_infos = [gather_file_info(f) for f in filenames]
print_report(file_infos, verbose)
- os.chdir(original_cwd)
################################################################################
# report cmd
@@ -325,13 +329,13 @@ def get_most_recent_git_change_year(filename):
################################################################################
def read_file_lines(filename):
- f = open(os.path.abspath(filename), 'r', encoding="utf8")
+ f = open(filename, 'r', encoding="utf8")
file_lines = f.readlines()
f.close()
return file_lines
def write_file_lines(filename, file_lines):
- f = open(os.path.abspath(filename), 'w', encoding="utf8")
+ f = open(filename, 'w', encoding="utf8")
f.write(''.join(file_lines))
f.close()
@@ -399,11 +403,8 @@ def update_updatable_copyright(filename):
"Copyright updated! -> %s" % last_git_change_year)
def exec_update_header_year(base_directory):
- original_cwd = os.getcwd()
- os.chdir(base_directory)
- for filename in get_filenames_to_examine():
+ for filename in get_filenames_to_examine(base_directory):
update_updatable_copyright(filename)
- os.chdir(original_cwd)
################################################################################
# update cmd