-
Notifications
You must be signed in to change notification settings - Fork 57
/
sync.py
51 lines (43 loc) · 1.73 KB
/
sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import sys
import shutil
# 当前目录
current_dir = os.path.dirname(__file__)
zh_cn_dir = os.path.join(current_dir, "zh-cn")
en_dir = os.path.join(current_dir, "en")
zh_hant_dir = os.path.join(current_dir, "zh-hant")
def findAllFile(base):
for root, ds, fs in os.walk(base):
for f in fs:
fullname = os.path.join(root, f)
yield fullname
def sync_all():
"""遍历中文目录, 如果英文目录/繁体中文目录,相应文件不存在,则复制。反之,跳过已有。
"""
zh_cn_all_files = findAllFile(zh_cn_dir)
# 同步至英文目录
for i in zh_cn_all_files:
relative_path = i.replace(zh_cn_dir + '/', '')
en_target_path = os.path.join(en_dir,relative_path)
if not os.path.exists(en_target_path):
en_target_dir = os.path.dirname(en_target_path)
if not os.path.exists(en_target_dir):
mkdir_cmd = "mkdir -p {0}".format(en_target_dir)
os.system(mkdir_cmd)
cp_cmd = "cp -pf {0} {1}".format(i,en_target_path)
os.system(cp_cmd)
# 同步至繁体中文目录
for i in zh_cn_all_files:
relative_path = i.replace(zh_cn_dir + '/', '')
zh_hant_target_path = os.path.join(zh_hant_dir,relative_path)
if not os.path.exists(zh_hant_target_path):
zh_hant_target_dir = os.path.dirname(zh_hant_target_path)
if not os.path.exists(zh_hant_target_dir):
mkdir_cmd = "mkdir -p {0}".format(zh_hant_target_dir)
os.system(mkdir_cmd)
cp_cmd = "cp -pf {0} {1}".format(i,zh_hant_target_path)
os.system(cp_cmd)
if __name__ == "__main__":
sync_all()