Page MenuHomec4science

version.py
No OneTemporary

File Metadata

Created
Fri, Nov 1, 00:48

version.py

import subprocess
import base64
from functools import reduce
def git(*args):
return subprocess.check_output(["git"] + args)
def write_info_file(file_name):
header = '#include "tamaas_info.hh"\n\n'
file_content = ''
branch = git("rev-parse", "--abbrev-ref", "HEAD")[:-1]
commit = git("rev-parse", branch)[:-1]
file_content += \
'std::string tamaas::TamaasInfo::branch = "{}";\n'.format(branch)
file_content += \
'std::string tamaas::TamaasInfo::commit = "{}";\n'.format(commit)
diff = git("diff")
diff += "|".encode('ascii') + git("diff", "--cached")
file_content += \
'std::string tamaas::TamaasInfo::diff = "{}";\n'.format(
base64.b64encode(diff))
remotes = git('remote', '-v')
remotes_strings = filter(lambda x: x != '', remotes.splitlines())
remotes_string = reduce(lambda x, y: x + '"{}\\n"\n'.format(y),
remotes_strings, "")
file_content += \
'std::string tamaas::TamaasInfo::remotes = {};\n'.format(remotes_string)
with open(file_name, 'w') as file:
file.write(header + file_content)

Event Timeline