~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

  • Committer: Jacques-Etienne Baudoux
  • Date: 2013-09-08 13:48:02 UTC
  • Revision ID: je@bcim.be-20130908134802-2lvo19d8u3sfccz9
Support buildout option "relative_paths = true"

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
SERVER_COMMA_LIST_OPTIONS = ('log_handler', )
14
14
 
15
15
 
 
16
def _relative_path(common, path):
 
17
    """Copied from easy_install"""
 
18
    r = []
 
19
    while 1:
 
20
        dirname, basename = os.path.split(path)
 
21
        r.append(basename)
 
22
        if dirname == common:
 
23
            break
 
24
        if dirname == path:
 
25
            raise AssertionError("dirname of %s is the same" % dirname)
 
26
        path = dirname
 
27
    r.reverse()
 
28
    return os.path.join(*r)
 
29
 
 
30
 
16
31
class ServerRecipe(BaseRecipe):
17
32
    """Recipe for server install and config
18
33
    """
266
281
            desc = self.openerp_scripts[name] = dict(entry=entry)
267
282
            return name, desc
268
283
 
 
284
    def _relativitize(self,path):
 
285
        """Inspired from easy_install"""
 
286
        if self._relative_paths:
 
287
            eggs = os.path.normcase(os.path.abspath(self.b_options['eggs-directory']))
 
288
            common = os.path.dirname(os.path.commonprefix([path, eggs]))
 
289
            if (common == self._relative_paths or
 
290
                common.startswith(os.path.join(self._relative_paths, ''))
 
291
                ):
 
292
                return "join(base, %r)" % _relative_path(common, path)
 
293
        return path
 
294
 
269
295
    def _register_main_startup_script(self, qualified_name):
270
296
        """Register main startup script, usually ``start_openerp`` for install.
271
297
        """
272
298
        desc = self._get_or_create_script('openerp_starter',
273
299
                                          name=qualified_name)[1]
274
300
        desc.update(
275
 
            arguments='%r, %r, version=%r' % (self._get_server_command(),
276
 
                                              self.config_path,
 
301
            arguments='%r, %r, version=%r' % (self._relativitize(self._get_server_command()),
 
302
                                              self._relativitize(self.config_path),
277
303
                                              self.major_version),
278
304
        )
279
305
 
306
332
                "devtools.load(for_tests=True)",
307
333
                "")),
308
334
            arguments='%r, %r, version=%r, just_test=True' % (
309
 
                self._get_server_command(),
310
 
                self.config_path,
 
335
                self._relativitize(self._get_server_command()),
 
336
                self._relativitize(self.config_path),
311
337
                self.major_version),
312
338
        )
313
339
 
340
366
        # to resort on hacking sys.argv
341
367
        desc['initialization'] = (
342
368
            "from sys import argv; argv[1:] = ['%s', '-c', '%s.conf.py']" % (
343
 
                gunicorn_entry_point, join(self.etc, qualified_name)))
 
369
                gunicorn_entry_point, self._relativitize(join(self.etc, qualified_name))))
344
370
 
345
371
    def _register_openerp_command(self, qualified_name):
346
372
        """Register https://launchpad.net/openerp-command for install.
403
429
        desc = self._get_or_create_script('openerp_cron_worker',
404
430
                                          name=qualified_name)[1]
405
431
        desc.update(entry='openerp_cron_worker',
406
 
                    arguments='%r, %r' % (script_src, self.config_path),
 
432
                    arguments='%s, %s' % (self._relativitize(script_src),
 
433
                                          self._relativitize(self.config_path)),
407
434
                    initialization='',
408
435
                    )
409
436
 
418
445
        initialization = os.linesep.join((
419
446
            "",
420
447
            "from anybox.recipe.openerp.startup import Session",
421
 
            "session = Session(%r)" % self.config_path,
 
448
            "session = Session(%s)" % self._relativitize(self.config_path),
422
449
            "if len(sys.argv) <= 1:",
423
450
            "    print('To start the OpenERP working session, just do:')",
424
451
            "    print('    session.open(db=DATABASE_NAME)')",
441
468
            initialization=initialization,
442
469
            arguments=self.options.get('arguments', ''),
443
470
            extra_paths=self.extra_paths,
444
 
            # TODO investigate these options:
445
 
            # relative_paths=self._relative_paths,
 
471
            relative_paths=self._relative_paths,
446
472
        )
447
473
 
448
474
    def _install_openerp_scripts(self):
476
502
                interpreter='',
477
503
                initialization=initialization,
478
504
                arguments=desc.get('arguments', ''),
479
 
                # TODO investigate these options:
480
505
                extra_paths=self.extra_paths,
481
 
                # relative_paths=self._relative_paths,
 
506
                relative_paths=self._relative_paths,
482
507
            )
483
508
            self.openerp_installed.append(join(self.bin_dir, script_name))
484
509