author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 08 Feb 2010 09:57:25 +0100 | |
branch | stable |
changeset 4488 | e8e7f6a0e7b6 |
parent 4212 | ab6573088b4a |
child 4252 | 6c4f109c2b03 |
permissions | -rw-r--r-- |
0 | 1 |
"""server.serverconfig definition |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3912
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 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:
1666
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
import os |
|
11 |
from os.path import join, exists |
|
12 |
||
3900
a26f50cb7e70
password is required, else we get obscure validation failure when inserting the admin user into cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3835
diff
changeset
|
13 |
from logilab.common.configuration import REQUIRED, Method, Configuration, \ |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
14 |
ini_format_section |
0 | 15 |
from logilab.common.decorators import wproperty, cached, clear_cache |
16 |
||
17 |
from cubicweb import CW_SOFTWARE_ROOT, RegistryNotFound |
|
3637 | 18 |
from cubicweb.toolsutils import read_config, restrict_perms_to_user |
0 | 19 |
from cubicweb.cwconfig import CubicWebConfiguration, merge_options |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
20 |
from cubicweb.server import SOURCE_TYPES |
0 | 21 |
|
22 |
||
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
23 |
USER_OPTIONS = ( |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
24 |
('login', {'type' : 'string', |
3835
a191b3b9e455
more sensible default values to c-c "create" inputs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
25 |
'default': 'admin', |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
26 |
'help': "cubicweb manager account's login " |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
27 |
'(this user will be created)', |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
28 |
'inputlevel': 0, |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
29 |
}), |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
30 |
('password', {'type' : 'password', |
3900
a26f50cb7e70
password is required, else we get obscure validation failure when inserting the admin user into cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3835
diff
changeset
|
31 |
'default': REQUIRED, |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
32 |
'help': "cubicweb manager account's password", |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
33 |
'inputlevel': 0, |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
34 |
}), |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
35 |
) |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
36 |
|
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
37 |
class SourceConfiguration(Configuration): |
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
38 |
def __init__(self, appid, options): |
3912
412eb366740b
set appid attribute before super call to avoid attribute error when fetching configuration's defaults
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3905
diff
changeset
|
39 |
self.appid = appid # has to be done before super call |
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
40 |
super(SourceConfiguration, self).__init__(options=options) |
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
41 |
|
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
42 |
# make Method('default_instance_id') usable in db option defs (in native.py) |
3905 | 43 |
def default_instance_id(self): |
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
44 |
return self.appid |
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
45 |
|
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
46 |
def generate_sources_file(appid, sourcesfile, sourcescfg, keys=None): |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
47 |
"""serialize repository'sources configuration into a INI like file |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
48 |
|
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
49 |
the `keys` parameter may be used to sort sections |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
50 |
""" |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
51 |
if keys is None: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
52 |
keys = sourcescfg.keys() |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
53 |
else: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
54 |
for key in sourcescfg: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
55 |
if not key in keys: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
56 |
keys.append(key) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
57 |
stream = open(sourcesfile, 'w') |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
58 |
for uri in keys: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
59 |
sconfig = sourcescfg[uri] |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
60 |
if isinstance(sconfig, dict): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
61 |
# get a Configuration object |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
62 |
if uri == 'admin': |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
63 |
options = USER_OPTIONS |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
64 |
else: |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
65 |
options = SOURCE_TYPES[sconfig['adapter']].options |
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
66 |
_sconfig = SourceConfiguration(appid, options=options) |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
67 |
for attr, val in sconfig.items(): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
68 |
if attr == 'uri': |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
69 |
continue |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
70 |
if attr == 'adapter': |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
71 |
_sconfig.adapter = val |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
72 |
else: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
73 |
_sconfig.set_option(attr, val) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
74 |
sconfig = _sconfig |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
75 |
optsbysect = list(sconfig.options_by_section()) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
76 |
assert len(optsbysect) == 1, 'all options for a source should be in the same group' |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
77 |
ini_format_section(stream, uri, optsbysect[0][1]) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
78 |
if hasattr(sconfig, 'adapter'): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
79 |
print >> stream |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
80 |
print >> stream, '# adapter for this source (YOU SHOULD NOT CHANGE THIS)' |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
81 |
print >> stream, 'adapter=%s' % sconfig.adapter |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
82 |
print >> stream |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
83 |
|
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
84 |
|
0 | 85 |
class ServerConfiguration(CubicWebConfiguration): |
86 |
"""standalone RQL server""" |
|
87 |
name = 'repository' |
|
88 |
||
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
89 |
cubicweb_appobject_path = CubicWebConfiguration.cubicweb_appobject_path | set(['sobjects']) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
90 |
cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['sobjects', 'hooks']) |
0 | 91 |
|
92 |
options = merge_options(( |
|
93 |
# ctl configuration |
|
94 |
('host', |
|
95 |
{'type' : 'string', |
|
96 |
'default': None, |
|
97 |
'help': 'host name if not correctly detectable through gethostname', |
|
98 |
'group': 'main', 'inputlevel': 1, |
|
99 |
}), |
|
100 |
('pid-file', |
|
101 |
{'type' : 'string', |
|
102 |
'default': Method('default_pid_file'), |
|
103 |
'help': 'repository\'s pid file', |
|
104 |
'group': 'main', 'inputlevel': 2, |
|
105 |
}), |
|
106 |
('uid', |
|
107 |
{'type' : 'string', |
|
108 |
'default': None, |
|
109 |
'help': 'if this option is set, use the specified user to start \ |
|
110 |
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
|
111 |
'group': 'main', 'inputlevel': (CubicWebConfiguration.mode == 'installed') and 0 or 1, |
0 | 112 |
}), |
113 |
('session-time', |
|
114 |
{'type' : 'int', |
|
115 |
'default': 30*60, |
|
116 |
'help': 'session expiration time, default to 30 minutes', |
|
117 |
'group': 'main', 'inputlevel': 1, |
|
118 |
}), |
|
119 |
('connections-pool-size', |
|
120 |
{'type' : 'int', |
|
121 |
'default': 4, |
|
122 |
'help': 'size of the connections pools. Each source supporting multiple \ |
|
123 |
connections will have this number of opened connections.', |
|
124 |
'group': 'main', 'inputlevel': 1, |
|
125 |
}), |
|
126 |
('rql-cache-size', |
|
127 |
{'type' : 'int', |
|
128 |
'default': 300, |
|
129 |
'help': 'size of the parsed rql cache size.', |
|
130 |
'group': 'main', 'inputlevel': 1, |
|
131 |
}), |
|
1160
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
132 |
('delay-full-text-indexation', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
133 |
{'type' : 'yn', 'default': False, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
134 |
'help': 'When full text indexation of entity has a too important cost' |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
135 |
' to be done when entity are added/modified by users, activate this ' |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
136 |
'option and setup a job using cubicweb-ctl db-rebuild-fti on your ' |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
137 |
'system (using cron for instance).', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
138 |
'group': 'main', 'inputlevel': 1, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
139 |
}), |
1666 | 140 |
|
0 | 141 |
# email configuration |
142 |
('default-recipients-mode', |
|
143 |
{'type' : 'choice', |
|
144 |
'choices' : ('default-dest-addrs', 'users', 'none'), |
|
145 |
'default': 'default-dest-addrs', |
|
146 |
'help': 'when a notification should be sent with no specific rules \ |
|
147 |
to find recipients, recipients will be found according to this mode. Available \ |
|
148 |
modes are "default-dest-addrs" (emails specified in the configuration \ |
|
149 |
variable with the same name), "users" (every users which has activated \ |
|
150 |
account with an email set), "none" (no notification).', |
|
151 |
'group': 'email', 'inputlevel': 1, |
|
152 |
}), |
|
153 |
('default-dest-addrs', |
|
154 |
{'type' : 'csv', |
|
155 |
'default': (), |
|
156 |
'help': 'comma separated list of email addresses that will be used \ |
|
157 |
as default recipient when an email is sent and the notification has no \ |
|
158 |
specific recipient rules.', |
|
159 |
'group': 'email', 'inputlevel': 1, |
|
160 |
}), |
|
161 |
('supervising-addrs', |
|
162 |
{'type' : 'csv', |
|
163 |
'default': (), |
|
164 |
'help': 'comma separated list of email addresses that will be \ |
|
165 |
notified of every changes.', |
|
166 |
'group': 'email', 'inputlevel': 2, |
|
167 |
}), |
|
168 |
# pyro server.serverconfig |
|
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
169 |
('pyro-host', |
3547
0c18a6c8d9b7
fix pyro-host option type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
170 |
{'type' : 'string', |
0 | 171 |
'default': None, |
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
172 |
'help': 'Pyro server host, if not detectable correctly through \ |
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
173 |
gethostname(). It may contains port information using <host>:<port> notation, \ |
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
174 |
and if not set, it will be choosen randomly', |
3539
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2959
diff
changeset
|
175 |
'group': 'pyro', 'inputlevel': 2, |
0 | 176 |
}), |
177 |
) + CubicWebConfiguration.options) |
|
1666 | 178 |
|
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
179 |
# should we open connections pools (eg connect to sources). This is usually |
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
180 |
# necessary... |
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
181 |
open_connections_pools = True |
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
182 |
|
0 | 183 |
# read the schema from the database |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
184 |
read_instance_schema = True |
0 | 185 |
bootstrap_schema = True |
1666 | 186 |
|
0 | 187 |
# check user's state at login time |
188 |
consider_user_state = True |
|
1666 | 189 |
|
0 | 190 |
# hooks registration configuration |
191 |
# all hooks should be activated during normal execution |
|
192 |
core_hooks = True |
|
193 |
usergroup_hooks = True |
|
194 |
schema_hooks = True |
|
195 |
notification_hooks = True |
|
196 |
security_hooks = True |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
197 |
instance_hooks = True |
0 | 198 |
|
199 |
# should some hooks be deactivated during [pre|post]create script execution |
|
200 |
free_wheel = False |
|
1666 | 201 |
|
0 | 202 |
# list of enables sources when sources restriction is necessary |
203 |
# (eg repository initialization at least) |
|
204 |
_enabled_sources = None |
|
205 |
@wproperty |
|
206 |
def enabled_sources(self, sourceuris=None): |
|
207 |
self._enabled_sources = sourceuris |
|
208 |
clear_cache(self, 'sources') |
|
1666 | 209 |
|
0 | 210 |
def bootstrap_cubes(self): |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
211 |
from logilab.common.textutils import splitstrip |
0 | 212 |
for line in file(join(self.apphome, 'bootstrap_cubes')): |
213 |
line = line.strip() |
|
214 |
if not line or line.startswith('#'): |
|
215 |
continue |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
216 |
self.init_cubes(self.expand_cubes(splitstrip(line))) |
0 | 217 |
break |
218 |
else: |
|
219 |
# no cubes |
|
220 |
self.init_cubes(()) |
|
1666 | 221 |
|
0 | 222 |
def write_bootstrap_cubes_file(self, cubes): |
223 |
stream = file(join(self.apphome, 'bootstrap_cubes'), 'w') |
|
224 |
stream.write('# this is a generated file only used for bootstraping\n') |
|
225 |
stream.write('# you should not have to edit this\n') |
|
226 |
stream.write('%s\n' % ','.join(cubes)) |
|
227 |
stream.close() |
|
1666 | 228 |
|
0 | 229 |
def sources_file(self): |
230 |
return join(self.apphome, 'sources') |
|
1666 | 231 |
|
0 | 232 |
# this method has to be cached since when the server is running using a |
233 |
# restricted user, this user usually don't have access to the sources |
|
234 |
# configuration file (#16102) |
|
235 |
@cached |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
236 |
def read_sources_file(self): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
237 |
return read_config(self.sources_file()) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
238 |
|
0 | 239 |
def sources(self): |
240 |
"""return a dictionnaries containing sources definitions indexed by |
|
241 |
sources'uri |
|
242 |
""" |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
243 |
allsources = self.read_sources_file() |
0 | 244 |
if self._enabled_sources is None: |
245 |
return allsources |
|
246 |
return dict((uri, config) for uri, config in allsources.items() |
|
247 |
if uri in self._enabled_sources or uri == 'admin') |
|
1666 | 248 |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
249 |
def write_sources_file(self, sourcescfg): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
250 |
sourcesfile = self.sources_file() |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
251 |
if exists(sourcesfile): |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
252 |
import shutil |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
253 |
shutil.copy(sourcesfile, sourcesfile + '.bak') |
3904
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
254 |
generate_sources_file(self.appid, sourcesfile, sourcescfg, |
dc7d315165fc
default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3900
diff
changeset
|
255 |
['admin', 'system']) |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
256 |
restrict_perms_to_user(sourcesfile) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
257 |
|
0 | 258 |
def pyro_enabled(self): |
259 |
"""pyro is always enabled in standalone repository configuration""" |
|
260 |
return True |
|
1666 | 261 |
|
0 | 262 |
def load_hooks(self, vreg): |
263 |
hooks = {} |
|
264 |
try: |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
265 |
apphookdefs = vreg['hooks'].all_objects() |
0 | 266 |
except RegistryNotFound: |
267 |
return hooks |
|
268 |
for hookdef in apphookdefs: |
|
269 |
for event, ertype in hookdef.register_to(): |
|
270 |
if ertype == 'Any': |
|
271 |
ertype = '' |
|
272 |
cb = hookdef.make_callback(event) |
|
273 |
hooks.setdefault(event, {}).setdefault(ertype, []).append(cb) |
|
274 |
return hooks |
|
1666 | 275 |
|
276 |
def load_schema(self, expand_cubes=False, **kwargs): |
|
0 | 277 |
from cubicweb.schema import CubicWebSchemaLoader |
278 |
if expand_cubes: |
|
279 |
# in case some new dependencies have been introduced, we have to |
|
280 |
# reinitialize cubes so the full filesystem schema is read |
|
281 |
origcubes = self.cubes() |
|
282 |
self._cubes = None |
|
283 |
self.init_cubes(self.expand_cubes(origcubes)) |
|
1666 | 284 |
schema = CubicWebSchemaLoader().load(self, **kwargs) |
0 | 285 |
if expand_cubes: |
286 |
# restaure original value |
|
287 |
self._cubes = origcubes |
|
288 |
return schema |
|
1666 | 289 |
|
0 | 290 |
def load_bootstrap_schema(self): |
291 |
from cubicweb.schema import BootstrapSchemaLoader |
|
292 |
schema = BootstrapSchemaLoader().load(self) |
|
293 |
schema.name = 'bootstrap' |
|
294 |
return schema |
|
1666 | 295 |
|
0 | 296 |
def set_sources_mode(self, sources): |
297 |
if 'migration' in sources: |
|
298 |
from cubicweb.server.sources import source_adapter |
|
299 |
assert len(sources) == 1 |
|
300 |
enabled_sources = [] |
|
301 |
for uri, config in self.sources().iteritems(): |
|
302 |
if uri == 'admin': |
|
303 |
continue |
|
304 |
if source_adapter(config).connect_for_migration: |
|
305 |
enabled_sources.append(uri) |
|
306 |
else: |
|
307 |
print 'not connecting to source', uri, 'during migration' |
|
308 |
elif 'all' in sources: |
|
309 |
assert len(sources) == 1 |
|
1133 | 310 |
enabled_sources = None |
0 | 311 |
else: |
312 |
known_sources = self.sources() |
|
313 |
for uri in sources: |
|
314 |
assert uri in known_sources, uri |
|
315 |
enabled_sources = sources |
|
316 |
self._enabled_sources = enabled_sources |
|
317 |
clear_cache(self, 'sources') |
|
1666 | 318 |
|
0 | 319 |
def migration_handler(self, schema=None, interactive=True, |
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
320 |
cnx=None, repo=None, connect=True, verbosity=None): |
0 | 321 |
"""return a migration handler instance""" |
322 |
from cubicweb.server.migractions import ServerMigrationHelper |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
323 |
if verbosity is None: |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
324 |
verbosity = getattr(self, 'verbosity', 0) |
0 | 325 |
return ServerMigrationHelper(self, schema, interactive=interactive, |
326 |
cnx=cnx, repo=repo, connect=connect, |
|
2493
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
327 |
verbosity=verbosity) |