3 # \file d1_client_patch.py
4 # \brief Install to client patch
5 # \date 2009-02-18 16:19GMT
6 # \author Jan Boon (Kaetemi)
7 # Python port of game data build pipeline.
8 # Install to client patch
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
, argparse
28 sys
.path
.append("configuration")
30 parser
= argparse
.ArgumentParser(description
='Ryzom Core - Build Gamedata - Client Patch')
31 parser
.add_argument('--bnponly', '-bo', action
='store_true')
32 args
= parser
.parse_args()
34 if os
.path
.isfile("log.log"):
36 log
= open("log.log", "w")
38 from buildsite
import *
41 sys
.path
.append(WorkspaceDirectory
)
42 from projects
import *
46 printLog(log
, "-------")
47 printLog(log
, "--- Install to client patch")
48 printLog(log
, "-------")
49 printLog(log
, time
.strftime("%Y-%m-%d %H:%MGMT", time
.gmtime(time
.time())))
53 BnpMake
= findTool(log
, ToolDirectories
, BnpMakeTool
, ToolSuffix
)
54 SnpMake
= findTool(log
, ToolDirectories
, SnpMakeTool
, ToolSuffix
);
55 PatchGen
= findTool(log
, ToolDirectories
, PatchGenTool
, ToolSuffix
)
58 # Find **** HARDCODED **** WINDOWS **** tools ... TODO: fix patch_gen tool !!!
59 Lzma
= findFileMultiDir(log
, ToolDirectories
+ WindowsExeDllCfgDirectories
, "lzma.exe")
60 printLog(log
, "LZMA " + Lzma
)
61 XDelta
= findFileMultiDir(log
, ToolDirectories
+ WindowsExeDllCfgDirectories
, "xdelta.exe")
62 printLog(log
, "XDELTA " + XDelta
)
66 toolLogFail(log
, BnpMakeTool
, ToolSuffix
)
67 elif PatchGen
== "" and not args
.bnponly
:
68 toolLogFail(log
, PatchGenTool
, ToolSuffix
)
69 elif Lzma
== "" and not args
.bnponly
:
70 toolLogFail(log
, "LZMA", ToolSuffix
)
71 elif XDelta
== "" and not args
.bnponly
:
72 toolLogFail(log
, "XDELTA", ToolSuffix
)
73 elif os
.path
.dirname(Lzma
) != os
.path
.dirname(XDelta
):
74 printLog(log
, "FAIL lzma.exe and xdelta.exe must be in the same directory")
76 mkPath(log
, ClientPatchDirectory
)
78 productXml
= ClientPatchDirectory
+ "/" + ProductName
+ ".xml"
79 if not os
.path
.isfile(productXml
):
80 printLog(log
, ">>> Create new product <<<")
81 subprocess
.call([ PatchGen
, "createNewProduct", productXml
])
83 printLog(log
, ">>> Rewrite " + ProductName
+ ".xml <<<") # because we know better.
84 shutil
.move(productXml
, productXml
+ ".old")
85 oldCfg
= open(productXml
+ ".old", "r")
86 cfg
= open(productXml
, "w")
90 if line
.strip() == "<_Categories>":
92 cfg
.write("\t<_Categories>\n")
93 for category
in InstallClientData
:
95 if (category
["StreamedPackages"]):
97 cfg
.write("\t\t<_Category>\n")
98 cfg
.write("\t\t\t<_Name type=\"STRING\" value=\"" + category
["Name"] + "\"/>\n")
99 if category
["UnpackTo"] != None:
100 if category
["UnpackTo"] != "":
101 cfg
.write("\t\t\t<_UnpackTo type=\"STRING\" value=\"./" + category
["UnpackTo"] + "/\"/>\n")
103 cfg
.write("\t\t\t<_UnpackTo type=\"STRING\" value=\"./\"/>\n")
104 cfg
.write("\t\t\t<_IsOptional type=\"SINT32\" value=\"" + str(category
["IsOptional"]) + "\"/>\n")
105 cfg
.write("\t\t\t<_IsIncremental type=\"SINT32\" value=\"" + str(category
["IsIncremental"]) + "\"/>\n")
106 for package
in category
["Packages"]:
107 if (len(package
[1]) > 0):
108 cfg
.write("\t\t\t<_Files type=\"STRING\" value=\"" + package
[1][0] + "\"/>\n")
110 cfg
.write("\t\t\t<_Files type=\"STRING\" value=\"" + package
[0] + packExt
+ "\"/>\n")
111 for ref
in category
["Refs"]:
112 cfg
.write("\t\t\t<_Files type=\"STRING\" value=\"" + ref
+ "_.ref\"/>\n")
113 cfg
.write("\t\t</_Category>\n")
114 cfg
.write("\t</_Categories>\n")
118 if line
.strip() == "</_Categories>":
122 os
.remove(productXml
+ ".old")
124 printLog(log
, ">>> Make bnp <<<")
125 targetPath
= ClientPatchDirectory
+ "/bnp"
126 tagPath
= ClientPatchDirectory
+ "/bnp_tag"
127 mkPath(log
, targetPath
)
129 for category
in InstallClientData
:
131 if (category
["StreamedPackages"]):
133 for package
in category
["Packages"]:
134 printLog(log
, "PACKAGE " + package
[0])
135 sourcePath
= InstallDirectory
+ "/" + package
[0]
136 mkPath(log
, sourcePath
)
137 targetBnp
= targetPath
+ "/" + package
[0] + packExt
138 tagBnp
= tagPath
+ "/" + package
[0] + packExt
+ ".tag"
139 if (len(package
[1]) > 0):
140 targetBnp
= targetPath
+ "/" + package
[1][0]
141 tagBnp
= tagPath
+ "/" + package
[1][0] + ".tag"
142 printLog(log
, "TARGET " + package
[1][0])
144 if (len(package
) > 2):
145 needUpdateBnp
= needUpdate(log
, sourcePath
+ "/" + package
[2], tagBnp
)
147 needUpdateBnp
= needUpdateDirNoSubdirFile(log
, sourcePath
, tagBnp
)
150 open(tagBnp
, 'a').close()
151 os
.utime(tagBnp
, None)
152 if (category
["StreamedPackages"]):
153 printLog(log
, "SNP " + targetBnp
)
154 # cwDir = os.getcwd().replace("\\", "/")
155 # toolDir = os.path.dirname(Lzma).replace("\\", "/")
157 subRet
= subprocess
.call([ SnpMake
, "-p", sourcePath
, targetBnp
, ClientPatchDirectory
+ "/stream" ] + package
[1][1:])
160 printLog(log
, "BNP " + targetBnp
)
161 subRet
= subprocess
.call([ BnpMake
, "-p", sourcePath
, "-o", targetBnp
] + package
[1][1:])
165 printLog(log
, "SKIP " + targetBnp
)
168 printLog(log
, ">>> Update product <<<")
169 cwDir
= os
.getcwd().replace("\\", "/")
170 toolDir
= os
.path
.dirname(Lzma
).replace("\\", "/")
172 subprocess
.call([ PatchGen
, "updateProduct", productXml
])
178 if os
.path
.isfile("d1_client_patch.log"):
179 os
.remove("d1_client_patch.log")
180 shutil
.copy("log.log", time
.strftime("%Y-%m-%d-%H-%M-GMT", time
.gmtime(time
.time())) + "_client_patch.log")
181 shutil
.move("log.log", "d1_client_patch.log")