Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / tools / build_gamedata / configuration / scripts.py
blob6e885bdd32159a5690bba77f74ab09a339cb73d6
1 #!/usr/bin/python
2 #
3 # \file export.py
4 # \brief Useful scripts
5 # \date 2009-02-18 09:22GMT
6 # \author Jan Boon (Kaetemi)
7 # Useful scripts
8 #
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")
33 print text
35 pendingProcesses = []
36 processLimit = math.ceil(multiprocessing.cpu_count() * 0.75)
38 def callParallelProcess(command):
39 res = 0
40 if len(pendingProcesses) >= processLimit:
41 waitingProc = pendingProcesses.pop(0)
42 res = waitingProc.wait()
43 proc = subprocess.Popen(command)
44 pendingProcesses.append(proc)
45 return res
47 def flushParallelProcesses():
48 res = 0
49 while (len(pendingProcesses) > 0):
50 waitingProc = pendingProcesses.pop(0)
51 procRes = waitingProc.wait()
52 if procRes != 0:
53 res = procRes
54 return res
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):
64 return 1
65 else:
66 return 0
67 return 1
68 printLog(log, "MISSING " + source)
69 return 0
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):
75 os.remove(dest)
76 return 1
77 else:
78 return 0
79 return 1
80 printLog(log, "MISSING " + source)
81 return 0
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):
87 os.remove(dest)
88 printLog(log, source + " -> " + dest)
89 return 1
90 else:
91 printLog(log, "SKIP " + dest)
92 return 0
93 printLog(log, source + " -> " + dest)
94 return 1
95 printLog(log, "MISSING " + source)
96 printLog(log, "SKIP " + dest)
97 return 0
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)
135 else:
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)
145 else:
146 printLog(log, "RM " + dir_files + "/" + fileName)
147 os.remove(dir_files + "/" + fileName)
148 printLog(log, "RMDIR " + dir_files)
149 os.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)
169 else:
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):
258 result = [ ]
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 + "/")
268 else:
269 printLog(log, "findFilesRecursive: file not dir or file?!" + filePath)
270 return result
272 def findFiles(log, dir_where, dir_sub, file_ext):
273 result = [ ]
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)
285 else:
286 printLog(log, "findFiles: file not dir or file?!" + filePath)
287 return result
289 def isLegalFileName(fileName):
290 return fileName != ".svn" and fileName != ".." and fileName != "." and fileName != "*.*"
292 def findFilesNoSubdir(log, dir_where, file_ext):
293 result = [ ]
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)
304 return result
306 def findFilesNoSubdirFiltered(log, dir_where, file_ext, filter):
307 if len(filter) == 0:
308 return findFilesNoSubdir(log, dir_where, file_ext)
309 result = [ ]
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 ]
321 break
322 elif not os.path.isdir(fileFull):
323 printLog(log, "findFilesNoSubdir: file not dir or file?!" + fileFull)
324 return result
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:
333 return filePath
334 elif os.path.isdir(filePath):
335 result = findFile(log, filePath, file_name)
336 if result != "":
337 return result
338 else:
339 printLog(log, "findFile: file not dir or file?! " + filePath)
340 return ""
342 def needUpdateDirByLowercaseTagLog(log, dir_source, ext_source, dir_dest, ext_dest):
343 updateCount = 0
344 skipCount = 0
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
356 else:
357 skipCount = skipCount + 1
358 else:
359 updateCount = updateCount + 1
360 if updateCount > 0:
361 printLog(log, "UPDATE " + str(updateCount) + " / " + str(len(sourceFiles)) + "; SKIP " + str(skipCount) + " / " + str(len(sourceFiles)) + "; DEST " + str(len(destFiles)))
362 return 1
363 else:
364 printLog(log, "SKIP " + str(skipCount) + " / " + str(len(sourceFiles)) + "; DEST " + str(len(destFiles)))
365 return 0
367 def needUpdateDirByTagLogFiltered(log, dir_source, ext_source, dir_dest, ext_dest, filter):
368 updateCount = 0
369 skipCount = 0
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
381 else:
382 skipCount = skipCount + 1
383 else:
384 updateCount = updateCount + 1
385 if updateCount > 0:
386 printLog(log, "UPDATE " + str(updateCount) + " / " + str(len(sourceFiles)) + "; SKIP " + str(skipCount) + " / " + str(len(sourceFiles)) + "; DEST " + str(len(destFiles)))
387 return 1
388 else:
389 printLog(log, "SKIP " + str(skipCount) + " / " + str(len(sourceFiles)) + "; DEST " + str(len(destFiles)))
390 return 0
392 def needUpdateDirByTagLog(log, dir_source, ext_source, dir_dest, ext_dest):
393 updateCount = 0
394 skipCount = 0
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
406 else:
407 skipCount = skipCount + 1
408 else:
409 updateCount = updateCount + 1
410 if updateCount > 0:
411 printLog(log, "UPDATE " + str(updateCount) + " / " + str(len(sourceFiles)) + "; SKIP " + str(skipCount) + " / " + str(len(sourceFiles)) + "; DEST " + str(len(destFiles)))
412 return 1
413 else:
414 printLog(log, "SKIP " + str(skipCount) + " / " + str(len(sourceFiles)) + "; DEST " + str(len(destFiles)))
415 return 0
417 def needUpdateDirNoSubdirFile(log, dir_source, file_dest):
418 if not os.path.isfile(file_dest):
419 return 1
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:
427 return 1
428 else:
429 return 0
431 def needUpdateFileDirNoSubdir(log, file_source, dir_dest):
432 if not os.path.isfile(file_source):
433 printLog(log, "WARNING MISSING " + file_source)
434 return 0
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:
442 return 1
443 else:
444 return 0
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):
449 return 1
450 return 0
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):
455 return 1
456 return 0
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):
461 return 1
462 return 0
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):
467 return 1
468 return 0
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):
473 return 1
474 return 0
476 def needUpdateDirNoSubdirExtFile(log, dir_source, dir_ext, file_dest):
477 if not os.path.isfile(file_dest):
478 return 1
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:
487 return 1
488 else:
489 return 0
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):
494 return 1
495 return 0
497 def needUpdateDirNoSubdir(log, dir_source, dir_dest):
498 latestSourceFile = 0
499 oldestDestFile = 0
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:
515 return 1
516 else:
517 return 0
519 def needUpdateDirNoSubdirLogExt(log, dir_source, ext_source, dir_dest, ext_dest):
520 latestSourceFile = 0
521 latestDestFile = 0
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")
534 return 1
535 else:
536 printLog(log, "SKIP *")
537 return 0
539 def needUpdateDirNoSubdirLogExtMultidir(log, all_dir_base, all_dir_source, dir_source, ext_source, dir_dest, ext_dest):
540 latestSourceFile = 0
541 latestDestFile = 0
542 sourceFilesAll = [ ]
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")
557 return 1
558 else:
559 printLog(log, "SKIP *")
560 return 0
562 def findFileMultiDir(log, dirs_where, file_name):
563 try:
564 for dir in dirs_where:
565 if dir != "":
566 file = findFile(log, dir, file_name)
567 if file != "":
568 return file
569 except Exception, e:
570 printLog(log, "EXCEPTION " + str(e))
571 printLog(log, "FILE NOT FOUND " + file_name)
572 return ""
574 def findTool(log, dirs_where, file_name, suffix):
575 try:
576 for dir in dirs_where:
577 if dir != "":
578 tool = findFile(log, dir, file_name + suffix)
579 if tool != "":
580 printLog(log, "TOOL " + tool)
581 return tool
582 except Exception, e:
583 printLog(log, "EXCEPTION " + str(e))
584 printLog(log, "TOOL NOT FOUND " + file_name + suffix)
585 return ""
587 def findMax(log, dir, file):
588 tool = dir + "/" + file
589 if os.path.isfile(tool):
590 printLog(log, "3DSMAX " + tool)
591 return tool
592 printLog(log, "3DSMAX NOT FOUND " + file)
593 return ""
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")
604 return ""
605 elif linestrip == "":
606 log.write(name + " (" + default + "): '" + default + "'\n")
607 return default
608 else:
609 log.write(name + " (" + default + "): '" + linestrip + "'\n")
610 return linestrip