71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
from __future__ import unicode_literals
|
|
|
|
import subprocess
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
# Usage: python3 ./devscripts/make_buildconfig.py key=value ...
|
|
|
|
values = {
|
|
'git_commit': '',
|
|
'git_upstream_commit': '',
|
|
# only used by Windows executables
|
|
'variant': None,
|
|
# only used by Linux installations, but not on build
|
|
'is_brew': False,
|
|
}
|
|
|
|
for arg in sys.argv[1:]:
|
|
key, value = arg.split('=')
|
|
# Only known key must be used
|
|
if values[key] is None:
|
|
values[key] = value
|
|
else:
|
|
raise Exception(f'Unknown or occupied key: {key}')
|
|
|
|
# git rev-parse --short ytdlp
|
|
sp = subprocess.Popen(
|
|
['git', 'rev-parse', '--short', 'ytdlp'],
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
cwd=os.path.dirname(os.path.abspath(__file__)))
|
|
out, err = sp.communicate()
|
|
out = out.decode().strip()
|
|
|
|
if re.match('[0-9a-f]+', out):
|
|
values['git_commit'] = out
|
|
|
|
|
|
# git rev-parse --short yt-dlp
|
|
sp = subprocess.Popen(
|
|
['git', 'rev-parse', '--short', 'yt-dlp'],
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
cwd=os.path.dirname(os.path.abspath(__file__)))
|
|
out, err = sp.communicate()
|
|
out = out.decode().strip()
|
|
|
|
if re.match('[0-9a-f]+', out):
|
|
values['git_upstream_commit'] = out
|
|
|
|
pycode = '''# coding: utf-8
|
|
# AUTOMATICALLY GENERATED FILE. DO NOT EDIT OR COMMIT.
|
|
# Generated by ./devscripts/make_buildconfig.py
|
|
from __future__ import unicode_literals
|
|
|
|
'''
|
|
|
|
|
|
def to_string(o):
|
|
if isinstance(o, (str, bool)) or o is None:
|
|
return f'{o!r}'
|
|
else:
|
|
raise Exception(f'Unknown object: {o}')
|
|
|
|
|
|
for k, v in values.items():
|
|
pycode += f'{k} = {to_string(v)}\n'
|
|
|
|
with open('./yt_dlp/build_config.py', 'w') as w:
|
|
w.write(pycode)
|
|
print(pycode)
|