mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-28 13:11:49 +00:00
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
|
#!/usr/bin/env python
|
||
|
from __future__ import unicode_literals
|
||
|
|
||
|
import datetime as dt
|
||
|
import sys
|
||
|
|
||
|
|
||
|
VERSION_FILE_FORMAT = '''\
|
||
|
# Autogenerated by devscripts/update_version.py
|
||
|
from __future__ import unicode_literals
|
||
|
|
||
|
__version__ = {!r}
|
||
|
'''
|
||
|
|
||
|
|
||
|
def split_version(version):
|
||
|
if '.' not in version:
|
||
|
return None, version
|
||
|
|
||
|
version_list = version.split('.')
|
||
|
version = '.'.join(version_list[:3])
|
||
|
revision = version_list[3] if len(version_list) > 3 else None
|
||
|
|
||
|
return version, revision
|
||
|
|
||
|
|
||
|
with open('youtube_dl/version.py', 'r') as f:
|
||
|
exec(compile(f.read(), 'youtube_dl/version.py', 'exec'))
|
||
|
|
||
|
old_ver, old_rev = split_version(locals()['__version__'])
|
||
|
ver, rev = split_version(sys.argv[1]) if len(sys.argv) > 1 else (None, None)
|
||
|
|
||
|
if not ver:
|
||
|
ver = (
|
||
|
dt.datetime.now(dt.timezone.utc) if sys.version_info >= (3,)
|
||
|
else dt.datetime.utcnow()).strftime('%Y.%m.%d')
|
||
|
if not rev and old_ver == ver:
|
||
|
rev = str(int(old_rev or 0) + 1)
|
||
|
|
||
|
if rev:
|
||
|
ver = ver + '.' + rev
|
||
|
|
||
|
with open('youtube_dl/version.py', 'w') as f:
|
||
|
f.write(VERSION_FILE_FORMAT.format(ver))
|
||
|
|
||
|
print(ver)
|