Skip to content

Commit 1c51a9e

Browse files
committed
wip
1 parent 6167280 commit 1c51a9e

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

tools/synchro.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
from __future__ import annotations
2121

22+
import os
2223
import re
24+
import subprocess
2325
from os import listdir
2426
from pathlib import Path
2527

@@ -356,37 +358,26 @@ def unasync_directory(files: list[str], src: str, dest: str, replacements: dict[
356358

357359

358360
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
367376
unasync_directory(async_files, _pymongo_base, _pymongo_dest_base, replacements)
368377
unasync_directory(gridfs_files, _gridfs_base, _gridfs_dest_base, replacements)
369378
unasync_directory(test_files, _test_base, _test_dest_base, replacements)
370379
process_files(sync_files + sync_gridfs_files + sync_test_files)
371380

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-
390381

391382
if __name__ == "__main__":
392383
main()

0 commit comments

Comments
 (0)