-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetgit.py
43 lines (36 loc) · 1.07 KB
/
getgit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import subprocess
import re
import datetime
import sys
def gitinfo():
git_ret=subprocess.Popen(['git','log','--pretty=%H','HEAD^..HEAD'],
stdout=subprocess.PIPE)
git_hash = git_ret.communicate()[0]
if git_hash:
git_hash=git_hash.strip().decode()
url_ret=subprocess.Popen(['git','remote','show','origin'],
stdout=subprocess.PIPE)
remote=url_ret.communicate()[0].decode()
match=re.search('URL:\s*(\S+)\n',remote)
if match:
git_url=match.group(1)
scmversion='{0}:{1}'.format(git_url, git_hash)
else:
scmversion=git_hash
return scmversion
else:
return None
def makefile():
return open("Makefile").read()
def when():
return datetime.datetime.now().isoformat()
if __name__=='__main__':
app=sys.argv[1]
attrib=dict()
attrib["VERSION"]=gitinfo()
attrib["CFG"]=makefile()
attrib["COMPILETIME"]=when()
f=open(app, "w")
for k, v in attrib.items():
f.write("constexpr char {0}[]=R\"({1})\";\n\n".format(k, v))
f.close()