-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
67 lines (51 loc) · 2.24 KB
/
build.py
File metadata and controls
67 lines (51 loc) · 2.24 KB
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
import sys
import os
import shutil
# 把资源文件夹里的资源按照是否相等复制一份到输出目录
def copyFiles(resourcePath: str, dirName: str, outputPath: str):
fileList = []
totalFiles = 0
for root, dirs, files in os.walk(resourcePath):
for file in files:
filePath = os.path.join(root, file)
targetPath = os.path.join(
outputPath, filePath.replace(resourcePath, dirName))
totalFiles = totalFiles + 1
if not os.path.exists(targetPath):
fileList.append((filePath, targetPath))
continue
# 如果文件与目标文件不同,也要复制过去
with open(filePath, 'rb') as fsrc:
with open(targetPath, 'rb') as ftarget:
if fsrc.read() != ftarget.read():
fileList.append((filePath, targetPath))
for src, dest in fileList:
os.makedirs(os.path.dirname(dest), exist_ok=True)
shutil.copy(src, dest)
print('Copying {}'.format(dest))
print('{} out of {} files are copied to output directory'.format(
len(fileList), totalFiles))
return fileList
def main():
# 检查输入的路径是否合法
if len(sys.argv) != 3:
print('Usage: ./build.py <Resources_Dir> <Output_Dir>')
return
print('Parameter List: [' + ', '.join(sys.argv) + ']')
resourcePath, outputPath = sys.argv[1], sys.argv[2]
resDirectoryName = resourcePath[str.rfind(resourcePath, '/') + 1:]
if not os.path.exists(resourcePath):
print('Cannot find resource: {}'.format(resourcePath))
return
if not os.path.exists(outputPath):
print('Cannot find output directory: {}'.format(outputPath))
return
# 绝对路径转相对路径
resourcePath, outputPath = os.path.relpath(
resourcePath), os.path.relpath(outputPath)
fileList = copyFiles(
resourcePath, resDirectoryName, outputPath)
if __name__ == '__main__':
print('\n************************************* Executing Resources-copy Script *************************************\n')
main()
print('\n************************************* Finished Resources-copy Script **************************************\n')