|
1 | | -#!/usr/bin/env python |
2 | | -#---------------------------------------------------------- |
3 | | -# odoo cli |
4 | | -# |
5 | | -# To install your odoo development environement type: |
6 | | -# |
7 | | -# wget -O- https://raw.githubusercontent.com/odoo/odoo/8.0/odoo.py | python |
8 | | -# |
9 | | -# The setup_* subcommands used to boostrap odoo are defined here inline and may |
10 | | -# only depends on the python 2.7 stdlib |
11 | | -# |
12 | | -# The rest of subcommands are defined in odoo/cli or in <module>/cli by |
13 | | -# subclassing the Command object |
14 | | -# |
15 | | -#---------------------------------------------------------- |
16 | | -import os |
17 | | -import re |
18 | | -import sys |
19 | | -import subprocess |
20 | | - |
21 | | -GIT_HOOKS_PRE_PUSH = """ |
22 | | -#!/usr/bin/env python2 |
23 | | -import re |
24 | | -import sys |
25 | | -if re.search('github.com[:/]odoo/odoo.git$', sys.argv[2]): |
26 | | - print "Pushing to /odoo/odoo.git is forbidden, please push to odoo-dev, use --no-verify to override" |
27 | | - sys.exit(1) |
28 | | -""" |
29 | | - |
30 | | -def printf(f,*l): |
31 | | - print "odoo:" + f % l |
32 | | - |
33 | | -def run(*l): |
34 | | - if isinstance(l[0], list): |
35 | | - l = l[0] |
36 | | - printf("running %s", " ".join(l)) |
37 | | - subprocess.check_call(l) |
38 | | - |
39 | | -def git_locate(): |
40 | | - # Locate git dir |
41 | | - # TODO add support for os.environ.get('GIT_DIR') |
42 | | - |
43 | | - # check for an odoo child |
44 | | - if os.path.isfile('odoo/.git/config'): |
45 | | - os.chdir('odoo') |
46 | | - |
47 | | - path = os.getcwd() |
48 | | - while path != os.path.abspath(os.sep): |
49 | | - gitconfig_path = os.path.join(path, '.git/config') |
50 | | - if os.path.isfile(gitconfig_path): |
51 | | - release_py = os.path.join(path, 'openerp/release.py') |
52 | | - if os.path.isfile(release_py): |
53 | | - break |
54 | | - path = os.path.dirname(path) |
55 | | - if path == os.path.abspath(os.sep): |
56 | | - path = None |
57 | | - return path |
58 | | - |
59 | | -def cmd_setup_git(): |
60 | | - git_dir = git_locate() |
61 | | - if git_dir: |
62 | | - printf('git repo found at %s',git_dir) |
63 | | - else: |
64 | | - run("git", "init", "odoo") |
65 | | - os.chdir('odoo') |
66 | | - git_dir = os.getcwd() |
67 | | - if git_dir: |
68 | | - # push sane config for git < 2.0, and hooks |
69 | | - #run('git','config','push.default','simple') |
70 | | - # alias |
71 | | - run('git','config','alias.st','status') |
72 | | - # merge bzr style |
73 | | - run('git','config','merge.commit','no') |
74 | | - # pull let me choose between merge or rebase only works in git > 2.0, use an alias for 1 |
75 | | - run('git','config','pull.ff','only') |
76 | | - run('git','config','alias.pl','pull --ff-only') |
77 | | - pre_push_path = os.path.join(git_dir, '.git/hooks/pre-push') |
78 | | - open(pre_push_path,'w').write(GIT_HOOKS_PRE_PUSH.strip()) |
79 | | - os.chmod(pre_push_path, 0755) |
80 | | - # setup odoo remote |
81 | | - run('git','config','remote.odoo.url','https://github.com/odoo/odoo.git') |
82 | | - run('git','config','remote.odoo.pushurl','git@github.com:odoo/odoo.git') |
83 | | - run('git','config','--add','remote.odoo.fetch','dummy') |
84 | | - run('git','config','--unset-all','remote.odoo.fetch') |
85 | | - run('git','config','--add','remote.odoo.fetch','+refs/heads/*:refs/remotes/odoo/*') |
86 | | - # setup odoo-dev remote |
87 | | - run('git','config','remote.odoo-dev.url','https://github.com/odoo-dev/odoo.git') |
88 | | - run('git','config','remote.odoo-dev.pushurl','git@github.com:odoo-dev/odoo.git') |
89 | | - run('git','remote','update') |
90 | | - # setup 8.0 branch |
91 | | - run('git','config','branch.8.0.remote','odoo') |
92 | | - run('git','config','branch.8.0.merge','refs/heads/8.0') |
93 | | - run('git','checkout','8.0') |
94 | | - else: |
95 | | - printf('no git repo found') |
96 | | - |
97 | | -def cmd_setup_git_dev(): |
98 | | - git_dir = git_locate() |
99 | | - if git_dir: |
100 | | - # setup odoo-dev remote |
101 | | - run('git','config','--add','remote.odoo-dev.fetch','dummy') |
102 | | - run('git','config','--unset-all','remote.odoo-dev.fetch') |
103 | | - run('git','config','--add','remote.odoo-dev.fetch','+refs/heads/*:refs/remotes/odoo-dev/*') |
104 | | - run('git','config','--add','remote.odoo-dev.fetch','+refs/pull/*:refs/remotes/odoo-dev/pull/*') |
105 | | - run('git','remote','update') |
106 | | - |
107 | | -def cmd_setup_git_review(): |
108 | | - git_dir = git_locate() |
109 | | - if git_dir: |
110 | | - # setup odoo-dev remote |
111 | | - run('git','config','--add','remote.odoo.fetch','dummy') |
112 | | - run('git','config','--unset-all','remote.odoo.fetch') |
113 | | - run('git','config','--add','remote.odoo.fetch','+refs/heads/*:refs/remotes/odoo/*') |
114 | | - run('git','config','--add','remote.odoo.fetch','+refs/tags/*:refs/remotes/odoo/tags/*') |
115 | | - run('git','config','--add','remote.odoo.fetch','+refs/pull/*:refs/remotes/odoo/pull/*') |
116 | | - |
117 | | -def setup_deps_debian(git_dir): |
118 | | - debian_control_path = os.path.join(git_dir, 'debian/control') |
119 | | - debian_control = open(debian_control_path).read() |
120 | | - debs = re.findall('python-[0-9a-z]+',debian_control) |
121 | | - debs += ["postgresql"] |
122 | | - proc = subprocess.Popen(['sudo','apt-get','install'] + debs, stdin=open('/dev/tty')) |
123 | | - proc.communicate() |
124 | | - |
125 | | -def cmd_setup_deps(): |
126 | | - git_dir = git_locate() |
127 | | - if git_dir: |
128 | | - if os.path.isfile('/etc/debian_version'): |
129 | | - setup_deps_debian(git_dir) |
130 | | - |
131 | | -def setup_pg_debian(git_dir): |
132 | | - cmd = ['sudo','su','-','postgres','-c','createuser -s %s' % os.environ['USER']] |
133 | | - subprocess.call(cmd) |
134 | | - |
135 | | -def cmd_setup_pg(): |
136 | | - git_dir = git_locate() |
137 | | - if git_dir: |
138 | | - if os.path.isfile('/etc/debian_version'): |
139 | | - setup_pg_debian(git_dir) |
140 | | - |
141 | | -def cmd_setup(): |
142 | | - cmd_setup_git() |
143 | | - cmd_setup_deps() |
144 | | - cmd_setup_pg() |
145 | | - |
146 | | -def main(): |
147 | | - # regsitry of commands |
148 | | - g = globals() |
149 | | - cmds = dict([(i[4:],g[i]) for i in g if i.startswith('cmd_')]) |
150 | | - # if curl URL | python2 then use command setup |
151 | | - if len(sys.argv) == 1 and __file__ == '<stdin>': |
152 | | - cmd_setup() |
153 | | - elif len(sys.argv) == 2 and sys.argv[1] in cmds: |
154 | | - cmds[sys.argv[1]]() |
155 | | - else: |
156 | | - import openerp |
157 | | - openerp.cli.main() |
158 | | - |
159 | | -if __name__ == "__main__": |
160 | | - main() |
161 | | - |
0 commit comments