Page MenuHomec4science

version.py
No OneTemporary

File Metadata

Created
Tue, May 7, 01:09

version.py

import subprocess
import base64
from functools import reduce
def write_info_file(file_name):
header = '#include "tamaas_info.hh"\n\n'
file_content = ''
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])[:-1]
commit = subprocess.check_output(["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 = subprocess.check_output(["git", "diff"])
diff += "|".encode('ascii') + subprocess.check_output(["git", "diff", "--cached"])
file_content += 'std::string tamaas::TamaasInfo::diff = "{}";\n'.format(base64.b64encode(diff))
remotes = subprocess.check_output(['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)
# try:
# origin_branch_commit = subprocess.check_output(["git", "rev-parse", "origin/" + branch, '--'], universal_newlines=True)
# file_content += "origin/{} commit: {}".format(branch, origin_branch_commit)
# except:
# file_content += "origin/ {} does not exist".format(branch)
with open(file_name, 'w') as file:
file.write(header + file_content)

Event Timeline