| 24 | |
| 25 | |
| 26 | def run_file(cmd: code_writer_cmd, file: Path, update_year: bool): |
| 27 | content = file.read_text("utf-8") |
| 28 | path = str(file.relative_to(sa_path)).replace("\\", "/") # handle windows |
| 29 | path_comment = f"# {path}" |
| 30 | has_license = bool(license_re.search(content)) |
| 31 | if file_re.match(content.strip()): |
| 32 | if has_license: |
| 33 | to_sub = path_comment |
| 34 | else: |
| 35 | to_sub = path_comment + license_ |
| 36 | content = file_re.sub(to_sub, content, count=1) |
| 37 | else: |
| 38 | content = path_comment + ("\n" if has_license else license_) + content |
| 39 | |
| 40 | if has_license and update_year: |
| 41 | content = license_re.sub( |
| 42 | rf"Copyright (C) \1-{this_year} the SQLAlchemy " |
| 43 | "authors and contributors", |
| 44 | content, |
| 45 | 1, |
| 46 | ) |
| 47 | cmd.write_output_file_from_text(content, file) |
| 48 | |
| 49 | |
| 50 | def run(cmd: code_writer_cmd, update_year: bool): |