Page MenuHomec4science

version.py
No OneTemporary

File Metadata

Created
Sat, Apr 27, 10:31

version.py

import subprocess
import base64
def write_info_file(file_name):
header = '''#include <string>\nstd::string tamaas_release_info = "'''
file_content = ''
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])[:-1]
commit = subprocess.check_output(["git", "rev-parse", branch])[:-1]
file_content += branch + ' ' + commit + '\n\n'
diff = subprocess.check_output(["git", "diff"])
diff_cached = subprocess.check_output(["git", "diff", "--cached"])
file_content += "diff\n" + base64.b64encode(diff) + '\n\n'
file_content += "diff --cached\n" + base64.b64encode(diff_cached) + '\n'
remotes = subprocess.check_output(['git', 'remote', '-v'])
file_content += "remotes\n" + remotes + '\n'
try:
origin_branch_commit = subprocess.check_output(["git", "rev-parse", "origin/" + branch, '--'])
file_content += "origin/" + branch + " commit: " + origin_branch_commit
except:
file_content += "origin/" + branch + " does not exist"
file_content += '"'
file_content = file_content.replace('\n', '\\\n')
with open(file_name, 'w') as file:
file.write(header + file_content + ';\n')

Event Timeline