-
Notifications
You must be signed in to change notification settings - Fork 403
/
Copy pathgen_filelist.py
149 lines (133 loc) · 3.89 KB
/
gen_filelist.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! python3
# coding=utf-8
"""
Author: zhaoqingqing([email protected])
Date: 2019/11/23 19:26
Desc: 1.遍历当前目录下的所有文件生成filelist
格式:filepath,版本号,文件大小
2.生成version.txt到Product目录
在python3.7.4+win10下测试通过
"""
import hashlib
import os
import shutil
import sys
import time
import gen_hotfix_res
filelist_name = 'filelist.txt'
version_name = 'version.txt'
dst_path = "" # 目标路径
def isIgnore(name):
if name.endswith(".py"):
return True
if name.endswith(".bat"):
return True
# if name.endswith(".manifest"):
# return True
if name.endswith(".py"):
return True
if name.endswith(".meta"):
return True
bname = os.path.basename(name)
if bname == "Windows" or bname == "Android" or bname == "iOS":
# manifest同名文件
return False
if bname.find(".") < 0:
return True
if bname.startswith("."):
return True
if bname.startswith("filelist"):
return True
if bname.startswith("version"):
return True
return False
def GetFileMd5(filename):
if not os.path.isfile(filename):
return
myhash = hashlib.md5()
f = open(filename, 'rb')
# 分段读取文件并计算md5,对大文件友好
while True:
b = f.read(8096)
if not b:
break
myhash.update(b)
f.close()
return myhash.hexdigest()
def makeFileLists(dir, save_path):
'''
makeFileList 函数用于包含多层目录的文件列表创建
Params:
dir :最上层的目录路径
Usage:
makeFileLists('dir')
'''
# 判断路径是否存在
if not os.path.exists(dir):
print(dir, ',目录不存在,请检查')
return
new_str = ""
for fpathe, dirs, fs in os.walk(os.path.abspath(os.path.dirname(dst_path))):
for f in fs:
path_name = os.path.join(fpathe, f)
if not isIgnore(path_name):
sname = path_name.replace(dir, "").replace("\\","/")
version = GetFileMd5(path_name)
size = str(os.path.getsize(path_name));
line = "{0},{1},{2}".format(sname, version, size)
new_str = new_str + line + "\n"
# print("find:" ,line)
# 生成filelist
old_str = ""
if not os.path.exists(bak_filelist):
with open(save_path, 'w', encoding='utf8') as fw:
fw.write(new_str)
fw.flush()
print("filelist生成完成")
else:
sw = os.path.isfile(bak_filelist) and open(bak_filelist, 'r')
if sw:
old_str = sw.read()
sw.close()
if new_str == old_str and os.path.exists(save_path):
print("filelist无需更新")
else:
sw = open(save_path, "w")
sw.write(new_str)
sw.close()
print("filelist有更新,生成完成")
if __name__ == "__main__":
try:
print("参数列表:", str(sys.argv))
# 未传入参数则使用脚本所在路径的相对路径
dir_name = os.getcwd()
dst_path = dir_name +"\..\KSFramework\Product\Bundles\Windows\\"
bak_path = dir_name
platform = "Windows"
if (len(sys.argv) >= 3):
dst_path = sys.argv[1]
bak_path = sys.argv[2]
platform = sys.argv[3]
print ("use args to set path.")
dir = os.path.abspath(os.path.dirname(dst_path)) + "\\"
bak_dir = os.path.abspath(os.path.dirname(bak_path)) + "\\"
bak_filelist = bak_dir + filelist_name + '.bak'
if os.path.exists(dir + filelist_name):
shutil.copyfile(dir + filelist_name, bak_filelist)
print("备份filelist文件:", bak_filelist)
print("要生成filelist的目录为:", dir)
makeFileLists(dir, dir + filelist_name)
# 生成version.txt 1.生成zip 2.写入version.txt 3.删除zip
product_dir = dir + '../../'
gen_hotfix_res.zip_dir(product_dir + "Lua", product_dir + "lua.zip", False)
gen_hotfix_res.zip_dir(product_dir + "Setting", product_dir + "setting.zip", False)
ver_list = [product_dir + "lua.zip", product_dir + "setting.zip", dir + filelist_name]
gen_hotfix_res.genVersion(product_dir + platform + "-" + version_name, ver_list)
os.remove(product_dir + "lua.zip")
os.remove(product_dir + "setting.zip")
except Exception as ex:
print
'Exception:\r\n'
print
ex
os.system("pause")