您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/env python3
  2. # -*- Coding: UTF-8 -*-
  3. # ---------------------------------------------------------------------------
  4. # Open Asset Import Library (ASSIMP)
  5. # ---------------------------------------------------------------------------
  6. #
  7. # Copyright (c) 2006-2010, ASSIMP Development Team
  8. #
  9. # All rights reserved.
  10. #
  11. # Redistribution and use of this software in source and binary forms,
  12. # with or without modification, are permitted provided that the following
  13. # conditions are met:
  14. #
  15. # * Redistributions of source code must retain the above
  16. # copyright notice, this list of conditions and the
  17. # following disclaimer.
  18. #
  19. # * Redistributions in binary form must reproduce the above
  20. # copyright notice, this list of conditions and the
  21. # following disclaimer in the documentation and/or other
  22. # materials provided with the distribution.
  23. #
  24. # * Neither the name of the ASSIMP team, nor the names of its
  25. # contributors may be used to endorse or promote products
  26. # derived from this software without specific prior
  27. # written permission of the ASSIMP Development Team.
  28. #
  29. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. # ---------------------------------------------------------------------------
  41. """Generate the regression database db.zip from the files in the <root>
  42. /test/models directory. Older databases are overwritten with no prompt.
  43. """
  44. import sys
  45. import os
  46. import subprocess
  47. import zipfile
  48. import settings
  49. import utils
  50. usage = """gen_db [-i=...] [-e=...] [-p] [-n]
  51. (lists of file extensions are comma delimited, i.e. `3ds,lwo,x`)
  52. -i,--include: List of file extensions to update dumps for. If omitted,
  53. all file extensions are updated except those in `exclude`.
  54. -e,--exclude: Merged with settings.exclude_extensions to produce a
  55. list of all file extensions to ignore. If dumps exist,
  56. they are not altered. If not, theu are not created.
  57. -p,--preview: Preview list of file extensions touched by the update.
  58. Dont' change anything.
  59. -n,--nozip: Don't pack to ZIP archive. Keep all dumps in individual files.
  60. """
  61. # -------------------------------------------------------------------------------
  62. def process_dir(d, outfile, file_filter):
  63. """ Generate small dump records for all files in 'd' """
  64. print("Processing directory " + d)
  65. num = 0
  66. for f in os.listdir(d):
  67. fullp = os.path.join(d, f)
  68. if os.path.isdir(fullp) and not f == ".svn":
  69. num += process_dir(fullp, outfile, file_filter)
  70. continue
  71. if file_filter(f):
  72. for pp in settings.pp_configs_to_test:
  73. num += 1
  74. print("DUMP " + fullp + "\n post-processing: " + pp)
  75. outf = os.path.join(os.getcwd(), settings.database_name,
  76. utils.hashing(fullp, pp))
  77. cmd = [utils.assimp_bin_path,"dump",fullp,outf,"-b","-s","-l"] + pp.split()
  78. outfile.write("assimp dump "+"-"*80+"\n")
  79. outfile.flush()
  80. if subprocess.call(cmd, stdout=outfile, stderr=outfile, shell=False):
  81. print("Failure processing " + fullp)
  82. # spit out an empty file to indicate that this failure is expected
  83. with open(outf,'wb') as f:
  84. pass
  85. return num
  86. # -------------------------------------------------------------------------------
  87. def make_zip():
  88. """Zip the contents of ./<settings.database_name>
  89. to <settings.database_name>.zip using DEFLATE
  90. compression to minimize the file size. """
  91. num = 0
  92. zipout = zipfile.ZipFile(settings.database_name + ".zip", "w", zipfile.ZIP_DEFLATED)
  93. for f in os.listdir(settings.database_name):
  94. p = os.path.join(settings.database_name, f)
  95. zipout.write(p, f)
  96. if settings.remove_old:
  97. os.remove(p)
  98. num += 1
  99. if settings.remove_old:
  100. os.rmdir(settings.database_name)
  101. bad = zipout.testzip()
  102. assert bad is None
  103. print("="*60)
  104. print("Database contains {0} entries".format(num))
  105. # -------------------------------------------------------------------------------
  106. def extract_zip():
  107. """Unzip <settings.database_name>.zip to
  108. ./<settings.database_name>"""
  109. try:
  110. zipout = zipfile.ZipFile(settings.database_name + ".zip", "r", 0)
  111. zipout.extractall(path=settings.database_name)
  112. except (RuntimeError,IOError) as r:
  113. print(r)
  114. print("failed to extract previous ZIP contents. "\
  115. "DB is generated from scratch.")
  116. # -------------------------------------------------------------------------------
  117. def gen_db(ext_list,outfile):
  118. """Generate the crash dump database in
  119. ./<settings.database_name>"""
  120. try:
  121. os.mkdir(settings.database_name)
  122. except OSError:
  123. pass
  124. num = 0
  125. for tp in settings.model_directories:
  126. num += process_dir(tp, outfile,
  127. lambda x: os.path.splitext(x)[1] in ext_list)
  128. print("="*60)
  129. print("Updated {0} entries".format(num))
  130. # -------------------------------------------------------------------------------
  131. if __name__ == "__main__":
  132. utils.find_assimp_or_die()
  133. def clean(f):
  134. f = f.strip("* \'")
  135. return "."+f if f[:1] != '.' else f
  136. if len(sys.argv)>1 and (sys.argv[1] == "--help" or sys.argv[1] == "-h"):
  137. print(usage)
  138. sys.exit(0)
  139. ext_list, preview, nozip = None, False, False
  140. for m in sys.argv[1:]:
  141. if m[:10]=="--exclude=":
  142. settings.exclude_extensions += map(clean, m[10:].split(","))
  143. elif m[:3]=="-e=":
  144. settings.exclude_extensions += map(clean, m[3:].split(","))
  145. elif m[:10]=="--include=":
  146. ext_list = m[10:].split(",")
  147. elif m[:3]=="-i=":
  148. ext_list = m[3:].split(",")
  149. elif m=="-p" or m == "--preview":
  150. preview = True
  151. elif m=="-n" or m == "--nozip":
  152. nozip = True
  153. outfile = open(os.path.join("..", "results", "gen_regression_db_output.txt"), "w")
  154. if ext_list is None:
  155. (ext_list, err) = subprocess.Popen([utils.assimp_bin_path, "listext"],
  156. stdout=subprocess.PIPE).communicate()
  157. ext_list = str(ext_list).lower().split(";")
  158. # todo: Fix for multi dot extensions like .skeleton.xml
  159. ext_list = list(filter(lambda f: not f in settings.exclude_extensions,
  160. map(clean, ext_list)))
  161. if preview:
  162. print(','.join(ext_list))
  163. sys.exit(1)
  164. extract_zip()
  165. gen_db(ext_list,outfile)
  166. make_zip()
  167. print("="*60)
  168. input("Press any key to continue")
  169. sys.exit(0)
  170. # vim: ai ts=4 sts=4 et sw=4