Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
3.5 KiB

  1. #!/usr/bin/python
  2. # ========= Copyright Valve Corporation, All rights reserved. ============
  3. import subprocess
  4. import re
  5. import os
  6. import sys
  7. reValve = re.compile( "valve", flags = re.IGNORECASE )
  8. reTurtleRock = re.compile( "turtle rock", flags = re.IGNORECASE )
  9. reCopyright = re.compile( "copyright", flags = re.IGNORECASE )
  10. sOutputCopyright = "//========= Copyright Valve Corporation, All rights reserved. ============//\n"
  11. def IsOldCopyrightLine( line ):
  12. if( len( reCopyright.findall( line ) ) == 0 ):
  13. return False
  14. if( len( reValve.findall( line ) ) == 0
  15. and len( reTurtleRock.findall( line ) ) == 0 ):
  16. return False
  17. return True
  18. rFilesWithNoCopyrightNotice = []
  19. def FixCopyrightNotice( sFullPath ):
  20. nLine = 0
  21. f = open( sFullPath, "r" )
  22. if( not f ):
  23. print( "Unable to open file " + sFullPath + "\n" )
  24. return
  25. rFileContents = f.readlines()
  26. f.close()
  27. nOldCopyright = -1
  28. for line in rFileContents:
  29. if( nLine < 10 ):
  30. if( line == sOutputCopyright ):
  31. # File already has the right notice
  32. return
  33. if( IsOldCopyrightLine( line ) ):
  34. nOldCopyright = nLine
  35. break
  36. nLine += 1
  37. if( nOldCopyright == -1 ):
  38. rFilesWithNoCopyrightNotice.append( sFullPath )
  39. rFileContents.insert( 0, sOutputCopyright )
  40. else:
  41. rFileContents[ nOldCopyright ] = sOutputCopyright
  42. # open the file for edit
  43. subprocess.call( [ "p4", "edit", sFullPath ], stdout = subprocess.PIPE )
  44. # open the file for writing
  45. f = open( sFullPath, "w" )
  46. f.writelines( rFileContents )
  47. f.close()
  48. rDirsToSkip = [
  49. 'thirdparty',
  50. 'external',
  51. 'BinkSDK',
  52. 'bink',
  53. 'bink_x360',
  54. 'freetype',
  55. 'GL',
  56. 'maya',
  57. 'miles',
  58. 'curl',
  59. 'ihfx',
  60. 'lxma',
  61. 'modo',
  62. 'openal',
  63. 'opengl',
  64. 'p4api',
  65. 'python',
  66. 'quicktime_win32',
  67. 'xsi',
  68. 'speex',
  69. 'ocaml',
  70. 'perl5',
  71. 'dx10sdk',
  72. 'dx11sdk',
  73. 'dx9sdk',
  74. 'haptics',
  75. 'ajb',
  76. 'stb',
  77. 'havok',
  78. 'hk_physics',
  79. 'lua',
  80. 'maxsdk',
  81. 'x360xdk',
  82. 'swigwin-1.3.34',
  83. 'sapi51',
  84. 'WMPSDK10',
  85. 'FontMaker',
  86. 'mxtk',
  87. 'nvtristriplib',
  88. 'g15',
  89. 'lzma',
  90. 'libparsifal-0.8.3',
  91. 'parsifal',
  92. 'libpng',
  93. 'mysql',
  94. 'zip',
  95. 'zlib',
  96. 'Zlib',
  97. 'windowssdk',
  98. 'bzip2',
  99. 'jpeglib',
  100. 'MakeGameData',
  101. 'toollib',
  102. ]
  103. rFileExtensionsToSkip = [
  104. '.pb.h',
  105. '.pb.cpp',
  106. '.spa.h',
  107. 'ATI_Compress.h',
  108. 'luaxlib.h',
  109. 'lua.h',
  110. 'luaconf.h',
  111. 'lualib.h',
  112. 'eax.h',
  113. 'IceKey.cpp',
  114. 'nvtc.h',
  115. 'amd3dx.h',
  116. 'halton.h',
  117. 'snappy',
  118. 'extendedtrace',
  119. ]
  120. def FixCopyrightNoticeWalk( sPath ):
  121. for root, dirs, files in os.walk( sPath ):
  122. print "Walking directory", root
  123. #print root, dirs
  124. for sDir in rDirsToSkip:
  125. if sDir in dirs:
  126. print "Skipping dir ", os.path.join( root, sDir )
  127. dirs.remove( sDir )
  128. for sFilename in files:
  129. sShortFilename, sFileExt = os.path.splitext( sFilename )
  130. if( sFileExt in [ '.cpp', '.h' ] ):
  131. bSkip = False
  132. for sExt in rFileExtensionsToSkip:
  133. if sExt in sFilename:
  134. bSkip = True
  135. #print "filename=", sFilename
  136. if( bSkip ):
  137. print "Skipping ", sFilename, "because of its extension"
  138. else:
  139. FixCopyrightNotice( os.path.join( root, sFilename ) )
  140. #FixCopyrightNotice( os.path.join( "..", "..", "bitmap", "bitmap.cpp" ) )
  141. #FixCopyrightNoticeWalk( os.path.join( "..", "..", "bitmap" ) )
  142. if( len( sys.argv ) != 2 ):
  143. print "Usage: fixcopyrights.py <path>"
  144. sys.exit(1)
  145. FixCopyrightNoticeWalk( sys.argv[1] )
  146. if( len( rFilesWithNoCopyrightNotice ) ):
  147. f = open( "newcopyrights.txt", "w" )
  148. for file in rFilesWithNoCopyrightNotice:
  149. f.write( file + "\n" )
  150. f.close()
  151. print "Copyright notices added to", len( rFilesWithNoCopyrightNotice ), "files. See newcopyrights.txt for a list\n"