license.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # https://stackoverflow.com/questions/151677/tool-for-adding-license-headers-to-source-files
  2. # updates the copyright information for all .cs files
  3. # usage: call recursive_traversal, with the following parameters
  4. # parent directory, old copyright text content, new copyright text content
  5. import os
  6. excludedir = ["..\\Lib"]
  7. def update_source(filename, oldcopyright, copyright):
  8. utfstr = chr(0xef)+chr(0xbb)+chr(0xbf)
  9. fdata = file(filename,"r+").read()
  10. isUTF = False
  11. if (fdata.startswith(utfstr)):
  12. isUTF = True
  13. fdata = fdata[3:]
  14. if (oldcopyright != None):
  15. if (fdata.startswith(oldcopyright)):
  16. fdata = fdata[len(oldcopyright):]
  17. if not (fdata.startswith(copyright)):
  18. print "updating "+filename
  19. fdata = copyright + fdata
  20. if (isUTF):
  21. file(filename,"w").write(utfstr+fdata)
  22. else:
  23. file(filename,"w").write(fdata)
  24. def recursive_traversal(dir, oldcopyright, copyright):
  25. global excludedir
  26. fns = os.listdir(dir)
  27. # print "listing "+dir
  28. for fn in fns:
  29. fullfn = os.path.join(dir,fn)
  30. if (fullfn in excludedir):
  31. continue
  32. if (os.path.isdir(fullfn)):
  33. recursive_traversal(fullfn, oldcopyright, copyright)
  34. else:
  35. if (fullfn.endswith(".py")):
  36. update_source(fullfn, oldcopyright, copyright)
  37. #oldcright = file("oldcr.txt","r+").read()
  38. #cright = file("copyrightText.txt","r+").read()
  39. oldcright = None
  40. cright = """# This file is part of libigl, a simple c++ geometry processing library.
  41. #
  42. # Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
  43. #
  44. # This Source Code Form is subject to the terms of the Mozilla Public License
  45. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  46. # obtain one at http://mozilla.org/MPL/2.0/.
  47. """
  48. recursive_traversal(".", oldcright, cright)
  49. exit()