~therp-nl/anybox.recipe.openerp/jbaudoux-relative_paths_resolve_conflict

« back to all changes in this revision

Viewing changes to anybox/recipe/openerp/runtime/start_openerp.py

[MRG] Update with target branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""This module bridges the classical ``openerp-server`` as a console script.
 
2
 
 
3
The :func:`main` function gets registered on the fly by the server recipe as
 
4
a console script entry point and used in particular for ``start_openerp`` and
 
5
``test_openerp``.
 
6
 
 
7
Some version independence logic for the startup process also get bootstrapped
 
8
from here.
 
9
"""
 
10
 
1
11
import sys
2
12
import os
3
13
from . import patch_openerp_v5
4
14
 
5
15
 
6
16
def insert_args(arguments):
 
17
    """Insert `arguments` in ``sys.argv`` (direct impact on child script).
 
18
    """
7
19
    for i, a in enumerate(arguments):
8
20
        sys.argv.insert(i+1, a)
9
21
 
10
22
 
11
23
def main(starter, conf, version=None, just_test=False):
 
24
    """Call the `starter` script, dispatching configuration.
 
25
 
 
26
    All arguments are set in the standalone script produced by buildout through
 
27
    entry point options.
 
28
 
 
29
    :param starter: path to the main script source file (currently
 
30
      ``openerp-server``)
 
31
    :param conf: path to the OpenERP configuration file (managed by the recipe)
 
32
    :param version: OpenERP major version
 
33
    :type version: tuple of integers
 
34
    :param just_test: if True, only run unit tests
 
35
    """
12
36
    arguments = ['-c', conf]
13
37
 
14
38
    if just_test:
19
43
        if version >= (7, 0):
20
44
            arguments.append('--test-enable')
21
45
 
 
46
    if '--install-all' in sys.argv:
 
47
        sys.argv.remove('--install-all')
 
48
        from openerp.tools import config
 
49
        # Maybe we should preparse config in all cases and therefore avoid
 
50
        # adding the '-c' on the fly ?
 
51
        # Still, cautious about pre-6.1 versions
 
52
        config.parse_config(['-c', conf])
 
53
        from openerp.modules import get_modules
 
54
        arguments.extend(('-i', ','.join(get_modules())))
 
55
 
22
56
    insert_args(arguments)
23
57
 
24
58
    if version == (5, 0):
28
62
    glob = globals()
29
63
    glob['__name__'] = '__main__'
30
64
    glob['__file__'] = starter
31
 
    execfile(starter, globals())
 
65
    try:
 
66
        execfile(starter, globals())
 
67
    except SystemExit as exc:
 
68
        if version == (5, 0):
 
69
            # Without Agent.quit() the Timer threads may go on forever
 
70
            # and the script will never stop
 
71
            import netsvc
 
72
            netsvc.Agent.quit()
 
73
        return exc.code