5 # \date 2009-03-10 13:13GMT
6 # \author Jan Boon (Kaetemi)
7 # Python port of game data build pipeline.
10 # NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
11 # Copyright (C) 2009-2014 by authors
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Affero General Public License as
15 # published by the Free Software Foundation, either version 3 of the
16 # License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Affero General Public License for more details.
23 # You should have received a copy of the GNU Affero General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 import time
, sys
, os
, shutil
, subprocess
, distutils
.dir_util
28 sys
.path
.append("../../configuration")
30 if os
.path
.isfile("log.log"):
32 log
= open("log.log", "w")
34 from buildsite
import *
37 from directories
import *
40 printLog(log
, "-------")
41 printLog(log
, "--- Build map")
42 printLog(log
, "-------")
43 printLog(log
, time
.strftime("%Y-%m-%d %H:%MGMT", time
.gmtime(time
.time())))
47 TgaToDds
= findTool(log
, ToolDirectories
, TgaToDdsTool
, ToolSuffix
)
48 ExecTimeout
= findTool(log
, ToolDirectories
, ExecTimeoutTool
, ToolSuffix
)
49 PanoplyMaker
= findTool(log
, ToolDirectories
, PanoplyMakerTool
, ToolSuffix
)
50 HlsBankMaker
= findTool(log
, ToolDirectories
, HlsBankMakerTool
, ToolSuffix
)
53 buildPanoplyTagPath
= ExportBuildDirectory
+ "/" + MapTagBuildDirectory
+ "/build_panoply.tag"
54 buildCompressTagPath
= ExportBuildDirectory
+ "/" + MapTagBuildDirectory
+ "/build_compress.tag"
56 if MapPanoplyFileList
!= None:
57 printLog(log
, ">>> Panoply build <<<")
58 mkPath(log
, ExportBuildDirectory
+ "/" + MapTagBuildDirectory
)
59 directoriesCheck
= [ ]
60 for panoplyCfg
in MapPanoplySourceDirectories
:
61 directoriesCheck
+= [ panoplyCfg
[2] ]
62 directoriesCheck
+= [ panoplyCfg
[3] ]
63 if (needUpdateMultiDirNoSubdirFile(log
, DatabaseDirectory
, directoriesCheck
, buildPanoplyTagPath
)):
64 mkPath(log
, ActiveProjectDirectory
+ "/generated")
65 mkPath(log
, ExportBuildDirectory
+ "/" + MapPanoplyBuildDirectory
)
66 mkPath(log
, ExportBuildDirectory
+ "/" + MapPanoplyHlsInfoBuildDirectory
)
67 mkPath(log
, ExportBuildDirectory
+ "/" + MapPanoplyCacheBuildDirectory
)
69 printLog(log
, ">>> Move panoply and hls to cache <<<")
70 removeFilesDirsRecursive(log
, ExportBuildDirectory
+ "/" + MapPanoplyCacheBuildDirectory
)
71 moveDir(log
, ExportBuildDirectory
+ "/" + MapPanoplyBuildDirectory
, ExportBuildDirectory
+ "/" + MapPanoplyCacheBuildDirectory
)
72 mkPath(log
, ExportBuildDirectory
+ "/" + MapPanoplyBuildDirectory
)
73 moveFilesNoSubdir(log
, ExportBuildDirectory
+ "/" + MapPanoplyHlsInfoBuildDirectory
, ExportBuildDirectory
+ "/" + MapPanoplyCacheBuildDirectory
)
75 for panoplyCfg
in MapPanoplySourceDirectories
:
76 printLog(log
, ">>> Panoply " + panoplyCfg
[1] + " <<<")
77 mkPath(log
, DatabaseDirectory
+ "/" + panoplyCfg
[2])
78 mkPath(log
, DatabaseDirectory
+ "/" + panoplyCfg
[3])
79 cfg
= open(ActiveProjectDirectory
+ "/generated/current_panoply.cfg", "w")
80 cfgCommon
= open(ActiveProjectDirectory
+ "/" + panoplyCfg
[0], "r")
81 cfgRace
= open(ActiveProjectDirectory
+ "/" + panoplyCfg
[1], "r")
83 cfg
.write("// CURRENT PANOPLY CONFIGURATION\n")
85 cfg
.write("input_path = \"" + DatabaseDirectory
+ "/" + panoplyCfg
[2] + "\";\n")
86 cfg
.write("additionnal_paths = \"" + DatabaseDirectory
+ "/" + panoplyCfg
[3] + "\";\n")
87 cfg
.write("output_path = \"" + ExportBuildDirectory
+ "/" + MapPanoplyBuildDirectory
+ "\";\n")
88 cfg
.write("hls_info_path = \"" + ExportBuildDirectory
+ "/" + MapPanoplyHlsInfoBuildDirectory
+ "\";\n")
89 cfg
.write("cache_path = \"" + ExportBuildDirectory
+ "/" + MapPanoplyCacheBuildDirectory
+ "\";\n")
91 cfg
.write("/////////////////////////////////////////////\n")
93 for line
in cfgCommon
:
100 subprocess
.call([ PanoplyMaker
, ActiveProjectDirectory
+ "/generated/current_panoply.cfg" ])
102 tagFile
= open(buildPanoplyTagPath
, "w")
103 tagFile
.write(time
.strftime("%Y-%m-%d %H:%MGMT", time
.gmtime(time
.time())) + "\n")
106 printLog(log
, "SKIP *.*")
109 printLog(log
, ">>> Compress TGA and PNG maps to DDS <<<")
111 toolLogFail(log
, TgaToDdsTool
, ToolSuffix
)
112 elif ExecTimeout
== "":
113 toolLogFail(log
, ExecTimeoutTool
, ToolSuffix
)
115 destPath
= ExportBuildDirectory
+ "/" + MapBuildDirectory
116 mkPath(log
, destPath
)
117 sourcePaths
= [ ExportBuildDirectory
+ "/" + MapExportDirectory
]
119 if MapPanoplyFileList
!= None:
120 if needUpdate(log
, buildPanoplyTagPath
, buildCompressTagPath
):
121 sourcePaths
+= [ ExportBuildDirectory
+ "/" + MapPanoplyBuildDirectory
]
123 printLog(log
, "SKIP " + ExportBuildDirectory
+ "/" + MapPanoplyBuildDirectory
+ "/*.*")
124 for sourcePath
in sourcePaths
:
125 mkPath(log
, sourcePath
)
126 files
= os
.listdir(sourcePath
)
127 len_tga_png
= len(".tga")
128 len_dds
= len(".dds")
129 for fileName
in files
:
130 if isLegalFileName(fileName
):
131 sourceFile
= sourcePath
+ "/" + fileName
132 if os
.path
.isfile(sourceFile
):
133 if (fileName
[-len_tga_png
:].lower() == ".tga") or (fileName
[-len_tga_png
:].lower() == ".png"):
134 destFile
= destPath
+ "/" + os
.path
.basename(fileName
)[0:-len_tga_png
] + ".dds"
135 if needUpdateLogRemoveDest(log
, sourceFile
, destFile
):
136 subprocess
.call([ ExecTimeout
, str(MapsBuildTimeout
), TgaToDds
, sourceFile
, "-o", destFile
, "-m", "-r" + str(ReduceBitmapFactor
) ])
138 elif fileName
[-len_dds
:].lower() == ".dds":
139 copyFileIfNeeded(log
, sourceFile
, destPath
+ "/" + os
.path
.basename(fileName
))
141 elif not os
.path
.isdir(sourceFile
):
142 printLog(log
, "FAIL ?! file not dir or file ?! " + sourceFile
)
144 tagFile
= open(buildCompressTagPath
, "w")
145 tagFile
.write(time
.strftime("%Y-%m-%d %H:%MGMT", time
.gmtime(time
.time())) + "\n")
149 if MapHlsBankFileName
!= None:
150 printLog(log
, ">>> Build the HLSBank <<<")
151 if HlsBankMaker
== "":
152 toolLogFail(log
, HlsBankMakerTool
, ToolSuffix
)
154 mkPath(log
, ExportBuildDirectory
+ "/" + MapPanoplyHlsInfoBuildDirectory
)
155 mkPath(log
, ExportBuildDirectory
+ "/" + MapPanoplyHlsBankBuildDirectory
)
156 hlsBankPath
= ExportBuildDirectory
+ "/" + MapPanoplyHlsBankBuildDirectory
+ "/" + MapHlsBankFileName
157 if (needUpdate(log
, buildPanoplyTagPath
, hlsBankPath
) or needUpdate(log
, buildCompressTagPath
, hlsBankPath
)):
158 if os
.path
.isfile(hlsBankPath
):
159 os
.remove(hlsBankPath
)
160 subprocess
.call([ HlsBankMaker
, ExportBuildDirectory
+ "/" + MapPanoplyHlsInfoBuildDirectory
, hlsBankPath
])
162 printLog(log
,"SKIP " + hlsBankPath
)