forked from tangziwen/CubeMiniGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoShipping.py
More file actions
88 lines (74 loc) · 2.94 KB
/
Copy pathDoShipping.py
File metadata and controls
88 lines (74 loc) · 2.94 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
77
78
79
80
81
82
83
84
85
86
87
88
import zipfile as zipfile
import os
def IsPathValid(path, ignoreDir, ignoreExt):
splited = None
if os.path.isfile(path):
if ignoreExt:
_, ext = os.path.splitext(path)
if ext in ignoreExt:
return False
splited = os.path.dirname(path).split('\\/')
else:
if not ignoreDir:
return True
splited = path.split('\\/')
for s in splited:
if s in ignoreDir: # You can also use set.intersection or [x for],
return False
return True
def zipDirHelper(path, rootDir, zf, ignoreDir = [], ignoreExt = []):
# zf is zipfile handle
if os.path.isfile(path):
if IsPathValid(path, ignoreDir, ignoreExt):
relative = os.path.relpath(path, rootDir)
zf.write(path, relative)
return
ls = os.listdir(path)
for subFileOrDir in ls:
if not IsPathValid(subFileOrDir, ignoreDir, ignoreExt):
continue
joinedPath = os.path.join(path, subFileOrDir)
zipDirHelper(joinedPath, rootDir, zf, ignoreDir, ignoreExt)
def ZipDir(path, zf, ignoreDir = [], ignoreExt = []):
rootDir = path if os.path.isdir(path) else os.path.dirname(path)
zipDirHelper(path, rootDir, zf, ignoreDir, ignoreExt)
pass
to_exclude = ["./Asset/ArtDev", ]
#ignores excluded directories and .exe files
def get_ignored(path, filenames):
ret = []
for filename in filenames:
theFilePath = os.path.join(path, filename)
filePathAbs = os.path.abspath(theFilePath)
for excludeDir in to_exclude:
excludeDirAbs = os.path.abspath(excludeDir)
if excludeDirAbs in filePathAbs:
print("exclude")
ret.append(filename)
return ret
from wand.image import Image
import os
import shutil
shutil.copytree("./Asset/", "./Asset_cook/", ignore = get_ignored)
#convert to dds
g = os.walk("./Asset_cook/")
for path,directories,filelist in g:
directories[:] = [d for d in directories if d not in ['UITexture']]#ignore UI Texture
for filename in filelist:
theFilePath = os.path.join(path, filename)
if os.path.splitext(theFilePath)[1] in (".png",".PNG", ".tga", ".TGA", ".jpg", ".JPG", ".bmp", ".BMP"):
print("cook texture",theFilePath)
os.system("texconv.exe -f DXT5 -vflip -keepcoverage 0.5 -nologo -o "+os.path.dirname(theFilePath) + " \""+ theFilePath + "\"")
os.remove(theFilePath)
# with Image(filename= theFilePath) as img:
# img.flip()
# img.save(filename=os.path.splitext(theFilePath)[0]+'.dds')
# #remove Old one
# os.remove(theFilePath)
print("packing..")
theZipFile = zipfile.ZipFile("./asset.pkg", 'w', compression=zipfile.ZIP_DEFLATED)
ZipDir("./Asset_cook", theZipFile, ignoreDir=["ArtDev"], ignoreExt=[".zip"])
#remove cooked file
print("clean up")
shutil.rmtree("./Asset_cook/", ignore_errors=False, onerror=None)
print ("done.")