diff --git a/scripts/tools/fix-header.py b/scripts/tools/fix-header.py index fd9867595..087e07d91 100755 --- a/scripts/tools/fix-header.py +++ b/scripts/tools/fix-header.py @@ -137,7 +137,8 @@ def parse_file(path, encoding='utf-8'): start = end = None authors_from_file = {} - skip_pattern = re.compile(r'^(?:#|/\*|//)\s+(fix-header:\s*skip|Automatically\s+generated|Created\s+by:\s+The\s+Resource\s+Compiler\s+for\s+PyQt5)', re.IGNORECASE) + fix_header_pattern = re.compile(r'^(?:#|/\*|//)\s+(fix-header:)\s*(.*)$', re.IGNORECASE) + skip_pattern = re.compile(r'^(?:#|/\*|//)\s+(Automatically\s+generated|Created\s+by:\s+The\s+Resource\s+Compiler\s+for\s+PyQt5)', re.IGNORECASE) with open(path, encoding=encoding) as f: lines = f.readlines() found = defaultdict(lambda: None) @@ -145,10 +146,22 @@ def parse_file(path, encoding='utf-8'): found["shebang"] = lines[0].rstrip() del lines[0] for num, line in enumerate(lines): - match = skip_pattern.search(line) - if match: - found['skip'] = match.group(1) + skip_matched = skip_pattern.search(line) + if skip_matched: + found['skip'] = skip_matched.group(1) + logging.debug("Found skip indicator: {}".format(found['skip'])) return (found, {}, {}, '', "".join(lines)) + fix_header_matched = fix_header_pattern.search(line) + if fix_header_matched: + words = fix_header_matched.group(2).lower().split() + if 'nolicense' in words: + # do not add a license header + logging.debug("Found fix-header: nolicense") + found['nolicense'] = True + if 'skip' in words: + logging.debug("Found fix-header: skip") + found['skip'] = fix_header_matched.group(1) + ' ' + fix_header_matched.group(2) + return (found, {}, {}, '', "".join(lines)) for num, line in enumerate(lines): if not line.startswith("#") and line not in EMPTY_LINE: @@ -265,9 +278,9 @@ def fix_header(path, encoding='utf-8'): parts = list(filter(None, [ found["shebang"], CODING_TEXT.strip(), - LICENSE_TOP.strip(), - new_copyright.strip(), - LICENSE_BOTTOM.strip() + ("\n\n" if has_content else ""), + LICENSE_TOP.strip() if not found['nolicense'] else None, + new_copyright.strip() if not found['nolicense'] else None, + (LICENSE_BOTTOM.strip() + ("\n\n" if has_content else "")) if not found['nolicense'] else None, before.strip(), after.strip(), ]))