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