author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Sat, 18 Jul 2009 22:58:30 +0200 | |
branch | stable |
changeset 2395 | e3093fc12a00 |
parent 1977 | 606923dff11b |
child 2476 | 1294a6bdf3bf |
permissions | -rw-r--r-- |
0 | 1 |
"""cubicweb-clt handlers for twisted |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
2 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
3 |
:organization: Logilab |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
||
9 |
import sys |
|
10 |
||
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
11 |
from cubicweb import underline_title |
0 | 12 |
from cubicweb.toolsutils import CommandHandler |
13 |
from cubicweb.web.webctl import WebCreateHandler |
|
14 |
||
15 |
# trigger configuration registration |
|
16 |
import cubicweb.etwist.twconfig # pylint: disable-msg=W0611 |
|
17 |
||
18 |
||
19 |
class TWCreateHandler(WebCreateHandler): |
|
20 |
cfgname = 'twisted' |
|
21 |
||
22 |
def bootstrap(self, cubes, inputlevel=0): |
|
23 |
"""bootstrap this configuration""" |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
24 |
print '\n'+underline_title('Configuring Twisted') |
0 | 25 |
mainpyfile = self.config.server_file() |
26 |
mainpy = open(mainpyfile, 'w') |
|
27 |
mainpy.write(''' |
|
28 |
from cubicweb.etwist import server |
|
29 |
application = server.main(%r, %r) |
|
30 |
''' % (self.config.appid, self.config.name)) |
|
31 |
mainpy.close() |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
32 |
print '-> generated %s' % mainpyfile |
0 | 33 |
super(TWCreateHandler, self).bootstrap(cubes, inputlevel) |
34 |
||
35 |
||
36 |
class TWStartHandler(CommandHandler): |
|
37 |
cmdname = 'start' |
|
38 |
cfgname = 'twisted' |
|
39 |
||
40 |
def start_command(self, config, debug): |
|
41 |
command = ['%s `which twistd`' % sys.executable] |
|
42 |
for ctl_opt, server_opt in (('pid-file', 'pidfile'), |
|
43 |
('uid', 'uid'), |
|
44 |
('log-file', 'logfile',)): |
|
45 |
value = config[ctl_opt] |
|
46 |
if not value or (debug and ctl_opt == 'log-file'): |
|
47 |
continue |
|
48 |
command.append('--%s %s' % (server_opt, value)) |
|
49 |
if debug: |
|
50 |
command.append('-n') |
|
51 |
if config['profile']: |
|
52 |
command.append('-p %s --savestats' % config['profile']) |
|
53 |
command.append('-oy') |
|
54 |
command.append(self.config.server_file()) |
|
55 |
return ' '.join(command) |
|
56 |
||
57 |
||
58 |
class TWStopHandler(CommandHandler): |
|
59 |
cmdname = 'stop' |
|
60 |
cfgname = 'twisted' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
61 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
62 |
|
0 | 63 |
try: |
64 |
from cubicweb.server import serverctl |
|
65 |
||
66 |
class AllInOneCreateHandler(serverctl.RepositoryCreateHandler, TWCreateHandler): |
|
67 |
"""configuration to get a web application running in a twisted web |
|
68 |
server integrating a repository server in the same process |
|
69 |
""" |
|
70 |
cfgname = 'all-in-one' |
|
71 |
||
72 |
def bootstrap(self, cubes, inputlevel=0): |
|
73 |
"""bootstrap this configuration""" |
|
74 |
serverctl.RepositoryCreateHandler.bootstrap(self, cubes, inputlevel) |
|
75 |
TWCreateHandler.bootstrap(self, cubes, inputlevel) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
76 |
|
0 | 77 |
class AllInOneStartHandler(TWStartHandler): |
78 |
cmdname = 'start' |
|
79 |
cfgname = 'all-in-one' |
|
80 |
subcommand = 'cubicweb-twisted' |
|
81 |
||
82 |
class AllInOneStopHandler(serverctl.RepositoryStopHandler): |
|
83 |
cmdname = 'stop' |
|
84 |
cfgname = 'all-in-one' |
|
85 |
subcommand = 'cubicweb-twisted' |
|
86 |
||
87 |
except ImportError: |
|
88 |
pass |