-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_install
executable file
·126 lines (115 loc) · 4.61 KB
/
run_install
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
"""
This script make a pull or clone from addons branches.
Require a addons_branches_conf.py file with a dictionary
Example
"hr": {
'branch': "{ODOO_VERSION}",
'repo': "[email protected]:Vauxoo/hr.git"
},
Require a enviroment variables:
VERSION -> Odoo Version. Example 8.0
ODOO_REPO -> Odoo Repo. Example odoo/odoo Default odoo/odoo.
ADDONS_PATH -> Path to download addons.
ODOO_SERVER_PATH -> Path to download odoo server repo.
"""
import os
import subprocess
import sys
def run(l,env=None):
#log("run",l)
env = dict(os.environ, **env) if env else None
if isinstance(l,list):
print "run:", ' '.join( l )
if env:
rc=os.spawnvpe(os.P_WAIT, l[0], l, env)
else:
rc=os.spawnvp(os.P_WAIT, l[0], l)
elif isinstance(l,str):
print "run:", l
tmp=['sh','-c',l]
if env:
rc=os.spawnvpe(os.P_WAIT, tmp[0], tmp, env)
else:
rc=os.spawnvp(os.P_WAIT, tmp[0], tmp)
#log("run", rc=rc)
return rc
def run_output(l, cwd=None):
#log("run_output",l)
print "run output:", ' '.join( l ), "into", cwd
return subprocess.Popen(l, stdout=subprocess.PIPE, cwd=cwd).communicate()[0]
def mkdirs(dirs):
if isinstance(dirs, basestring) or isinstance(dirs, str):
dirs = [dirs]
for d in dirs:
if not os.path.exists(d):
os.makedirs(d)
def get_cmd_pull(branch_datas, prefix_local_name=None, odoo_version=None):
for local_name in branch_datas:
#branch_name = branch_datas[local_name]['branch']
#repo_name = branch_datas[local_name]['repo']
if prefix_local_name is None:
prefix_local_name = '.'
branch_datas[local_name].update({
'local_name': os.path.join(prefix_local_name, local_name),
'branch': branch_datas[local_name]['branch'].format(
ODOO_VERSION = odoo_version),
})
# TODO: Get from a regex url of lp and git
if 'lp:' in branch_datas[local_name]['repo']:
if os.path.isdir(os.path.join(
branch_datas[local_name]['local_name'], '.bzr')):
cmd = "bzr update {0[local_name]}"\
.format(branch_datas[local_name])
else:
mkdirs(branch_datas[local_name]['local_name'])
cmd = "bzr checkout {0[repo]}/{0[branch]} --lightweight "\
"{0[local_name]}".format(branch_datas[local_name])
elif 'git' in branch_datas[local_name]['repo']:
if os.path.isdir(os.path.join(branch_datas[local_name]['local_name'], '.git')):
cmd = "git --git-dir={git_dir} pull".format(
git_dir = os.path.join(
branch_datas[local_name]['local_name'], '.git'))
else:
mkdirs(branch_datas[local_name]['local_name'])
cmd = "git clone -b {0[branch]} --single-branch --depth=1"\
" {0[repo]} {0[local_name]}".format(branch_datas[local_name])
run(cmd)
def main():
ODOO_VERSION = os.environ.get("VERSION")
if ODOO_VERSION is None:
#ODOO_VERSION = sys.argv[1]
raise "Set VERSION variable"
#print("WARNING: no env variable set for VERSION. "
# "Using '%s'" % ODOO_VERSION)
IS_TRAVIS = os.environ.get("TRAVIS_BUILD_DIR") and True or False
ADDONS_GLOBAL_PATH = IS_TRAVIS and os.environ.get("HOME") or\
os.environ.get("ADDONS_PATH")
ODOO_REPO = os.environ.get("ODOO_REPO")
if ODOO_REPO is None:
ODOO_REPO = "odoo/odoo"
print("WARNING: no env variable set for ODOO_REPO. "
"Using '%s'" % ODOO_REPO)
fname_branches_conf = None
if len(sys.argv) >= 2:
fname_branches_conf = sys.argv[1]
if not os.path.isfile(fname_branches_conf):
fname_branches_conf = None
if fname_branches_conf is None:
raise "First param should be a real file name of branch conf"
ADDONS_BRANCHES = eval(open(fname_branches_conf).read())
get_cmd_pull(ADDONS_BRANCHES, ADDONS_GLOBAL_PATH, ODOO_VERSION)
if not IS_TRAVIS:
ODOO_SERVER_PATH = os.environ.get('ODOO_SERVER_PATH')
if ODOO_SERVER_PATH is None:
raise "Set ODOO_SERVER_PATH variable"
SERVER_BRANCHES = {
"odoo": {
'branch': "{ODOO_VERSION}",
'repo': "[email protected]:{ODOO_REPO}.git"\
.format(ODOO_REPO = ODOO_REPO),
}
}
get_cmd_pull(SERVER_BRANCHES, ODOO_SERVER_PATH, ODOO_VERSION)
if __name__ == '__main__':
main()