mirror of
https://github.com/modelscope/DiffSynth-Studio.git
synced 2026-03-19 06:48:12 +00:00
DiffSynth-Studio 2.0 major update
This commit is contained in:
43
examples/dev_tools/fix_path.py
Normal file
43
examples/dev_tools/fix_path.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import re, os
|
||||
|
||||
|
||||
def read_file(path):
|
||||
with open(path, "r", encoding="utf-8-sig") as f:
|
||||
context = f.read()
|
||||
return context
|
||||
|
||||
def get_files(files, path):
|
||||
if os.path.isdir(path):
|
||||
for folder in os.listdir(path):
|
||||
get_files(files, os.path.join(path, folder))
|
||||
elif path.endswith(".md"):
|
||||
files.append(path)
|
||||
|
||||
def fix_path(doc_root_path):
|
||||
files = []
|
||||
get_files(files, doc_root_path)
|
||||
file_map = {}
|
||||
for file in files:
|
||||
name = file.split("/")[-1]
|
||||
file_map[name] = "/" + file
|
||||
|
||||
pattern = re.compile(r'\]\([^)]*\.md')
|
||||
for file in files:
|
||||
context = read_file(file)
|
||||
matches = pattern.findall(context)
|
||||
|
||||
edited = False
|
||||
for match in matches:
|
||||
target = "](" + file_map[match.split("/")[-1].replace("](", "")]
|
||||
context = context.replace(match, target)
|
||||
if target != match:
|
||||
print(match, target)
|
||||
edited = True
|
||||
print(file, match, target)
|
||||
|
||||
if edited:
|
||||
with open(file, "w", encoding="utf-8") as f:
|
||||
f.write(context)
|
||||
|
||||
fix_path("doc/zh")
|
||||
fix_path("doc/en")
|
||||
Reference in New Issue
Block a user