|
19 | 19 |
|
20 | 20 | from __future__ import annotations
|
21 | 21 |
|
| 22 | +import os |
22 | 23 | import re
|
| 24 | +import subprocess |
23 | 25 | from os import listdir
|
24 | 26 | from pathlib import Path
|
25 | 27 |
|
@@ -356,37 +358,26 @@ def unasync_directory(files: list[str], src: str, dest: str, replacements: dict[
|
356 | 358 |
|
357 | 359 |
|
358 | 360 | def main() -> None:
|
359 |
| - # output = subprocess.check_output(['git', 'status', '-s']).decode('utf8') |
360 |
| - # modified_files = set() |
361 |
| - # for line in output.splitlines(): |
362 |
| - # modified_files.add('./' + line.strip().split(' ')[1]) |
363 |
| - # target_before_content = dict() |
364 |
| - # for dest in [_pymongo_dest_base, _gridfs_dest_base, _test_dest_base]: |
365 |
| - # for target in Path(dest).glob('*.py'): |
366 |
| - # target_before_content[str(target)] = target.read_text() |
| 361 | + output = subprocess.check_output(["git", "status", "-s"]).decode("utf8") # noqa:S603,S607 |
| 362 | + modified_files = set() |
| 363 | + for line in output.splitlines(): |
| 364 | + modified_files.add("./" + line.strip().split(" ")[1]) |
| 365 | + errored = False |
| 366 | + for fname in async_files + gridfs_files: |
| 367 | + if str(fname) in modified_files: |
| 368 | + continue |
| 369 | + sync_name = str(fname).replace("asynchronous", "synchronous") |
| 370 | + if sync_name in modified_files and "OVERRIDE_SYNCHRO_CHECK" not in os.environ: |
| 371 | + print(f"Refusing to overwrite {sync_name}") |
| 372 | + errored = True |
| 373 | + if errored: |
| 374 | + raise ValueError("Aborting synchro due to errors") |
| 375 | + return |
367 | 376 | unasync_directory(async_files, _pymongo_base, _pymongo_dest_base, replacements)
|
368 | 377 | unasync_directory(gridfs_files, _gridfs_base, _gridfs_dest_base, replacements)
|
369 | 378 | unasync_directory(test_files, _test_base, _test_dest_base, replacements)
|
370 | 379 | process_files(sync_files + sync_gridfs_files + sync_test_files)
|
371 | 380 |
|
372 |
| - # if os.environ.get('OVERRIDE_SYNC_FILES'): |
373 |
| - # return |
374 |
| - |
375 |
| - # errored = False |
376 |
| - # for fname in sync_files + sync_gridfs_files: |
377 |
| - # async_name = fname.replace('synchronous', 'asynchronous') |
378 |
| - # if async_name in modified_files: |
379 |
| - # continue |
380 |
| - # target = Path(fname) |
381 |
| - # new_text = target.read_text() |
382 |
| - # old_text = target_before_content[str(target)] |
383 |
| - # if new_text != old_text: |
384 |
| - # target.write_text(old_text) |
385 |
| - # errored = True |
386 |
| - # print(f"Refusing to overwrite {target}") |
387 |
| - # if errored: |
388 |
| - # raise ValueError('Encountered errors') |
389 |
| - |
390 | 381 |
|
391 | 382 | if __name__ == "__main__":
|
392 | 383 | main()
|
0 commit comments