author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 14 May 2009 16:32:20 +0200 | |
changeset 1827 | 93840d187f26 |
parent 1802 | d628defebc17 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
"""twisted server configurations: |
2 |
||
3 |
* the "twisted" configuration to get a web application running in a standalone |
|
4 |
twisted web server which talk to a repository server using Pyro |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
136
diff
changeset
|
5 |
|
0 | 6 |
* the "all-in-one" configuration to get a web application running in a twisted |
7 |
web server integrating a repository server in the same process (only available |
|
8 |
if the repository part of the software is installed |
|
9 |
||
10 |
:organization: Logilab |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
136
diff
changeset
|
11 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 12 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
13 |
""" |
|
14 |
__docformat__ = "restructuredtext en" |
|
15 |
||
16 |
from os.path import join |
|
17 |
||
18 |
from cubicweb.web.webconfig import WebConfiguration, merge_options, Method |
|
19 |
||
20 |
class TwistedConfiguration(WebConfiguration): |
|
21 |
"""web application (in a twisted web server) client of a RQL server""" |
|
22 |
name = 'twisted' |
|
23 |
||
24 |
options = merge_options(( |
|
25 |
# ctl configuration |
|
26 |
('host', |
|
27 |
{'type' : 'string', |
|
28 |
'default': None, |
|
29 |
'help': 'host name if not correctly detectable through gethostname', |
|
30 |
'group': 'main', 'inputlevel': 1, |
|
31 |
}), |
|
32 |
('port', |
|
33 |
{'type' : 'int', |
|
34 |
'default': None, |
|
35 |
'help': 'http server port number (default to 8080)', |
|
36 |
'group': 'main', 'inputlevel': 0, |
|
37 |
}), |
|
38 |
('pid-file', |
|
39 |
{'type' : 'string', |
|
40 |
'default': Method('default_pid_file'), |
|
41 |
'help': 'repository\'s pid file', |
|
42 |
'group': 'main', 'inputlevel': 2, |
|
43 |
}), |
|
44 |
('uid', |
|
45 |
{'type' : 'string', |
|
46 |
'default': None, |
|
47 |
'help': 'if this option is set, use the specified user to start \ |
|
48 |
the repository rather than the user running the command', |
|
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
49 |
'group': 'main', 'inputlevel': (WebConfiguration.mode == 'installed') and 0 or 1, |
0 | 50 |
}), |
51 |
('session-time', |
|
52 |
{'type' : 'int', |
|
53 |
'default': 30*60, |
|
54 |
'help': 'session expiration time, default to 30 minutes', |
|
55 |
'group': 'main', 'inputlevel': 1, |
|
56 |
}), |
|
57 |
('profile', |
|
58 |
{'type' : 'string', |
|
59 |
'default': None, |
|
60 |
'help': 'profile code and use the specified file to store stats if this option is set', |
|
61 |
'group': 'main', 'inputlevel': 2, |
|
62 |
}), |
|
63 |
('pyro-server', |
|
64 |
{'type' : 'yn', |
|
65 |
# pyro is only a recommends by default, so don't activate it here |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
136
diff
changeset
|
66 |
'default': False, |
0 | 67 |
'help': 'run a pyro server', |
68 |
'group': 'main', 'inputlevel': 1, |
|
69 |
}), |
|
70 |
) + WebConfiguration.options) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
136
diff
changeset
|
71 |
|
0 | 72 |
def server_file(self): |
73 |
return join(self.apphome, '%s-%s.py' % (self.appid, self.name)) |
|
74 |
||
75 |
def default_base_url(self): |
|
76 |
from socket import gethostname |
|
77 |
return 'http://%s:%s/' % (self['host'] or gethostname(), self['port'] or 8080) |
|
78 |
||
79 |
try: |
|
80 |
from cubicweb.server.serverconfig import ServerConfiguration |
|
81 |
||
82 |
class AllInOneConfiguration(TwistedConfiguration, ServerConfiguration): |
|
83 |
"""repository and web application in the same twisted process""" |
|
84 |
name = 'all-in-one' |
|
85 |
repo_method = 'inmemory' |
|
86 |
options = merge_options(TwistedConfiguration.options |
|
87 |
+ ServerConfiguration.options) |
|
88 |
||
89 |
cubicweb_vobject_path = TwistedConfiguration.cubicweb_vobject_path | ServerConfiguration.cubicweb_vobject_path |
|
90 |
cube_vobject_path = TwistedConfiguration.cube_vobject_path | ServerConfiguration.cube_vobject_path |
|
91 |
def pyro_enabled(self): |
|
92 |
"""tell if pyro is activated for the in memory repository""" |
|
93 |
return self['pyro-server'] |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
136
diff
changeset
|
94 |
|
0 | 95 |
except ImportError: |
96 |
pass |