-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetgitid.py
More file actions
62 lines (46 loc) · 1.67 KB
/
Copy pathgetgitid.py
File metadata and controls
62 lines (46 loc) · 1.67 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Method for querying the current gitid
This module contains a single method used to query the current gitid of stlab and stlabutils.
This is necessary because the repositories are constantly being developed and rewritten.
To be able to reproduce measurements, this module will save the git ids together
with the measurement data.
"""
import os
import platform
import subprocess
def get_gitid(measfile):
"""Saves the gitid.
Will query the gitid of both stlab and stlabutils and save the ids into a textfile in
the same directory as the measurement data.
Parameters
----------
measfile : _io.TextIOWrapper
File handle
Returns
-------
gitid : str
The current git id
"""
theOS = platform.system()
theids = []
try:
filename = os.path.realpath(measfile.name)
except AttributeError:
filename = measfile
with open(filename + '.gitids.txt', 'a') as myfile:
for repo in ['stlab', 'stlabutils']:
if theOS == 'Windows':
cmd = 'git -C C:\\libs\\' + repo + ' rev-parse HEAD'
elif theOS == 'Linux': #or theOS == 'Darwin': # does not currently work for MacOS
cmd = 'git -C ~/git/' + repo + ' rev-parse HEAD'
else:
print('Unknown platform detected:', theOS)
break
gitid = subprocess.check_output(
cmd.split(' ')).decode("utf-8").strip('\n')
myfile.write('# Current ' + repo + ' gitid\n')
myfile.write(gitid + '\n')
print(repo, 'git id:', gitid)
theids.append(gitid)
return theids
if __name__ == '__main__':
get_gitid('.')