update-copyright.py 665 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from __future__ import with_statement, unicode_literals
  4. import datetime
  5. import glob
  6. import os
  7. import re
  8. import sys
  9. dirn = os.path.dirname
  10. sys.path.insert(0, dirn(dirn(dirn(os.path.abspath(__file__)))))
  11. from devscripts.utils import read_file, write_file
  12. from youtube_dl import compat_str
  13. year = compat_str(datetime.datetime.now().year)
  14. for fn in glob.glob('*.html*'):
  15. content = read_file(fn)
  16. newc = re.sub(r'(?P<copyright>Copyright © 2011-)(?P<year>[0-9]{4})', 'Copyright © 2011-' + year, content)
  17. if content != newc:
  18. tmpFn = fn + '.part'
  19. write_file(tmpFn, newc)
  20. os.rename(tmpFn, fn)