Repository navigation
Expand file tree
/
Copy pathUnusedAssetsCollection.py
More file actions
77 lines (67 loc) · 2.3 KB
/
Copy pathUnusedAssetsCollection.py
File metadata and controls
77 lines (67 loc) · 2.3 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
68
69
70
71
72
73
74
75
76
import uuid
import os
import sys, getopt
def standardPath(line):
line = line.replace('\\', '/').replace(projectName + '/Content', 'Game').replace('Engine/Content', 'Engine')
lastSplit = line.rindex('/')
assetDir = line[:lastSplit + 1]
assetName = line[lastSplit + 1:].split('.')[0]
index = assetDir.find('/Game')
if index != -1:
assetDir = assetDir[index:]
return assetDir + assetName + '.' + assetName
index = assetDir.find('/Engine')
if index != -1:
assetDir = assetDir[index:]
return assetDir + assetName + '.' + assetName
return ''
def writeCollectionFile(fileName, assetList):
with open(fileName, 'w') as collectionFile:
collectionFile.write('FileVersion:2\n')
collectionFile.write('Type:Static\n')
collectionFile.write('Guid:' + str(uuid.uuid1()) + '\n')
collectionFile.write('ParentGuid:00000000-0000-0000-0000-000000000000\n')
collectionFile.write('\n')
for asset in assetList:
collectionFile.write(asset + '\n')
projectPath = ''
cookLogPath = ''
opts, args = getopt.getopt(sys.argv[1:], '', ['projectPath=', 'cookLogPath='])
for o, a in opts:
if o == '--projectPath':
projectPath = os.path.abspath(a)
if not os.path.isdir(projectPath):
print('project path not exist', projectPath)
exit()
projectName = os.path.basename(projectPath)
projectContentPath = projectPath + '\\Content'
projectCollectionPath = projectContentPath + '\\Collections'
elif o == '--cookLogPath':
cookLogPath = os.path.abspath(a)
if not os.path.exists(cookLogPath):
print('cook log file not exist', cookLogPath)
exit()
if projectPath == '' or cookLogPath == '':
text = """
--projectPath:
--cookLogPath: CookerOpenOrder.log
"""
print(text)
exit()
# used assets
usedAssets = set()
with open(cookLogPath, 'r') as cookLog:
for line in cookLog:
asset = standardPath(line.split(' ')[0][1:-1])
if asset != '' and asset.startswith('/Game'):
usedAssets.add(asset)
writeCollectionFile(projectCollectionPath + '\\Used.collection', usedAssets)
# unUsed assets
allAssets = set()
for root, dirs, files in os.walk(projectContentPath):
for line in files:
asset = standardPath(os.path.join(root, line))
if asset != '' and asset.startswith('/Game'):
allAssets.add(asset)
unUsedAssets = allAssets.difference(usedAssets)
writeCollectionFile(projectCollectionPath + '\\UnUsed.collection', unUsedAssets)