Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions presto-native-execution/scripts/license-header.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ def wrapper_hash(header, args):
}
)

file_pattern = regex.compile(
"|".join(["^" + fnmatch.translate(type) + "$" for type in file_types.keys()])
)


def get_filename(filename):
return os.path.basename(filename)
Expand Down Expand Up @@ -155,14 +151,25 @@ def main():

header_text = file_lines(args.header)

# fnmatch.translate can generate "\z" in the regex pattern
# which causes an error when compiled by regex:
# regex._regex_core.error: bad escape \z at position 23
# Usually, the pattern is generated with "\Z" which works fine.
raw_pattern = "|".join(
["^" + fnmatch.translate(type) + "$" for type in file_types.keys()]
)
pattern = raw_pattern.replace(r"\z", "\\Z")
message(log_to, "File pattern : " + pattern)
file_pattern = regex.compile(pattern)

if len(args.files) == 1 and args.files[0] == "-":
files = [file.strip() for file in sys.stdin.readlines()]
else:
files = args.files

for filepath in files:
filename = get_filename(filepath)

message(log_to, "File processed : " + filename)
matched = file_pattern.match(filename)

if not matched:
Expand Down
Loading