mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
Merge remote-tracking branch 'upstream/main' into add-sync_to_translation_status.er
This commit is contained in:
commit
c3d27fb059
47 changed files with 462 additions and 237 deletions
23
doc/scripts/align_files.py
Normal file
23
doc/scripts/align_files.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
import glob
|
||||
|
||||
"""
|
||||
Align file prefixes when they are not numbered consecutively.
|
||||
existing files: 01_foo.md, 03_bar.md, 04_baz.md
|
||||
result: 01_foo.md, 02_bar.md, 03_baz.md
|
||||
"""
|
||||
if __name__ == '__main__':
|
||||
prev = None
|
||||
diff = None
|
||||
for f in sorted(glob.glob("[0-9][0-9]_*")):
|
||||
if prev != None:
|
||||
now_file_no = int(f.split("_")[0])
|
||||
diff = now_file_no - prev
|
||||
if diff != 1:
|
||||
replace_to = "_".join([f"{now_file_no-diff+1:02d}", *f.split("_")[1:]])
|
||||
os.rename(f, replace_to)
|
||||
prev = now_file_no - diff + 1
|
||||
else:
|
||||
prev = now_file_no
|
||||
else:
|
||||
prev = int(f.split("_")[0])
|
43
doc/scripts/insert_file.py
Normal file
43
doc/scripts/insert_file.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
import os
|
||||
import sys
|
||||
import glob
|
||||
|
||||
"""
|
||||
Insert a file into files followed by a sequential number. Existing files are shifted by one.
|
||||
example:
|
||||
existing files: 01_foo.md, 02_bar.md, 03_baz.md
|
||||
1st arg(inserting file): qux.md
|
||||
2nd arg(file no): 2
|
||||
result: 01_foo.md, 02_qux.md, 03_bar.md, 04_baz.md
|
||||
"""
|
||||
if __name__ == '__main__':
|
||||
file = sys.argv[1]
|
||||
file_no = sys.argv[2]
|
||||
if not file_no.isdigit():
|
||||
raise ValueError('File number must be a number')
|
||||
else:
|
||||
file_no = int(file_no)
|
||||
|
||||
if len(glob.glob("_[0-9][0-9]_*")) > 0:
|
||||
raise Exception("Escaped file already exists, rename it")
|
||||
# escaping
|
||||
for esc in sorted(glob.glob("[0-9][0-9]_*")):
|
||||
if int(esc.split("_")[0]) < file_no: continue
|
||||
else: os.rename(esc, "_" + esc)
|
||||
|
||||
target = f"{file_no:02d}_" + file
|
||||
if os.path.exists(target):
|
||||
raise OSError(f"File {target} already exists")
|
||||
os.rename(file, target)
|
||||
|
||||
while True:
|
||||
nxt = glob.glob(f"_{file_no:02d}_*")
|
||||
if len(nxt) == 0:
|
||||
exit(0)
|
||||
elif len(nxt) >= 2:
|
||||
raise ValueError("More than one file with the same number")
|
||||
else:
|
||||
target = nxt[0]
|
||||
replace_to = "_".join([f"{file_no+1:02d}", *target.split("_")[2:]])
|
||||
os.rename(target, replace_to)
|
||||
file_no += 1
|
Loading…
Add table
Add a link
Reference in a new issue