forked from aethereng/docker-codeaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aster_pkginfo.pytmpl
32 lines (26 loc) · 1.04 KB
/
aster_pkginfo.pytmpl
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
import os
from collections import namedtuple
from time import strftime
import subprocess
def get_git_commit_hash_and_branch(directory):
try:
commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=directory).strip().decode('utf-8')
branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=directory).strip().decode(
'utf-8')
if branch == 'HEAD':
# the branch is in a detached head because we've cloned using a tag
branch = subprocess.check_output(['git', 'describe', '--tags', '--exact-match'], cwd=directory).strip().decode('utf-8')
return commit_hash, branch
except subprocess.CalledProcessError:
print("An error occurred while accessing Git information.")
return None, None
chash, bname = get_git_commit_hash_and_branch(os.getenv('TEMP_DIRECTORY') +'/aster')
pkginfo =(
tuple([int(x) for x in *@VERSION_INFO@.split('.')]),
chash,
bname,
strftime("%d/%m/%Y"),
"n/a",
1,
["no source repository"],
)