(file)
| 102 | return missing, outdated, failures |
| 103 | |
| 104 | def fix(file): |
| 105 | queries, failures = query_files([file]) |
| 106 | |
| 107 | current_year = datetime.datetime.now().year |
| 108 | |
| 109 | |
| 110 | for filename, tokens in queries.items(): |
| 111 | if not tokens: |
| 112 | continue |
| 113 | |
| 114 | for token in tokens: |
| 115 | year_range = YEAR_RANGE_PATTERN.search(token) |
| 116 | if year_range: |
| 117 | year_range = year_range.group(0) |
| 118 | start_year, end_year = year_range.split("-") |
| 119 | if int(end_year) != current_year: |
| 120 | fixed_token = token.replace(year_range, start_year + "-" + str(current_year)) |
| 121 | with io.open(filename, "r+", encoding="utf-8") as f: |
| 122 | file_contents = f.read() |
| 123 | file_contents = file_contents.replace(token, fixed_token) |
| 124 | f.seek(0) |
| 125 | f.write(file_contents) |
| 126 | f.truncate( |
| 127 | f.tell() |
| 128 | ) |
| 129 | continue |
| 130 | |
| 131 | year = YEAR_PATTERN.search(token) |
| 132 | if year: |
| 133 | year = year.group(0) |
| 134 | if int(year) != current_year: |
| 135 | fixed_token = token + "-" + str(current_year) |
| 136 | with io.open(filename, "r+", encoding="utf-8") as f: |
| 137 | file_contents = f.read() |
| 138 | file_contents = file_contents.replace(token, fixed_token) |
| 139 | f.seek(0) |
| 140 | f.write(file_contents) |
| 141 | f.truncate( |
| 142 | f.tell() |
| 143 | ) # Truncate the file to the current position of the file pointer |
| 144 | |
| 145 | if __name__ == "__main__": |
| 146 | argument_parser = argparse.ArgumentParser( |
no test coverage detected