4 # \brief Useful scripts
5 # \date 2009-02-18 09:22GMT
6 # \author Jan Boon (Kaetemi)
9 # NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
10 # Copyright (C) 2009-2014 by authors
12 # This program is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Affero General Public License as
14 # published by the Free Software Foundation, either version 3 of the
15 # License, or (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Affero General Public License for more details.
22 # You should have received a copy of the GNU Affero General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 import time
, sys
, os
, shutil
, subprocess
, distutils
.dir_util
, multiprocessing
, math
28 ActiveProjectDirectory
= os
.getenv("NELBUILDACTIVEPROJECT", "configuration/project")
29 sys
.path
.append(ActiveProjectDirectory
)
31 def printLog(log
, text
):
32 log
.write(text
+ "\n")
36 processLimit
= math
.ceil(multiprocessing
.cpu_count() * 0.75)
38 def callParallelProcess(command
):
40 if len(pendingProcesses
) >= processLimit
:
41 waitingProc
= pendingProcesses
.pop(0)
42 res
= waitingProc
.wait()
43 proc
= subprocess
.Popen(command
)
44 pendingProcesses
.append(proc
)
47 def flushParallelProcesses():
49 while (len(pendingProcesses
) > 0):
50 waitingProc
= pendingProcesses
.pop(0)
51 procRes
= waitingProc
.wait()
56 def mkPath(log
, path
):
57 printLog(log
, "DIR " + path
)
58 distutils
.dir_util
.mkpath(path
)
60 def needUpdate(log
, source
, dest
):
61 if (os
.path
.isfile(source
)):
62 if (os
.path
.isfile(dest
)):
63 if (os
.stat(source
).st_mtime
> os
.stat(dest
).st_mtime
):
68 printLog(log
, "MISSING " + source
)
71 def needUpdateRemoveDest(log
, source
, dest
):
72 if (os
.path
.isfile(source
)):
73 if (os
.path
.isfile(dest
)):
74 if (os
.stat(source
).st_mtime
> os
.stat(dest
).st_mtime
):
80 printLog(log
, "MISSING " + source
)
83 def needUpdateLogRemoveDest(log
, source
, dest
):
84 if (os
.path
.isfile(source
)):
85 if (os
.path
.isfile(dest
)):
86 if (os
.stat(source
).st_mtime
> os
.stat(dest
).st_mtime
):
88 printLog(log
, source
+ " -> " + dest
)
91 printLog(log
, "SKIP " + dest
)
93 printLog(log
, source
+ " -> " + dest
)
95 printLog(log
, "MISSING " + source
)
96 printLog(log
, "SKIP " + dest
)
99 def copyFileList(log
, dir_source
, dir_target
, files
):
100 for fileName
in files
:
101 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
102 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
103 if needUpdateLogRemoveDest(log
, dir_source
+ "/" + fileName
, dir_target
+ "/" + fileName
):
104 shutil
.copy(dir_source
+ "/" + fileName
, dir_target
+ "/" + fileName
)
106 def copyFileListLogless(log
, dir_source
, dir_target
, files
):
107 for fileName
in files
:
108 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
109 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
110 if needUpdateRemoveDest(log
, dir_source
+ "/" + fileName
, dir_target
+ "/" + fileName
):
111 shutil
.copy(dir_source
+ "/" + fileName
, dir_target
+ "/" + fileName
)
113 def copyFileListNoTree(log
, dir_source
, dir_target
, files
):
114 for fileName
in files
:
115 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
116 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
117 printLog(log
, dir_source
+ "/" + fileName
+ " -> " + dir_target
+ "/" + os
.path
.basename(fileName
))
118 shutil
.copy(dir_source
+ "/" + fileName
, dir_target
+ "/" + os
.path
.basename(fileName
))
120 def copyFileListNoTreeIfNeeded(log
, dir_source
, dir_target
, files
):
121 for fileName
in files
:
122 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
123 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
124 srcFile
= dir_source
+ "/" + fileName
125 destFile
= dir_target
+ "/" + os
.path
.basename(fileName
)
126 if needUpdateLogRemoveDest(log
, srcFile
, destFile
):
127 shutil
.copy(srcFile
, destFile
)
129 def removeFilesRecursive(log
, dir_files
):
130 files
= os
.listdir(dir_files
)
131 for fileName
in files
:
132 if (fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*"):
133 if os
.path
.isdir(dir_files
+ "/" + fileName
):
134 removeFilesRecursive(log
, dir_files
+ "/" + fileName
)
136 printLog(log
, "RM " + dir_files
+ "/" + fileName
)
137 os
.remove(dir_files
+ "/" + fileName
)
139 def removeFilesDirsRecursive(log
, dir_files
):
140 files
= os
.listdir(dir_files
)
141 for fileName
in files
:
142 if (fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*"):
143 if os
.path
.isdir(dir_files
+ "/" + fileName
):
144 removeFilesRecursive(log
, dir_files
+ "/" + fileName
)
146 printLog(log
, "RM " + dir_files
+ "/" + fileName
)
147 os
.remove(dir_files
+ "/" + fileName
)
148 printLog(log
, "RMDIR " + dir_files
)
151 def removeFilesRecursiveExt(log
, dir_files
, file_ext
):
152 files
= os
.listdir(dir_files
)
153 len_file_ext
= len(file_ext
)
154 for fileName
in files
:
155 if (fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*"):
156 if os
.path
.isdir(dir_files
+ "/" + fileName
):
157 removeFilesRecursiveExt(log
, dir_files
+ "/" + fileName
, file_ext
)
158 elif (fileName
[-len_file_ext
:].lower() == file_ext
.lower()):
159 printLog(log
, "RM " + dir_files
+ "/" + fileName
)
160 os
.remove(dir_files
+ "/" + fileName
)
162 def copyFilesRecursive(log
, dir_source
, dir_target
):
163 files
= os
.listdir(dir_source
)
164 mkPath(log
, dir_target
)
165 for fileName
in files
:
166 if (fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*"):
167 if os
.path
.isdir(dir_source
+ "/" + fileName
):
168 copyFilesRecursive(log
, dir_source
+ "/" + fileName
, dir_target
+ "/" + fileName
)
170 printLog(log
, dir_source
+ "/" + fileName
+ " -> " + dir_target
+ "/" + fileName
)
171 shutil
.copy(dir_source
+ "/" + fileName
, dir_target
+ "/" + fileName
)
173 def copyFiles(log
, dir_source
, dir_target
):
174 copyFileList(log
, dir_source
, dir_target
, os
.listdir(dir_source
))
176 def copyFilesLogless(log
, dir_source
, dir_target
):
177 copyFileListLogless(log
, dir_source
, dir_target
, os
.listdir(dir_source
))
179 def copyFilesExt(log
, dir_source
, dir_target
, file_ext
):
180 files
= os
.listdir(dir_source
)
181 len_file_ext
= len(file_ext
)
182 for fileName
in files
:
183 if (fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*") and (fileName
[-len_file_ext
:].lower() == file_ext
.lower()):
184 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
185 printLog(log
, dir_source
+ "/" + fileName
+ " -> " + dir_target
+ "/" + fileName
)
186 shutil
.copy(dir_source
+ "/" + fileName
, dir_target
+ "/" + fileName
)
188 def copyFilesRenamePrefixExt(log
, dir_source
, dir_target
, old_prefix
, new_prefix
, file_ext
):
189 files
= os
.listdir(dir_source
)
190 len_file_ext
= len(file_ext
)
191 len_prefix
= len(old_prefix
)
192 for fileName
in files
:
193 if (fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*") and (fileName
[-len_file_ext
:].lower() == file_ext
.lower()) and ((fileName
[:len_prefix
].lower() == old_prefix
.lower())):
194 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
195 printLog(log
, dir_source
+ "/" + fileName
+ " -> " + dir_target
+ "/" + new_prefix
+ fileName
[-(len(fileName
) - len_prefix
):])
196 shutil
.copy(dir_source
+ "/" + fileName
, dir_target
+ "/" + new_prefix
+ fileName
[-(len(fileName
) - len_prefix
):])
198 def copyFilesExtNoSubdir(log
, dir_source
, dir_target
, file_ext
):
199 files
= findFilesNoSubdir(log
, dir_source
, file_ext
)
200 copyFileListNoTree(log
, dir_source
, dir_target
, files
)
202 def copyFilesExtNoTree(log
, dir_source
, dir_target
, file_ext
):
203 files
= findFiles(log
, dir_source
, "", file_ext
)
204 copyFileListNoTree(log
, dir_source
, dir_target
, files
)
206 def copyFilesExtNoTreeIfNeeded(log
, dir_source
, dir_target
, file_ext
):
207 files
= findFiles(log
, dir_source
, "", file_ext
)
208 copyFileListNoTreeIfNeeded(log
, dir_source
, dir_target
, files
)
210 def copyFilesExtNoSubdirIfNeeded(log
, dir_source
, dir_target
, file_ext
):
211 files
= findFilesNoSubdir(log
, dir_source
, file_ext
)
212 copyFileListNoTreeIfNeeded(log
, dir_source
, dir_target
, files
)
214 def copyFilesNoTreeIfNeeded(log
, dir_source
, dir_target
):
215 copyFileListNoTreeIfNeeded(log
, dir_source
, dir_target
, os
.listdir(dir_source
))
217 def copyFilesRecursiveNoTreeIfNeeded(log
, dir_source
, dir_target
):
218 files
= findFilesRecursive(log
, dir_source
, "")
219 copyFileListNoTreeIfNeeded(log
, dir_source
, dir_target
, files
)
221 def copyFileListExtReplaceNoTreeIfNeeded(log
, dir_source
, dir_target
, files
, file_ext
, target_ext
):
222 for fileName
in files
:
223 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
224 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
225 srcFile
= dir_source
+ "/" + fileName
226 destFile
= dir_target
+ "/" + os
.path
.basename(fileName
)[0:-len(file_ext
)] + target_ext
227 if needUpdateLogRemoveDest(log
, srcFile
, destFile
):
228 shutil
.copy(srcFile
, destFile
)
230 def copyFilesExtReplaceNoTreeIfNeeded(log
, dir_source
, dir_target
, file_ext
, target_ext
):
231 files
= findFiles(log
, dir_source
, "", file_ext
)
232 copyFileListExtReplaceNoTreeIfNeeded(log
, dir_source
, dir_target
, files
, file_ext
, target_ext
)
234 def copyFileIfNeeded(log
, srcFile
, destFile
):
235 if needUpdateLogRemoveDest(log
, srcFile
, destFile
):
236 shutil
.copy(srcFile
, destFile
)
238 def moveFileListNoTree(log
, dir_source
, dir_target
, files
):
239 for fileName
in files
:
240 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
241 if (os
.path
.isfile(dir_source
+ "/" + fileName
)):
242 printLog(log
, "MOVE " + dir_source
+ "/" + fileName
+ " -> " + dir_target
+ "/" + os
.path
.basename(fileName
))
243 shutil
.move(dir_source
+ "/" + fileName
, dir_target
+ "/" + os
.path
.basename(fileName
))
245 def moveFilesExtNoTree(log
, dir_source
, dir_target
, file_ext
):
246 files
= findFiles(log
, dir_source
, "", file_ext
)
247 moveFileListNoTree(log
, dir_source
, dir_target
, files
)
249 def moveFilesNoSubdir(log
, dir_source
, dir_target
):
250 files
= os
.listdir(dir_source
)
251 moveFileListNoTree(log
, dir_source
, dir_target
, files
)
253 def moveDir(log
, dir_source
, dir_target
):
254 printLog(log
, "MOVE " + dir_source
+ " -> " + dir_target
)
255 shutil
.move(dir_source
, dir_target
)
257 def findFilesRecursive(log
, dir_where
, dir_sub
):
259 files
= os
.listdir(dir_where
+ "/" + dir_sub
)
260 for fileName
in files
:
261 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
262 filePath
= dir_sub
+ fileName
263 fileFull
= dir_where
+ "/" + dir_sub
+ fileName
264 if os
.path
.isfile(fileFull
):
265 result
+= [ filePath
]
266 elif os
.path
.isdir(fileFull
):
267 result
+= findFilesRecursive(log
, dir_where
, filePath
+ "/")
269 printLog(log
, "findFilesRecursive: file not dir or file?!" + filePath
)
272 def findFiles(log
, dir_where
, dir_sub
, file_ext
):
274 files
= os
.listdir(dir_where
+ "/" + dir_sub
)
275 len_file_ext
= len(file_ext
)
276 for fileName
in files
:
277 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
278 filePath
= dir_sub
+ fileName
279 fileFull
= dir_where
+ "/" + dir_sub
+ fileName
280 if os
.path
.isfile(fileFull
):
281 if fileName
[-len_file_ext
:].lower() == file_ext
.lower():
282 result
+= [ filePath
]
283 elif os
.path
.isdir(fileFull
):
284 result
+= findFiles(log
, dir_where
, filePath
+ "/", file_ext
)
286 printLog(log
, "findFiles: file not dir or file?!" + filePath
)
289 def isLegalFileName(fileName
):
290 return fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*"
292 def findFilesNoSubdir(log
, dir_where
, file_ext
):
294 files
= os
.listdir(dir_where
)
295 len_file_ext
= len(file_ext
)
296 for fileName
in files
:
297 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
298 fileFull
= dir_where
+ "/" + fileName
299 if os
.path
.isfile(fileFull
):
300 if fileName
[-len_file_ext
:].lower() == file_ext
.lower():
301 result
+= [ fileName
]
302 elif not os
.path
.isdir(fileFull
):
303 printLog(log
, "findFilesNoSubdir: file not dir or file?!" + fileFull
)
306 def findFilesNoSubdirFiltered(log
, dir_where
, file_ext
, filter):
308 return findFilesNoSubdir(log
, dir_where
, file_ext
)
310 files
= os
.listdir(dir_where
)
311 len_file_ext
= len(file_ext
)
312 for fileName
in files
:
313 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
314 fileFull
= dir_where
+ "/" + fileName
315 if os
.path
.isfile(fileFull
):
316 if fileName
[-len_file_ext
:].lower() == file_ext
.lower():
317 fileNameLower
= fileName
.lower()
318 for filterWord
in filter:
319 if filterWord
in fileNameLower
:
320 result
+= [ fileName
]
322 elif not os
.path
.isdir(fileFull
):
323 printLog(log
, "findFilesNoSubdir: file not dir or file?!" + fileFull
)
326 def findFile(log
, dir_where
, file_name
):
327 files
= os
.listdir(dir_where
)
328 for fileName
in files
:
329 if fileName
!= ".svn" and fileName
!= ".." and fileName
!= "." and fileName
!= "*.*":
330 filePath
= dir_where
+ "/" + fileName
331 if os
.path
.isfile(filePath
):
332 if fileName
== file_name
:
334 elif os
.path
.isdir(filePath
):
335 result
= findFile(log
, filePath
, file_name
)
339 printLog(log
, "findFile: file not dir or file?! " + filePath
)
342 def needUpdateDirByLowercaseTagLog(log
, dir_source
, ext_source
, dir_dest
, ext_dest
):
345 lenSrcExt
= len(ext_source
)
346 sourceFiles
= findFilesNoSubdir(log
, dir_source
, ext_source
)
347 destFiles
= findFilesNoSubdir(log
, dir_dest
, ext_dest
)
348 for file in sourceFiles
:
349 sourceFile
= dir_source
+ "/" + file
350 tagFile
= dir_dest
+ "/" + file[0:-lenSrcExt
].lower() + ext_dest
351 if os
.path
.isfile(tagFile
):
352 sourceTime
= os
.stat(sourceFile
).st_mtime
353 tagTime
= os
.stat(tagFile
).st_mtime
354 if (sourceTime
> tagTime
):
355 updateCount
= updateCount
+ 1
357 skipCount
= skipCount
+ 1
359 updateCount
= updateCount
+ 1
361 printLog(log
, "UPDATE " + str(updateCount
) + " / " + str(len(sourceFiles
)) + "; SKIP " + str(skipCount
) + " / " + str(len(sourceFiles
)) + "; DEST " + str(len(destFiles
)))
364 printLog(log
, "SKIP " + str(skipCount
) + " / " + str(len(sourceFiles
)) + "; DEST " + str(len(destFiles
)))
367 def needUpdateDirByTagLogFiltered(log
, dir_source
, ext_source
, dir_dest
, ext_dest
, filter):
370 lenSrcExt
= len(ext_source
)
371 sourceFiles
= findFilesNoSubdirFiltered(log
, dir_source
, ext_source
, filter)
372 destFiles
= findFilesNoSubdir(log
, dir_dest
, ext_dest
)
373 for file in sourceFiles
:
374 sourceFile
= dir_source
+ "/" + file
375 tagFile
= dir_dest
+ "/" + file[0:-lenSrcExt
] + ext_dest
376 if os
.path
.isfile(tagFile
):
377 sourceTime
= os
.stat(sourceFile
).st_mtime
378 tagTime
= os
.stat(tagFile
).st_mtime
379 if (sourceTime
> tagTime
):
380 updateCount
= updateCount
+ 1
382 skipCount
= skipCount
+ 1
384 updateCount
= updateCount
+ 1
386 printLog(log
, "UPDATE " + str(updateCount
) + " / " + str(len(sourceFiles
)) + "; SKIP " + str(skipCount
) + " / " + str(len(sourceFiles
)) + "; DEST " + str(len(destFiles
)))
389 printLog(log
, "SKIP " + str(skipCount
) + " / " + str(len(sourceFiles
)) + "; DEST " + str(len(destFiles
)))
392 def needUpdateDirByTagLog(log
, dir_source
, ext_source
, dir_dest
, ext_dest
):
395 lenSrcExt
= len(ext_source
)
396 sourceFiles
= findFilesNoSubdir(log
, dir_source
, ext_source
)
397 destFiles
= findFilesNoSubdir(log
, dir_dest
, ext_dest
)
398 for file in sourceFiles
:
399 sourceFile
= dir_source
+ "/" + file
400 tagFile
= dir_dest
+ "/" + file[0:-lenSrcExt
] + ext_dest
401 if os
.path
.isfile(tagFile
):
402 sourceTime
= os
.stat(sourceFile
).st_mtime
403 tagTime
= os
.stat(tagFile
).st_mtime
404 if (sourceTime
> tagTime
):
405 updateCount
= updateCount
+ 1
407 skipCount
= skipCount
+ 1
409 updateCount
= updateCount
+ 1
411 printLog(log
, "UPDATE " + str(updateCount
) + " / " + str(len(sourceFiles
)) + "; SKIP " + str(skipCount
) + " / " + str(len(sourceFiles
)) + "; DEST " + str(len(destFiles
)))
414 printLog(log
, "SKIP " + str(skipCount
) + " / " + str(len(sourceFiles
)) + "; DEST " + str(len(destFiles
)))
417 def needUpdateDirNoSubdirFile(log
, dir_source
, file_dest
):
418 if not os
.path
.isfile(file_dest
):
420 destTime
= os
.stat(file_dest
).st_mtime
421 sourceFiles
= os
.listdir(dir_source
)
422 for file in sourceFiles
:
423 filePath
= dir_source
+ "/" + file
424 if os
.path
.isfile(filePath
):
425 fileTime
= os
.stat(filePath
).st_mtime
426 if fileTime
> destTime
:
431 def needUpdateFileDirNoSubdir(log
, file_source
, dir_dest
):
432 if not os
.path
.isfile(file_source
):
433 printLog(log
, "WARNING MISSING " + file_source
)
435 sourceTime
= os
.stat(file_source
).st_mtime
436 destFiles
= os
.listdir(dir_dest
)
437 for file in destFiles
:
438 filePath
= dir_dest
+ "/" + file
439 if os
.path
.isfile(filePath
):
440 fileTime
= os
.stat(filePath
).st_mtime
441 if sourceTime
> fileTime
:
446 def needUpdateDirNoSubdirMultiFile(log
, dir_source
, root_file
, files_dest
):
447 for file_dest
in files_dest
:
448 if needUpdateDirNoSubdirFile(log
, dir_source
, root_file
+ "/" + file_dest
):
452 def needUpdateDirNoSubdirMultiFileExt(log
, dir_source
, root_file
, files_dest
, file_ext
):
453 for file_dest
in files_dest
:
454 if needUpdateDirNoSubdirFile(log
, dir_source
, root_file
+ "/" + file_dest
+ file_ext
):
458 def needUpdateMultiDirNoSubdirFile(log
, root_dir
, dirs_source
, file_dest
):
459 for dir_source
in dirs_source
:
460 if needUpdateDirNoSubdirFile(log
, root_dir
+ "/" + dir_source
, file_dest
):
464 def needUpdateMultiDirNoSubdirMultiFileExt(log
, root_dir
, dirs_source
, root_file
, files_dest
, file_ext
):
465 for file_dest
in files_dest
:
466 if needUpdateMultiDirNoSubdirFile(log
, root_dir
, dirs_source
, root_file
+ "/" + file_dest
+ file_ext
):
470 def needUpdateMultiDirNoSubdir(log
, root_dir
, dirs_source
, dir_dest
):
471 for dir_source
in dirs_source
:
472 if needUpdateDirNoSubdir(log
, root_dir
+ "/" + dir_source
, dir_dest
):
476 def needUpdateDirNoSubdirExtFile(log
, dir_source
, dir_ext
, file_dest
):
477 if not os
.path
.isfile(file_dest
):
479 destTime
= os
.stat(file_dest
).st_mtime
480 sourceFiles
= os
.listdir(dir_source
)
481 for file in sourceFiles
:
482 if file.endswith(dir_ext
):
483 filePath
= dir_source
+ "/" + file
484 if os
.path
.isfile(filePath
):
485 fileTime
= os
.stat(filePath
).st_mtime
486 if fileTime
> destTime
:
491 def needUpdateDirNoSubdirExtMultiFileExt(log
, dir_source
, dir_ext
, root_file
, files_dest
, file_ext
):
492 for file_dest
in files_dest
:
493 if needUpdateDirNoSubdirExtFile(log
, dir_source
, dir_ext
, root_file
+ "/" + file_dest
+ file_ext
):
497 def needUpdateDirNoSubdir(log
, dir_source
, dir_dest
):
500 sourceFiles
= os
.listdir(dir_source
)
501 destFiles
= os
.listdir(dir_dest
)
502 for file in sourceFiles
:
503 filePath
= dir_source
+ "/" + file
504 if os
.path
.isfile(filePath
):
505 fileTime
= os
.stat(filePath
).st_mtime
506 if fileTime
> latestSourceFile
:
507 latestSourceFile
= fileTime
508 for file in destFiles
:
509 filePath
= dir_dest
+ "/" + file
510 if os
.path
.isfile(filePath
):
511 fileTime
= os
.stat(filePath
).st_mtime
512 if oldestDestFile
== 0 or fileTime
< oldestDestFile
:
513 oldestDestFile
= fileTime
514 if latestSourceFile
> oldestDestFile
:
519 def needUpdateDirNoSubdirLogExt(log
, dir_source
, ext_source
, dir_dest
, ext_dest
):
522 sourceFiles
= findFilesNoSubdir(log
, dir_source
, ext_source
)
523 destFiles
= findFilesNoSubdir(log
, dir_dest
, ext_dest
)
524 for file in sourceFiles
:
525 fileTime
= os
.stat(dir_source
+ "/" + file).st_mtime
526 if (fileTime
> latestSourceFile
):
527 latestSourceFile
= fileTime
528 for file in destFiles
:
529 fileTime
= os
.stat(dir_dest
+ "/" + file).st_mtime
530 if (fileTime
> latestDestFile
):
531 latestDestFile
= fileTime
532 if latestSourceFile
> latestDestFile
or len(sourceFiles
) > len(destFiles
):
533 printLog(log
, "UPDATE; Source: " + str(latestSourceFile
) + ", " + str(len(sourceFiles
)) + " files; Dest: " + str(latestDestFile
) + ", " + str(len(destFiles
)) + " files")
536 printLog(log
, "SKIP *")
539 def needUpdateDirNoSubdirLogExtMultidir(log
, all_dir_base
, all_dir_source
, dir_source
, ext_source
, dir_dest
, ext_dest
):
543 for dir in all_dir_source
:
544 sourceFilesAll
+= findFilesNoSubdir(log
, all_dir_base
+ "/" + dir, ext_source
)
545 sourceFiles
= findFilesNoSubdir(log
, dir_source
, ext_source
)
546 destFiles
= findFilesNoSubdir(log
, dir_dest
, ext_dest
)
547 for file in sourceFiles
:
548 fileTime
= os
.stat(dir_source
+ "/" + file).st_mtime
549 if (fileTime
> latestSourceFile
):
550 latestSourceFile
= fileTime
551 for file in destFiles
:
552 fileTime
= os
.stat(dir_dest
+ "/" + file).st_mtime
553 if (fileTime
> latestDestFile
):
554 latestDestFile
= fileTime
555 if latestSourceFile
> latestDestFile
or len(sourceFilesAll
) > len(destFiles
):
556 printLog(log
, "UPDATE; Source: " + str(latestSourceFile
) + ", " + str(len(sourceFilesAll
)) + " files; Dest: " + str(latestDestFile
) + ", " + str(len(destFiles
)) + " files")
559 printLog(log
, "SKIP *")
562 def findFileMultiDir(log
, dirs_where
, file_name
):
564 for dir in dirs_where
:
566 file = findFile(log
, dir, file_name
)
570 printLog(log
, "EXCEPTION " + str(e
))
571 printLog(log
, "FILE NOT FOUND " + file_name
)
574 def findTool(log
, dirs_where
, file_name
, suffix
):
576 for dir in dirs_where
:
578 tool
= findFile(log
, dir, file_name
+ suffix
)
580 printLog(log
, "TOOL " + tool
)
583 printLog(log
, "EXCEPTION " + str(e
))
584 printLog(log
, "TOOL NOT FOUND " + file_name
+ suffix
)
587 def findMax(log
, dir, file):
588 tool
= dir + "/" + file
589 if os
.path
.isfile(tool
):
590 printLog(log
, "3DSMAX " + tool
)
592 printLog(log
, "3DSMAX NOT FOUND " + file)
595 def toolLogFail(log
, tool
, suffix
):
596 printLog(log
, "FAIL " + tool
+ suffix
+ " is not found")
598 def askVar(log
, name
, default
):
599 sys
.stdout
.write(name
+ " (" + default
+ "): ")
600 line
= sys
.stdin
.readline()
601 linestrip
= line
.strip()
602 if linestrip
== "--":
603 log
.write(name
+ " (" + default
+ "): ''\n")
605 elif linestrip
== "":
606 log
.write(name
+ " (" + default
+ "): '" + default
+ "'\n")
609 log
.write(name
+ " (" + default
+ "): '" + linestrip
+ "'\n")