4 # \brief Upload data to servers
5 # \date 2009-02-18 16:19GMT
6 # \author Jan Boon (Kaetemi)
7 # Game data build pipeline.
8 # Upload data to servers
10 # NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
11 # Copyright (C) 2011 Kaetemi
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_local
import *
40 # Not documenting this. Because we can.
41 printLog(log
, "ERROR Upload not configured, bye.")
44 sys
.path
.append(WorkspaceDirectory
)
45 from projects
import *
49 printLog(log
, "-------")
50 printLog(log
, "--- Upload data to servers")
51 printLog(log
, "-------")
52 printLog(log
, time
.strftime("%Y-%m-%d %H:%MGMT", time
.gmtime(time
.time())))
56 # Not documenting this. Because we can.
57 Psftp
= findFileMultiDir(log
, ToolDirectories
+ WindowsExeDllCfgDirectories
, UploadPsftpTool
)
58 printLog(log
, "PSFTP " + Psftp
)
60 def downloadVersionTag(server
, user
, sshkey
, dir):
61 if os
.path
.isfile("upload.tag"):
62 os
.remove("upload.tag")
63 if os
.path
.isfile("upload.batch"):
64 os
.remove("upload.batch")
65 ub
= open("upload.batch", "w")
66 ub
.write("cd " + dir + "\n")
67 ub
.write("get upload.tag upload.tag\n")
70 subprocess
.call([ Psftp
, "-b", "upload.batch", "-i", sshkey
, user
+ "@" + server
])
71 os
.remove("upload.batch")
72 if os
.path
.isfile("upload.tag"):
73 ft
= open("upload.tag")
74 result
= float(ft
.read()) # float, really
76 os
.remove("upload.tag")
77 printLog(log
, "INFO Upload tag is " + str(result
))
80 printLog(log
, "WARNING Upload tag not found, uploading everything")
83 def isDirectoryNeeded(ft
, dir):
84 files
= os
.listdir(dir)
85 for fileName
in files
:
86 if isLegalFileName(fileName
):
87 fileFull
= dir + "/" + fileName
88 if os
.path
.isfile(fileFull
):
89 nftf
= os
.stat(fileFull
).st_mtime
92 elif os
.path
.isdir(fileFull
):
93 if isDirectoryNeeded(ft
, fileFull
):
95 elif not os
.path
.isdir(fileFull
):
96 printLog(log
, "isDirectoryNeeded: file not dir or file?!" + fileFull
)
99 def listDirectoryUpload(ft
, ub
, udb
, dir):
101 files
= os
.listdir(dir)
102 for fileName
in files
:
103 if isLegalFileName(fileName
):
104 fileFull
= dir + "/" + fileName
105 if os
.path
.isfile(fileFull
):
106 nftf
= os
.stat(fileFull
).st_mtime
108 ub
.write("put " + fileFull
+ " " + fileName
+ "\n")
111 elif os
.path
.isdir(fileFull
):
112 if isDirectoryNeeded(ft
, fileFull
):
113 udb
.write("mkdir " + fileName
+ "\n")
114 ub
.write("cd " + fileName
+ "\n")
115 udb
.write("cd " + fileName
+ "\n")
116 nft2
= listDirectoryUpload(ft
, ub
, udb
, fileFull
)
121 elif not os
.path
.isdir(fileFull
):
122 printLog(log
, "listDirectoryUpload: file not dir or file?!" + fileFull
)
125 def uploadSftp(server
, user
, sshkey
, dir_to
, dir_from
, addcmd
):
126 ft
= downloadVersionTag(server
, user
, sshkey
, dir_to
)
127 if isDirectoryNeeded(ft
, dir_from
):
128 if os
.path
.isfile("upload_dir.batch"):
129 os
.remove("upload_dir.batch")
130 if os
.path
.isfile("upload.batch"):
131 os
.remove("upload.batch")
132 udb
= open("upload_dir.batch", "w")
133 udb
.write("cd " + dir_to
+ "\n")
134 ub
= open("upload.batch", "w")
135 ub
.write("cd " + dir_to
+ "\n")
138 ftn
= listDirectoryUpload(ft
, ub
, udb
, dir_from
)
141 nft
= open("upload.tag", "w")
144 ub
.write("put upload.tag upload.tag\n")
149 subprocess
.call([ Psftp
, "-be", "-b", "upload_dir.batch", "-i", sshkey
, user
+ "@" + server
])
150 subprocess
.call([ Psftp
, "-b", "upload.batch", "-i", sshkey
, user
+ "@" + server
])
151 os
.remove("upload_dir.batch")
152 os
.remove("upload.batch")
153 os
.remove("upload.tag")
155 printLog(log
, "SKIP " + dir_to
)
157 printLog(log
, ">>> Upload patch <<<")
158 for target
in UploadPatch
:
159 uploadSftp(target
[0], target
[1], target
[2], target
[3], ClientPatchDirectory
+ "/patch", [ ])
161 printLog(log
, ">>> Upload data_shard <<<")
162 for target
in UploadShard
:
163 uploadSftp(target
[0], target
[1], target
[2], target
[3], DataShardDirectory
, [ "rm *.packed_sheets", "rm primitive_cache/*.binprim" ])
165 printLog(log
, ">>> Upload data_common <<<")
166 for target
in UploadCommon
:
167 uploadSftp(target
[0], target
[1], target
[2], target
[3], DataCommonDirectory
, [ ])
169 printLog(log
, ">>> Upload data_leveldesign/leveldesign <<<")
170 for target
in UploadLeveldesign
:
171 uploadSftp(target
[0], target
[1], target
[2], target
[3], LeveldesignDirectory
, [ ])
173 printLog(log
, ">>> Upload data_leveldesign/primitives <<<")
174 for target
in UploadPrimitives
:
175 uploadSftp(target
[0], target
[1], target
[2], target
[3], PrimitivesDirectory
, [ ])
178 if os
.path
.isfile("9_upload.log"):
179 os
.remove("9_upload.log")
180 shutil
.copy("log.log", time
.strftime("%Y-%m-%d-%H-%M-GMT", time
.gmtime(time
.time())) + "_upload.log")
181 shutil
.move("log.log", "9_upload.log")