9
9
current_dir = os .path .dirname (__file__ )
10
10
zh_cn_dir = os .path .join (current_dir , "zh-cn" )
11
11
en_dir = os .path .join (current_dir , "en" )
12
+ zh_hant_dir = os .path .join (current_dir , "zh-hant" )
12
13
13
14
def findAllFile (base ):
14
15
for root , ds , fs in os .walk (base ):
15
16
for f in fs :
16
17
fullname = os .path .join (root , f )
17
18
yield fullname
18
19
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