-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_updater.py
executable file
·61 lines (51 loc) · 1.89 KB
/
version_updater.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
"""
SYNOPSIS: this script is intended to be a hg commit hook-script, i.e. it is
suppose to be run everytime you commit to the repository.
On every commit, it will write the current changeset information to lib/pkg.cfg
This changeset information is then available for the programs to read.
NOTE: you may need to tweak _conf_file so that it finds the right cfg file
SEE the bottom of this file
"""
# BEGIN: YOU PROBABLY SHOULD LEAVE THIS ALONE
import os
import configparser
import subprocess
_ver = None
# try:
# _ver = os.environ['HG_NODE']
# except:
# _ver = None
# def getHGTip():
# """returns the hg tip changeset"""
# ps = subprocess.Popen(["hg", "tip"], stdout=subprocess.PIPE)
# (out, err) = ps.communicate()
# #the version is the second part of the first line
# first_line = out.split("\n")[0];
# return first_line.split(" ")[-1];
def getGitVersion():
"""returns the git commit string"""
ps = subprocess.Popen(["git","rev-parse","--short", "HEAD"], stdout=subprocess.PIPE)
(out, err) = ps.communicate()
out = out.decode().strip()
# print(out)
return out
def update_config(configFile, ver):
"""Tries to read in the configFile, and updates the current version to ver
IF configFile dne, then a new configFile is written w/ the version
"""
configParser = configparser.ConfigParser()
if len(configParser.read(configFile)) == 0:
configParser.add_section("pkg_info")
configParser.set("pkg_info", "git_changeset", ver)
f = open(configFile, "w")
configParser.write(f)
f.close()
#END: YOU PROBABLY SHOULD LEAVE THIS ALONE
#note this might have to be tweaked for every deployment!
_conf_file = os.path.join(os.getcwd(), "lib", "pkg.cfg")
if __name__ == '__main__':
if not _ver:
# (ignored,_ver) = getHGTip().split(":")
_ver = getGitVersion()
update_config(_conf_file, _ver)