37 |
37 |
38 from cubicweb import ExecutionError |
38 from cubicweb import ExecutionError |
39 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
39 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg |
40 from cubicweb.cwctl import CWCTL, InstanceCommand, init_cmdline_log_threshold |
40 from cubicweb.cwctl import CWCTL, InstanceCommand, init_cmdline_log_threshold |
41 from cubicweb.pyramid import wsgi_application_from_cwconfig |
41 from cubicweb.pyramid import wsgi_application_from_cwconfig |
|
42 from cubicweb.pyramid.config import get_random_secret_key |
42 from cubicweb.server import serverctl, set_debug |
43 from cubicweb.server import serverctl, set_debug |
43 from cubicweb.web.webctl import WebCreateHandler |
44 from cubicweb.web.webctl import WebCreateHandler |
|
45 from cubicweb.toolsutils import fill_templated_file |
44 |
46 |
45 import waitress |
47 import waitress |
46 |
48 |
47 MAXFD = 1024 |
49 MAXFD = 1024 |
48 |
50 |
49 DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'HOOKS', 'OPS', 'SEC', 'MORE') |
51 DBG_FLAGS = ('RQL', 'SQL', 'REPO', 'HOOKS', 'OPS', 'SEC', 'MORE') |
50 LOG_LEVELS = ('debug', 'info', 'warning', 'error') |
52 LOG_LEVELS = ('debug', 'info', 'warning', 'error') |
|
53 |
|
54 |
|
55 def _generate_pyramid_ini_file(pyramid_ini_path): |
|
56 """Write a 'development.ini' file into apphome.""" |
|
57 template_fpath = os.path.join(os.path.dirname(__file__), 'pyramid.ini.tmpl') |
|
58 target_fpath = os.path.join(pyramid_ini_path) |
|
59 context = { |
|
60 'secret_1': get_random_secret_key(), |
|
61 'secret_2': get_random_secret_key(), |
|
62 'secret_3': get_random_secret_key(), |
|
63 } |
|
64 fill_templated_file(template_fpath, target_fpath, context) |
51 |
65 |
52 |
66 |
53 class PyramidCreateHandler(serverctl.RepositoryCreateHandler, |
67 class PyramidCreateHandler(serverctl.RepositoryCreateHandler, |
54 WebCreateHandler): |
68 WebCreateHandler): |
55 cfgname = 'pyramid' |
69 cfgname = 'pyramid' |
70 |
84 |
71 def bootstrap(self, cubes, automatic=False, inputlevel=0): |
85 def bootstrap(self, cubes, automatic=False, inputlevel=0): |
72 """bootstrap this configuration""" |
86 """bootstrap this configuration""" |
73 serverctl.RepositoryCreateHandler.bootstrap(self, cubes, automatic, inputlevel) |
87 serverctl.RepositoryCreateHandler.bootstrap(self, cubes, automatic, inputlevel) |
74 WebCreateHandler.bootstrap(self, cubes, automatic, inputlevel) |
88 WebCreateHandler.bootstrap(self, cubes, automatic, inputlevel) |
75 # TODO: write pyramid.ini file |
89 _generate_pyramid_ini_file(os.path.join(self.config.apphome, "pyramid.ini")) |
76 |
90 |
77 |
91 |
78 class PyramidStartHandler(InstanceCommand): |
92 class PyramidStartHandler(InstanceCommand): |
79 """Start an interactive pyramid server. |
93 """Start an interactive pyramid server. |
80 |
94 |
330 |
344 |
331 cwconfig = cwcfg.config_for(appid, debugmode=debugmode) |
345 cwconfig = cwcfg.config_for(appid, debugmode=debugmode) |
332 filelist_path = os.path.join(cwconfig.apphome, |
346 filelist_path = os.path.join(cwconfig.apphome, |
333 '.pyramid-reload-files.list') |
347 '.pyramid-reload-files.list') |
334 |
348 |
|
349 pyramid_ini_path = os.path.join(cwconfig.apphome, "pyramid.ini") |
|
350 if not os.path.exists(pyramid_ini_path): |
|
351 _generate_pyramid_ini_file(pyramid_ini_path) |
|
352 |
335 if autoreload and not os.environ.get(self._reloader_environ_key): |
353 if autoreload and not os.environ.get(self._reloader_environ_key): |
336 return self.restart_with_reloader(filelist_path) |
354 return self.restart_with_reloader(filelist_path) |
337 |
355 |
338 if autoreload: |
356 if autoreload: |
339 _turn_sigterm_into_systemexit() |
357 _turn_sigterm_into_systemexit() |