forked from openprocurement/openprocurement.buildout
-
Notifications
You must be signed in to change notification settings - Fork 4
/
pin_commits_hash.py
38 lines (33 loc) · 1.21 KB
/
pin_commits_hash.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
from ConfigParser import ConfigParser
from git import Repo
import re
import os
from time import gmtime, strftime
import getpass
username = getpass.getuser()
def pin_commit_hash(package, config):
repo = Repo('')
value = config.get('sources', package)
value = re.sub('branch=\w+', '', value)
value = value + ' ' + 'rev={}'.format(repo.head.object.hexsha)
config.set('sources', package, value)
def create_sandbox_cfg():
config = ConfigParser()
config.read('profiles/sandbox.cfg')
all_packages = dict(config.items('sources')).keys()
pwd = os.getcwd()
for package in all_packages:
try:
os.chdir(pwd + '/src/' + package)
pin_commit_hash(package, config)
os.chdir(pwd)
except OSError:
continue
with open('profiles/sandbox.cfg', 'w') as fp:
config.write(fp)
with open('profiles/sandbox.cfg', 'r') as fp:
content = fp.read().replace('+ =', '+=')
with open('profiles/sandbox.cfg', 'w') as fp:
fp.write("# Autogenerated at ({time}) by {user} \n{content}".format(time=strftime("%Y-%m-%d %H:%M:%S", gmtime()), user=getpass.getuser(), content=content))
if __name__ == '__main__':
create_sandbox_cfg()