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

« back to all changes in this revision

Viewing changes to anybox/recipe/openerp/server.py

[MRG] Update with target branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import os
3
3
from os.path import join
4
4
import sys
 
5
import shutil
5
6
import logging
6
7
import subprocess
7
8
import zc.buildout
46
47
    soft_requirements = ('openerp-command',)
47
48
    with_openerp_command = False
48
49
    with_gunicorn = False
 
50
    with_upgrade = True
49
51
    ws = None
 
52
    template_upgrade_script = os.path.join(os.path.dirname(__file__),
 
53
                                           'upgrade.py.tmpl')
50
54
 
51
55
    def __init__(self, *a, **kw):
52
56
        super(ServerRecipe, self).__init__(*a, **kw)
53
57
        opt = self.options
54
58
        self.with_devtools = (
55
59
            opt.get('with_devtools', 'false').lower() == 'true')
 
60
        self.with_upgrade = self.options.get('upgrade_script') != ''
56
61
        # discarding, because we have a special behaviour with custom
57
62
        # interpreters
58
63
        opt.pop('interpreter', None)
186
191
timeout = %(timeout)s
187
192
max_requests = %(max_requests)s
188
193
 
 
194
openerp.multi_process = True  # needed even with only one worker
189
195
openerp.conf.server_wide_modules = ['web']
190
196
conf = openerp.tools.config
191
197
""" % gunicorn_options
339
345
                self.major_version),
340
346
        )
341
347
 
 
348
    def _register_upgrade_script(self, qualified_name):
 
349
        desc = self._get_or_create_script('openerp_upgrader',
 
350
                                          name=qualified_name)[1]
 
351
        script_opt = self.options.get('upgrade_script', 'upgrade.py run')
 
352
        script = script_opt.split()
 
353
        if len(script) != 2:
 
354
            # TODO add console script entry point support
 
355
            raise zc.buildout.UserError(
 
356
                ("upgrade_script option must take the form "
 
357
                 "SOURCE_FILE CALLABLE (got '%r')" % script))
 
358
        script_source_path = self.make_absolute(script[0])
 
359
        desc.update(
 
360
            entry='openerp_upgrader',
 
361
            arguments='%r, %r, %r, %r' % (
 
362
                script_source_path, script[1],
 
363
                self.config_path, self.buildout_dir),
 
364
        )
 
365
 
 
366
        if not os.path.exists(script_source_path):
 
367
            logger.warning("Ugrade script source %s does not exist."
 
368
                           "Initializing it for you", script_source_path)
 
369
            shutil.copy(self.template_upgrade_script, script_source_path)
 
370
 
342
371
    def _register_gunicorn_startup_script(self, qualified_name):
343
372
        """Register a gunicorn foreground start script for installation.
344
373
 
448
477
 
449
478
        initialization = os.linesep.join((
450
479
            "",
451
 
            "from anybox.recipe.openerp.startup import Session",
452
 
            "session = Session(%s)" % self._relativitize(self.config_path),
 
480
            "from anybox.recipe.openerp.runtime.session import Session",
 
481
            "session = Session(%r, %r)" % (
 
482
                    self._relativitize(self.config_path),
 
483
                    self.buildout_dir),
453
484
            "if len(sys.argv) <= 1:",
454
485
            "    print('To start the OpenERP working session, just do:')",
455
486
            "    print('    session.open(db=DATABASE_NAME)')",
488
519
 
489
520
        common_init = os.linesep.join((
490
521
            "",
491
 
            "from anybox.recipe.openerp.startup import Session",
492
 
            "session = Session(%r)" % self.config_path,
 
522
            "from anybox.recipe.openerp.runtime.session import Session",
 
523
            "session = Session(%r, %r)" % (self.config_path,
 
524
                                           self.buildout_dir),
493
525
        ))
494
526
 
495
527
        for script_name, desc in self.openerp_scripts.items():
518
550
 
519
551
        # provide additional needed entry points for main start/test scripts
520
552
        self.eggs_reqs.extend((
521
 
            ('openerp_starter', 'anybox.recipe.openerp.start_openerp', 'main'),
522
 
            ('openerp_cron_worker', 'anybox.recipe.openerp.start_openerp',
523
 
             'main'),
 
553
            ('openerp_starter',
 
554
             'anybox.recipe.openerp.runtime.start_openerp',
 
555
             'main'),
 
556
            ('openerp_cron_worker',
 
557
             'anybox.recipe.openerp.runtime.start_openerp',
 
558
             'main'),
 
559
            ('openerp_upgrader',
 
560
             'anybox.recipe.openerp.runtime.upgrade',
 
561
             'upgrade'),
524
562
        ))
525
563
 
526
564
        if self.major_version >= (8, 0):
551
589
                                              'cron_worker_%s' % self.name)
552
590
            self._register_cron_worker_startup_script(qualified_name)
553
591
 
 
592
        if self.with_upgrade:
 
593
            qualified_name = self.options.get('upgrade_script_name',
 
594
                                              'upgrade_%s' % self.name)
 
595
            self._register_upgrade_script(qualified_name)
 
596
 
554
597
        self._install_openerp_scripts()
555
598
 
556
599
    def _60_fix_root_path(self):