From 2d5fc151a201ddcbdbabfb1f45060b65679f67f2 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Tue, 27 Sep 2016 11:54:12 +0200 Subject: [REF] cli: rename odoo.py to setup_dev.py and move it under the setup package. Since the rename of the openerp directory into odoo, having a script named "odoo.py" conflicts with a package named "odoo". --- setup/setup_dev.py | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100755 setup/setup_dev.py (limited to 'setup/setup_dev.py') diff --git a/setup/setup_dev.py b/setup/setup_dev.py new file mode 100755 index 00000000000..c9efdaf8935 --- /dev/null +++ b/setup/setup_dev.py @@ -0,0 +1,166 @@ +#!/usr/bin/env python +#---------------------------------------------------------- +# odoo cli +# +# To install your odoo development environement type: +# +# wget -O- https://raw.githubusercontent.com/odoo/odoo/9.0/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 /cli by +# subclassing the Command object +# +#---------------------------------------------------------- +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 --no-verify 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 != os.path.abspath(os.sep): + gitconfig_path = os.path.join(path, '.git/config') + if os.path.isfile(gitconfig_path): + release_py = os.path.join(path, 'odoo/release.py') + if os.path.isfile(release_py): + break + path = os.path.dirname(path) + if path == os.path.abspath(os.sep): + path = None + return path + +def cmd_setup_git(): + git_dir = git_locate() + if git_dir: + printf('git repo found at %s',git_dir) + else: + run("git", "init", "odoo") + os.chdir('odoo') + git_dir = os.getcwd() + if git_dir: + # push sane config for git < 2.0, and hooks + #run('git','config','push.default','simple') + # alias + run('git','config','alias.st','status') + # merge bzr style + run('git','config','merge.commit','no') + # pull let me choose between merge or rebase only works in git > 2.0, use an alias for 1 + run('git','config','pull.ff','only') + run('git','config','alias.pl','pull --ff-only') + 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/*') + # 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 9.0 branch + run('git','config','branch.9.0.remote','odoo') + run('git','config','branch.9.0.merge','refs/heads/9.0') + run('git','checkout','9.0') + else: + printf('no git repo found') + +def cmd_setup_git_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/*') + run('git','config','--add','remote.odoo-dev.fetch','+refs/pull/*:refs/remotes/odoo-dev/pull/*') + run('git','remote','update') + +def cmd_setup_git_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/*') + 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) + debs += ["postgresql"] + 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() + cmd_setup_deps() + cmd_setup_pg() + +def main(): + # registry 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__ == '': + cmd_setup() + elif len(sys.argv) == 2 and sys.argv[1] in cmds: + cmds[sys.argv[1]]() + else: + if len(sys.argv) > 1 and sys.argv[1] == 'gevent': + sys.argv.remove('gevent') + import gevent.monkey + gevent.monkey.patch_all() + import psycogreen.gevent + psycogreen.gevent.patch_psycopg() + import odoo + odoo.cli.main() + +if __name__ == "__main__": + main() -- cgit v1.2.3 From ed8f0c83c46a5011abb5da772b74c3aed5a32b9d Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Fri, 23 Sep 2016 22:25:18 +0200 Subject: [REF] cli: renamed openerp-server to odoo-bin The use of an entry point was considered in order to provide an `odoo` command in the path for the packages users, but the generated entry point will first check that all the things in install_requires were provided in a not bright way: it'll check that it matches a distribution name. This does not work because python-chart does not have the distrubtion name "pychart" which is provided by the python-pychart package in debian jessie. Same for suds-jurko which is provided by python-suds in debian stretch but does not have the distribution name "suds". Also, adapted the packages tests to these cli changes. --- setup/setup_dev.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setup/setup_dev.py') diff --git a/setup/setup_dev.py b/setup/setup_dev.py index c9efdaf8935..dfea4b67d74 100755 --- a/setup/setup_dev.py +++ b/setup/setup_dev.py @@ -4,7 +4,7 @@ # # To install your odoo development environement type: # -# wget -O- https://raw.githubusercontent.com/odoo/odoo/9.0/odoo.py | python +# wget -O- https://raw.githubusercontent.com/odoo/odoo/10.0/setup/setup_dev.py | python # # The setup_* subcommands used to boostrap odoo are defined here inline and may # only depends on the python 2.7 stdlib -- cgit v1.2.3 From 467a958ab0a4bcee03b9d4e611a65a945916b189 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 26 Sep 2016 12:09:00 +0200 Subject: [FIX] core: handle gevent on command line correctly --- setup/setup_dev.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'setup/setup_dev.py') diff --git a/setup/setup_dev.py b/setup/setup_dev.py index dfea4b67d74..5ddac8b1a6f 100755 --- a/setup/setup_dev.py +++ b/setup/setup_dev.py @@ -153,14 +153,7 @@ def main(): elif len(sys.argv) == 2 and sys.argv[1] in cmds: cmds[sys.argv[1]]() else: - if len(sys.argv) > 1 and sys.argv[1] == 'gevent': - sys.argv.remove('gevent') - import gevent.monkey - gevent.monkey.patch_all() - import psycogreen.gevent - psycogreen.gevent.patch_psycopg() - import odoo - odoo.cli.main() + sys.exit('Unknow command. Command available: %r' % (cmds.keys(),)) if __name__ == "__main__": main() -- cgit v1.2.3