update-version.py 896 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. from __future__ import unicode_literals
  3. from datetime import datetime
  4. import sys
  5. with open('youtube_dl/version.py', 'rt') as f:
  6. exec(compile(f.read(), 'youtube_dl/version.py', 'exec'))
  7. old_version = locals()['__version__']
  8. old_version_list = old_version.split('.')
  9. old_ver = '.'.join(old_version_list[:3])
  10. old_rev = old_version_list[3] if len(old_version_list) > 3 else ''
  11. ver = datetime.utcnow().strftime("%Y.%m.%d")
  12. rev = (sys.argv[1:] or [''])[0] # Use first argument, if present as revision number
  13. if not rev:
  14. rev = str(int(old_rev or 0) + 1) if old_ver == ver else ''
  15. VERSION = '.'.join((ver, rev)) if rev else ver
  16. VERSION_FILE = '''# Autogenerated by devscripts/update-version.py
  17. from __future__ import unicode_literals
  18. __version__ = {!r}
  19. '''.format(VERSION)
  20. with open('youtube_dl/version.py', 'wt') as f:
  21. f.write(VERSION_FILE)
  22. print(VERSION)