author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 24 Jul 2009 14:33:37 +0200 | |
changeset 2476 | 1294a6bdf3bf |
parent 2395 | e3093fc12a00 |
child 2654 | 6512522860aa |
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): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2395
diff
changeset
|
67 |
"""configuration to get an instance running in a twisted web server |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2395
diff
changeset
|
68 |
integrating a repository server in the same process |
0 | 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 |