validator_data_LEGAL_REVIEW_REQUIRED.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # This python file contains the data used to drive the validator.
  2. """Data for Validator tool"""
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. #
  10. # Anyone seeking to modify this file must follow the process, contact sig-build
  11. # Notice that this is not a JSON file, even though it is almost a valid JSON
  12. # data file.
  13. # The key reason we store this in a python file instead is so that we can
  14. # put explanatory comments int the data, which is not supported by JSON.
  15. # There are other possible approaches (such as removing comments with an re after reading the string)
  16. # but they are more work, so for now we just do it this way.
  17. # In regular expressions in this file, do not use patterns that start with ".*", as they make the entire system very slow.
  18. # Even patterns that start with an single "." open match will slow the system down.
  19. # Patterns should start with a match to a specific character, and match as many specific
  20. # characters as possible before using any wildcard matches.
  21. import os
  22. import logging
  23. import sys
  24. from pathlib import Path
  25. restricted_platforms_for_package = {
  26. 'Mac': [],
  27. 'Windows': [],
  28. 'Provo': ['Provo'],
  29. 'Salem': ['Salem'],
  30. 'Jasper': ['Jasper'],
  31. 'Linux': []
  32. }
  33. restricted_platforms = {}
  34. def find_restricted_platforms():
  35. this_path = Path(__file__).resolve()
  36. root_folder = this_path.parents[2]
  37. relative_path = os.path.relpath(this_path.parent, root_folder)
  38. restricted_path = os.path.join(root_folder, 'restricted')
  39. if os.path.exists(restricted_path):
  40. for dir in [f.path for f in os.scandir(restricted_path) if f.is_dir()]:
  41. sys.path.append(os.path.join(dir, relative_path))
  42. try:
  43. module = __import__('{}_data_LEGAL_REVIEW_REQUIRED'.format(os.path.basename(dir).lower()), locals(), globals())
  44. module.add_restricted_platform(restricted_platforms)
  45. except ModuleNotFoundError:
  46. pass
  47. find_restricted_platforms()
  48. # Order of the exceptions is important. The longer and more specific exceptions should come before the
  49. # short ones to improve the locality of any given exception.
  50. # This is based on the unix style test for binary files.
  51. # It provides a set of characters that occur in text files.
  52. # We assume that file that contain characters outside of this set are binary
  53. # files and skip them.
  54. TEXT_CHARS = bytearray({7, 8, 9, 10, 12, 13, 27} | set(range(0x20, 0x100)) - {0x7f})
  55. def skip_file(filepath):
  56. _ext = os.path.splitext(filepath)[1].lower()
  57. """Check if a file is binary"""
  58. # Don't ever scan these, even thought they sometimes look like text files or are text files
  59. if _ext in {'.js', '.ma', '.psd', '.fbx', '.obj', '.pem', '.lyr', '.resx', '.pak', '.dat', '.dds', '.ilk', '.ppm', '.html'}:
  60. return True
  61. # the dds extension is special, there may be foo.dds, foo.dds.1, foo.dds.2, etc. In these cases, .dds is not the extension returned by splitext
  62. if '.dds.' in filepath:
  63. return True
  64. # Always scan these, even if someone puts binary characters in them.
  65. if _ext in {'.cpp', '.c++', '.cxx', '.h', '.hpp', '.hxx', '.inl', '.c', '.cs', '.py', '.mel', '.mm', '.rc', '.ui', '.qrc', '.ts', '.ini', '.cfg', '.cfx',
  66. '.cfi', '.plist'}:
  67. return False
  68. # Otherwise, open the file and see if we think it is binary by looking at the data.
  69. # This is based on unix style test for binary.
  70. try:
  71. with open(filepath, mode='rb') as f:
  72. data = f.read(1024)
  73. binary = bool(data.translate(None, TEXT_CHARS))
  74. return binary
  75. except:
  76. logging.error('Unable to load file - check this manually: %s', filepath)
  77. return True
  78. def get_prohibited_platforms_for_package(package):
  79. permitted_platforms = restricted_platforms_for_package[package]
  80. return [p for p in restricted_platforms if p not in permitted_platforms]
  81. def get_bypassed_directories(is_all):
  82. # Temporarily exempt folders to not fail validation while people is fixing validation errors, they will be removed once the errors are fixed.
  83. temp_bypass_directories = [
  84. 'commit_validation'
  85. ]
  86. bypassed_directories = [
  87. 'python'
  88. ]
  89. if not is_all:
  90. bypassed_directories.extend([
  91. '.git',
  92. 'restricted',
  93. 'Cache',
  94. 'logs',
  95. 'AssetProcessorTemp',
  96. 'user/log',
  97. 'External'
  98. ])
  99. bypassed_directories.extend(temp_bypass_directories)
  100. return bypassed_directories