Skip to content

Commit d2b26ab

Browse files
committed
优化 python数据同步脚本
1 parent 117aa81 commit d2b26ab

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

sync.py

+33-12
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,43 @@
99
current_dir = os.path.dirname(__file__)
1010
zh_cn_dir = os.path.join(current_dir, "zh-cn")
1111
en_dir = os.path.join(current_dir, "en")
12+
zh_hant_dir = os.path.join(current_dir, "zh-hant")
1213

1314
def findAllFile(base):
1415
for root, ds, fs in os.walk(base):
1516
for f in fs:
1617
fullname = os.path.join(root, f)
1718
yield fullname
1819

19-
# 遍历中文目录, 如果英文目录相应文件不存在,则复制。反之,跳过已有。
20-
zh_cn_all_files = findAllFile(zh_cn_dir)
21-
for i in zh_cn_all_files:
22-
relative_path = i.replace(zh_cn_dir + '/', '')
23-
en_target_path = os.path.join(en_dir,relative_path)
24-
if not os.path.exists(en_target_path):
25-
en_target_dir = os.path.dirname(en_target_path)
26-
if not os.path.exists(en_target_dir):
27-
mkdir_cmd = "mkdir -p {0}".format(en_target_dir)
28-
os.system(mkdir_cmd)
29-
cp_cmd = "cp -pf {0} {1}".format(i,en_target_path)
30-
os.system(cp_cmd)
20+
def sync_all():
21+
"""遍历中文目录, 如果英文目录/繁体中文目录,相应文件不存在,则复制。反之,跳过已有。
22+
"""
23+
zh_cn_all_files = findAllFile(zh_cn_dir)
24+
25+
# 同步至英文目录
26+
for i in zh_cn_all_files:
27+
relative_path = i.replace(zh_cn_dir + '/', '')
28+
en_target_path = os.path.join(en_dir,relative_path)
29+
if not os.path.exists(en_target_path):
30+
en_target_dir = os.path.dirname(en_target_path)
31+
if not os.path.exists(en_target_dir):
32+
mkdir_cmd = "mkdir -p {0}".format(en_target_dir)
33+
os.system(mkdir_cmd)
34+
cp_cmd = "cp -pf {0} {1}".format(i,en_target_path)
35+
os.system(cp_cmd)
36+
37+
# 同步至繁体中文目录
38+
for i in zh_cn_all_files:
39+
relative_path = i.replace(zh_cn_dir + '/', '')
40+
zh_hant_target_path = os.path.join(zh_hant_dir,relative_path)
41+
if not os.path.exists(zh_hant_target_path):
42+
zh_hant_target_dir = os.path.dirname(zh_hant_target_path)
43+
if not os.path.exists(zh_hant_target_dir):
44+
mkdir_cmd = "mkdir -p {0}".format(zh_hant_target_dir)
45+
os.system(mkdir_cmd)
46+
cp_cmd = "cp -pf {0} {1}".format(i,zh_hant_target_path)
47+
os.system(cp_cmd)
48+
49+
50+
if __name__ == "__main__":
51+
sync_all()

0 commit comments

Comments
 (0)