author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 14 May 2009 11:38:40 +0200 | |
branch | tls-sprint |
changeset 1802 | d628defebc17 |
parent 0 | b97547f5f1fa |
child 1977 | 606923dff11b |
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 |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
0 | 6 |
""" |
7 |
||
8 |
import sys |
|
9 |
||
10 |
from cubicweb.toolsutils import CommandHandler |
|
11 |
from cubicweb.web.webctl import WebCreateHandler |
|
12 |
||
13 |
# trigger configuration registration |
|
14 |
import cubicweb.etwist.twconfig # pylint: disable-msg=W0611 |
|
15 |
||
16 |
||
17 |
class TWCreateHandler(WebCreateHandler): |
|
18 |
cfgname = 'twisted' |
|
19 |
||
20 |
def bootstrap(self, cubes, inputlevel=0): |
|
21 |
"""bootstrap this configuration""" |
|
22 |
print '** twisted configuration' |
|
23 |
mainpyfile = self.config.server_file() |
|
24 |
mainpy = open(mainpyfile, 'w') |
|
25 |
mainpy.write(''' |
|
26 |
from cubicweb.etwist import server |
|
27 |
application = server.main(%r, %r) |
|
28 |
''' % (self.config.appid, self.config.name)) |
|
29 |
mainpy.close() |
|
30 |
print 'application\'s twisted file %s generated' % mainpyfile |
|
31 |
super(TWCreateHandler, self).bootstrap(cubes, inputlevel) |
|
32 |
||
33 |
||
34 |
class TWStartHandler(CommandHandler): |
|
35 |
cmdname = 'start' |
|
36 |
cfgname = 'twisted' |
|
37 |
||
38 |
def start_command(self, config, debug): |
|
39 |
command = ['%s `which twistd`' % sys.executable] |
|
40 |
for ctl_opt, server_opt in (('pid-file', 'pidfile'), |
|
41 |
('uid', 'uid'), |
|
42 |
('log-file', 'logfile',)): |
|
43 |
value = config[ctl_opt] |
|
44 |
if not value or (debug and ctl_opt == 'log-file'): |
|
45 |
continue |
|
46 |
command.append('--%s %s' % (server_opt, value)) |
|
47 |
if debug: |
|
48 |
command.append('-n') |
|
49 |
if config['profile']: |
|
50 |
command.append('-p %s --savestats' % config['profile']) |
|
51 |
command.append('-oy') |
|
52 |
command.append(self.config.server_file()) |
|
53 |
return ' '.join(command) |
|
54 |
||
55 |
||
56 |
class TWStopHandler(CommandHandler): |
|
57 |
cmdname = 'stop' |
|
58 |
cfgname = 'twisted' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
59 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
60 |
|
0 | 61 |
try: |
62 |
from cubicweb.server import serverctl |
|
63 |
||
64 |
class AllInOneCreateHandler(serverctl.RepositoryCreateHandler, TWCreateHandler): |
|
65 |
"""configuration to get a web application running in a twisted web |
|
66 |
server integrating a repository server in the same process |
|
67 |
""" |
|
68 |
cfgname = 'all-in-one' |
|
69 |
||
70 |
def bootstrap(self, cubes, inputlevel=0): |
|
71 |
"""bootstrap this configuration""" |
|
72 |
serverctl.RepositoryCreateHandler.bootstrap(self, cubes, inputlevel) |
|
73 |
TWCreateHandler.bootstrap(self, cubes, inputlevel) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
74 |
|
0 | 75 |
class AllInOneStartHandler(TWStartHandler): |
76 |
cmdname = 'start' |
|
77 |
cfgname = 'all-in-one' |
|
78 |
subcommand = 'cubicweb-twisted' |
|
79 |
||
80 |
class AllInOneStopHandler(serverctl.RepositoryStopHandler): |
|
81 |
cmdname = 'stop' |
|
82 |
cfgname = 'all-in-one' |
|
83 |
subcommand = 'cubicweb-twisted' |
|
84 |
||
85 |
except ImportError: |
|
86 |
pass |