-
Notifications
You must be signed in to change notification settings - Fork 1
/
gflib.py
73 lines (58 loc) · 1.64 KB
/
gflib.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
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
"""Python library for downloading git flow."""
import os
import tempfile
import shlex
import subprocess
EXEC_FILES = ['git-flow']
SCRIPT_FILES = [
'git-flow-init',
'git-flow-feature',
'git-flow-hotfix',
'git-flow-release',
'git-flow-support',
'git-flow-version',
'gitflow-common',
'gitflow-shFlags'
]
if os.environ.get('DEBUG') is not None:
DEBUG = ''
else:
DEBUG = '-q'
def gf_repo():
"""Set Git Flow Repo based on env variable or file.
@return: Git Flow Repo from Env Var or File.
@rtype: str
"""
gfv = os.environ.get('GF_REPO')
if gfv is not None:
return gfv
elif gfv is None:
with open('GF_REPO') as gfvf:
return gfvf.read()
def gf_version():
"""Set Git Flow Version based on env variable or file.
@return: Git Flow Version from Env Var or File.
@rtype: str
"""
gfv = os.environ.get('GF_VERSION')
if gfv is not None:
return gfv
elif gfv is None:
with open('GF_VERSION') as gfvf:
return gfvf.read()
def get_gitflow():
"""Downloads Git Flow from Github and creates setuptools 'scripts' struct.
@return: Setuptools 'scripts'-type file list.
@rtype: list
"""
co_dir = tempfile.mkdtemp()
git_cmds = [
"git clone %s %s %s" % (DEBUG, gf_repo(), co_dir),
"git checkout %s %s " % (DEBUG, gf_version()),
"git submodule %s init" % DEBUG,
"git submodule %s update" % DEBUG
]
for cmd in git_cmds:
subprocess.Popen(shlex.split(cmd), cwd=co_dir).wait()
return [os.path.join(co_dir, dlf) for dlf in EXEC_FILES + SCRIPT_FILES]