author | Christophe de Vienne <christophe@unlish.com> |
Fri, 05 Sep 2014 12:38:13 +0200 | |
changeset 11633 | ffe4040cf4a2 |
child 11637 | a9cde6a3394c |
permissions | -rw-r--r-- |
11633
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
1 |
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
2 |
from cubicweb.cwctl import CWCTL, InstanceCommand, init_cmdline_log_threshold |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
3 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
4 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
5 |
class PyramidStartHandler(InstanceCommand): |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
6 |
"""Start an interactive pyramid server. |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
7 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
8 |
This command requires http://hg.logilab.org/review/pyramid_cubicweb/ |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
9 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
10 |
<instance> |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
11 |
identifier of the instance to configure. |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
12 |
""" |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
13 |
name = 'pyramid' |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
14 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
15 |
options = ( |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
16 |
("debug", |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
17 |
{'short': 'D', 'action': 'store_true', |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
18 |
'help': 'start server in debug mode.'}), |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
19 |
('loglevel', |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
20 |
{'short': 'l', 'type': 'choice', 'metavar': '<log level>', |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
21 |
'default': None, 'choices': ('debug', 'info', 'warning', 'error'), |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
22 |
'help': 'debug if -D is set, error otherwise', |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
23 |
}), |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
24 |
) |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
25 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
26 |
def pyramid_instance(self, appid): |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
27 |
from pyramid_cubicweb import make_cubicweb_application |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
28 |
from waitress import serve |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
29 |
cwconfig = cwcfg.config_for(appid, debugmode=self['debug']) |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
30 |
init_cmdline_log_threshold(cwconfig, self['loglevel']) |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
31 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
32 |
host = cwconfig['interface'] |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
33 |
port = cwconfig['port'] or 8080 |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
34 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
35 |
pyramid_config = make_cubicweb_application(cwconfig) |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
36 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
37 |
repo = cwconfig.repository() |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
38 |
try: |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
39 |
repo.start_looping_tasks() |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
40 |
serve(pyramid_config.make_wsgi_app(), host=host, port=port) |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
41 |
finally: |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
42 |
repo.shutdown() |
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
43 |
|
ffe4040cf4a2
Implements the 'pyramid' command.
Christophe de Vienne <christophe@unlish.com>
parents:
diff
changeset
|
44 |
CWCTL.register(PyramidStartHandler) |