diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /devtools/bin/fixcopyrights.py | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'devtools/bin/fixcopyrights.py')
| -rw-r--r-- | devtools/bin/fixcopyrights.py | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/devtools/bin/fixcopyrights.py b/devtools/bin/fixcopyrights.py new file mode 100644 index 0000000..ba43986 --- /dev/null +++ b/devtools/bin/fixcopyrights.py @@ -0,0 +1,177 @@ +#!/usr/bin/python +# ========= Copyright Valve Corporation, All rights reserved. ============ + +import subprocess +import re +import os +import sys + +reValve = re.compile( "valve", flags = re.IGNORECASE ) +reTurtleRock = re.compile( "turtle rock", flags = re.IGNORECASE ) +reCopyright = re.compile( "copyright", flags = re.IGNORECASE ) +sOutputCopyright = "//========= Copyright Valve Corporation, All rights reserved. ============//\n" + +def IsOldCopyrightLine( line ): + if( len( reCopyright.findall( line ) ) == 0 ): + return False + if( len( reValve.findall( line ) ) == 0 + and len( reTurtleRock.findall( line ) ) == 0 ): + return False + + return True + + +rFilesWithNoCopyrightNotice = [] + +def FixCopyrightNotice( sFullPath ): + nLine = 0 + + f = open( sFullPath, "r" ) + if( not f ): + print( "Unable to open file " + sFullPath + "\n" ) + return + + rFileContents = f.readlines() + f.close() + nOldCopyright = -1 + for line in rFileContents: + if( nLine < 10 ): + if( line == sOutputCopyright ): + # File already has the right notice + return + if( IsOldCopyrightLine( line ) ): + nOldCopyright = nLine + break + + nLine += 1 + if( nOldCopyright == -1 ): + rFilesWithNoCopyrightNotice.append( sFullPath ) + rFileContents.insert( 0, sOutputCopyright ) + else: + rFileContents[ nOldCopyright ] = sOutputCopyright + + # open the file for edit + subprocess.call( [ "p4", "edit", sFullPath ], stdout = subprocess.PIPE ) + + # open the file for writing + f = open( sFullPath, "w" ) + f.writelines( rFileContents ) + f.close() + +rDirsToSkip = [ + 'thirdparty', + 'external', + 'BinkSDK', + 'bink', + 'bink_x360', + 'freetype', + 'GL', + 'maya', + 'miles', + 'curl', + 'ihfx', + 'lxma', + 'modo', + 'openal', + 'opengl', + 'p4api', + 'python', + 'quicktime_win32', + 'xsi', + 'speex', + 'ocaml', + 'perl5', + 'dx10sdk', + 'dx11sdk', + 'dx9sdk', + 'haptics', + 'ajb', + 'stb', + 'havok', + 'hk_physics', + 'lua', + 'maxsdk', + 'x360xdk', + 'swigwin-1.3.34', + 'sapi51', + 'WMPSDK10', + 'FontMaker', + 'mxtk', + 'nvtristriplib', + 'g15', + 'lzma', + 'libparsifal-0.8.3', + 'parsifal', + 'libpng', + 'mysql', + 'zip', + 'zlib', + 'Zlib', + 'windowssdk', + 'bzip2', + 'jpeglib', + 'MakeGameData', + 'toollib', + ] + +rFileExtensionsToSkip = [ + '.pb.h', + '.pb.cpp', + '.spa.h', + 'ATI_Compress.h', + 'luaxlib.h', + 'lua.h', + 'luaconf.h', + 'lualib.h', + 'eax.h', + 'IceKey.cpp', + 'nvtc.h', + 'amd3dx.h', + 'halton.h', + 'snappy', + 'extendedtrace', + ] + +def FixCopyrightNoticeWalk( sPath ): + for root, dirs, files in os.walk( sPath ): + print "Walking directory", root + #print root, dirs + for sDir in rDirsToSkip: + if sDir in dirs: + print "Skipping dir ", os.path.join( root, sDir ) + dirs.remove( sDir ) + + for sFilename in files: + sShortFilename, sFileExt = os.path.splitext( sFilename ) + + if( sFileExt in [ '.cpp', '.h' ] ): + bSkip = False + for sExt in rFileExtensionsToSkip: + if sExt in sFilename: + bSkip = True + + #print "filename=", sFilename + if( bSkip ): + print "Skipping ", sFilename, "because of its extension" + else: + FixCopyrightNotice( os.path.join( root, sFilename ) ) + + +#FixCopyrightNotice( os.path.join( "..", "..", "bitmap", "bitmap.cpp" ) ) +#FixCopyrightNoticeWalk( os.path.join( "..", "..", "bitmap" ) ) + +if( len( sys.argv ) != 2 ): + print "Usage: fixcopyrights.py <path>" + sys.exit(1) + +FixCopyrightNoticeWalk( sys.argv[1] ) + +if( len( rFilesWithNoCopyrightNotice ) ): + + f = open( "newcopyrights.txt", "w" ) + for file in rFilesWithNoCopyrightNotice: + f.write( file + "\n" ) + f.close() + + print "Copyright notices added to", len( rFilesWithNoCopyrightNotice ), "files. See newcopyrights.txt for a list\n" + |