|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Due to various technical limitations, we sometimes have files that need to be |
| 4 | +# kept identical in the repository. This script loads a database of such |
| 5 | +# files and can perform two functions: check whether they are still identical, |
| 6 | +# and overwrite the others with a master copy if needed. |
| 7 | +# The script that does the actual work is `sync-files.py`, which lives in the `codeql` submodule. |
| 8 | +import sys |
| 9 | +import os |
| 10 | + |
| 11 | +sys.path.append(os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../codeql/config'))) |
| 12 | + |
| 13 | +import importlib |
| 14 | +syncfiles = importlib.import_module('sync-files') |
| 15 | + |
| 16 | +def chdir_repo_root(): |
| 17 | + root_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') |
| 18 | + os.chdir(root_path) |
| 19 | + |
| 20 | +def sync_identical_files(): |
| 21 | + if len(sys.argv) == 1: |
| 22 | + master_file_picker = lambda files: None |
| 23 | + elif len(sys.argv) == 2: |
| 24 | + if sys.argv[1] == "--latest": |
| 25 | + master_file_picker = syncfiles.choose_latest_file |
| 26 | + elif os.path.isfile(sys.argv[1]): |
| 27 | + master_file_picker = lambda files: syncfiles.choose_master_file(sys.argv[1], files) |
| 28 | + else: |
| 29 | + raise Exception("File not found") |
| 30 | + else: |
| 31 | + raise Exception("Bad command line or file not found") |
| 32 | + chdir_repo_root() |
| 33 | + syncfiles.load_if_exists('.', 'scripts/identical-files.json') |
| 34 | + for group_name, files in syncfiles.file_groups.items(): |
| 35 | + syncfiles.check_group(group_name, files, master_file_picker, syncfiles.emit_local_error) |
| 36 | + |
| 37 | +def main(): |
| 38 | + sync_identical_files() |
| 39 | + |
| 40 | + if syncfiles.local_error_count > 0: |
| 41 | + exit(1) |
| 42 | + else: |
| 43 | + print(__file__ +": All checks OK.") |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + main() |
0 commit comments