diff options
| author | Antony Lesuisse <lesuisse@gmail.com> | 2014-05-29 18:33:04 +0200 |
|---|---|---|
| committer | Antony Lesuisse <lesuisse@gmail.com> | 2014-05-29 18:33:04 +0200 |
| commit | d4624fa826a5e9542782f2c53c8ba2c766d093bc (patch) | |
| tree | be214779eb6d1f17157aa48e72fbcbf95405e38b /odoo.py | |
| parent | 045ecc603e67911a5390c812cb6b5b123d9c190e (diff) | |
[IMP] repository cleanup
- move packaging stuff to setup
- remove historical stuff
- remove oe, odoo-cmd-fme will be merged with the convered commands
- add an odoo.py script to run odo and boostrap it
- simplify README
- prepare to move documentation to the github wiki
Diffstat (limited to 'odoo.py')
| -rwxr-xr-x | odoo.py | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/odoo.py b/odoo.py new file mode 100755 index 00000000000..54e32726f55 --- /dev/null +++ b/odoo.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python2 +#---------------------------------------------------------- +# odoo cli +# +# To install your odoo development environement type: +# +# wget -O- https://raw.githubusercontent.com/odoo/odoo/master/odoo.py | python +# +# The setup_* subcommands used to boostrap odoo are defined here inline and may +# only depends on the python 2.7 stdlib +# +# The rest of subcommands are defined in odoo/cli or in <module>/cli by +# subclassing the Command object +# +# https://raw.githubusercontent.com/odoo-dev/odoo/master-odoo-cmd-fme/odoo.py +# +#---------------------------------------------------------- +import os +import re +import sys +import subprocess + +GIT_HOOKS_PRE_PUSH = """ +#!/usr/bin/env python2 +import re +import sys +if re.search('github.com[:/]odoo/odoo.git$', sys.argv[2]): + print "Pushing to /odoo/odoo.git is forbidden, please push to odoo-dev, use -f to override" + sys.exit(1) +""" + +def printf(f,*l): + print "odoo:" + f % l + +def run(*l): + if isinstance(l[0], list): + l = l[0] + printf("running %s", " ".join(l)) + subprocess.check_call(l) + +def git_locate(): + # Locate git dir + # TODO add support for os.environ.get('GIT_DIR') + + # check for an odoo child + if os.path.isfile('odoo/.git/config'): + os.chdir('odoo') + + path = os.getcwd() + while path != '/': + gitconfig_path = os.path.join(path, '.git/config') + if os.path.isfile(gitconfig_path): + content = open(gitconfig_path).read() + if re.search('github.com[:/]odoo/odoo.git', content): + break + path = os.path.dirname(path) + if path == '/': + path = None + return path + +def cmd_setup_git_init(): + git_dir = git_locate() + if git_dir: + printf('git repo found at %s',git_dir) + else: + run("git", "init", "odoo") + git_dir = os.path.join(os.getcwd(), 'odoo') + if git_dir: + # sane push config for git < 2.0 + run('git','config','push.default','simple') + # merge bzr style + run('git','config','merge.ff','no') + run('git','config','merge.commit','no') + # push hooks + pre_push_path = os.path.join(git_dir, '.git/hooks/pre-push') + open(pre_push_path,'w').write(GIT_HOOKS_PRE_PUSH.strip()) + os.chmod(pre_push_path, 0755) + # setup odoo remote + run('git','config','remote.odoo.url','https://github.com/odoo/odoo.git') + run('git','config','remote.odoo.pushurl','git@github.com:odoo/odoo.git') + run('git','config','--add','remote.odoo.fetch','dummy') + run('git','config','--unset-all','remote.odoo.fetch') + run('git','config','--add','remote.odoo.fetch','+refs/heads/*:refs/remotes/odoo/heads/*') + # setup odoo-dev remote + run('git','config','remote.odoo-dev.url','https://github.com/odoo-dev/odoo.git') + run('git','config','remote.odoo-dev.pushurl','git@github.com:odoo-dev/odoo.git') + run('git','remote','update') + # setup master branch + run('git','config','branch.master.remote','odoo') + run('git','config','branch.master.merge','refs/heads/master') + run('git','checkout','master') + else: + printf('no git repo found') + +def cmd_setup_git_odoo_dev(): + git_dir = git_locate() + if git_dir: + # setup odoo-dev remote + run('git','config','--add','remote.odoo-dev.fetch','dummy') + run('git','config','--unset-all','remote.odoo-dev.fetch') + run('git','config','--add','remote.odoo-dev.fetch','+refs/heads/*:refs/remotes/odoo-dev/heads/*') + run('git','config','--add','remote.odoo-dev.fetch','+refs/pull/*:refs/remotes/odoo-dev/pull/*') + run('git','remote','update') + +def cmd_setup_git_odoo_review(): + git_dir = git_locate() + if git_dir: + # setup odoo-dev remote + run('git','config','--add','remote.odoo.fetch','dummy') + run('git','config','--unset-all','remote.odoo.fetch') + run('git','config','--add','remote.odoo.fetch','+refs/heads/*:refs/remotes/odoo/heads/*') + run('git','config','--add','remote.odoo.fetch','+refs/tags/*:refs/remotes/odoo/tags/*') + run('git','config','--add','remote.odoo.fetch','+refs/pull/*:refs/remotes/odoo/pull/*') + +def setup_deps_debian(git_dir): + debian_control_path = os.path.join(git_dir, 'debian/control') + debian_control = open(debian_control_path).read() + debs = re.findall('python-[0-9a-z]+',debian_control) + proc = subprocess.Popen(['sudo','apt-get','install'] + debs, stdin=open('/dev/tty')) + proc.communicate() + +def cmd_setup_deps(): + git_dir = git_locate() + if git_dir: + if os.path.isfile('/etc/debian_version'): + setup_deps_debian(git_dir) + +def setup_pg_debian(git_dir): + cmd = ['sudo','su','-','postgres','-c','createuser -s %s' % os.environ['USER']] + subprocess.call(cmd) + +def cmd_setup_pg(): + git_dir = git_locate() + if git_dir: + if os.path.isfile('/etc/debian_version'): + setup_pg_debian(git_dir) + +def cmd_setup(): + cmd_setup_git_init() + cmd_setup_deps() + cmd_setup_pg() + +def main(): + # regsitry of commands + g = globals() + cmds = dict([(i[4:],g[i]) for i in g if i.startswith('cmd_')]) + # if curl URL | python2 then use command setup + if len(sys.argv) == 1 and __file__ == '<stdin>': + cmd_setup() + elif len(sys.argv) == 2 and sys.argv[1] in cmds: + cmds[sys.argv[1]]() + else: + import openerp + openerp.cli.main() + +if __name__ == "__main__": + main() + |
