author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Thu, 05 Nov 2009 12:44:24 +0100 | |
branch | stable |
changeset 3798 | d2c27621cc81 |
parent 3638 | 648d6dbec630 |
child 3674 | 387d51af966d |
child 3835 | a191b3b9e455 |
permissions | -rw-r--r-- |
0 | 1 |
"""server.serverconfig definition |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1666
diff
changeset
|
4 |
:copyright: 2001-2009 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 |
||
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
|
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', |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
25 |
'default': REQUIRED, |
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', |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
31 |
'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
|
32 |
'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
|
33 |
}), |
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 |
|
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
|
36 |
def generate_sources_file(sourcesfile, sourcescfg, keys=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
|
37 |
"""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
|
38 |
|
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
39 |
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
|
40 |
""" |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
# 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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
options = SOURCE_TYPES[sconfig['adapter']].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
|
56 |
_sconfig = Configuration(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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
_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
|
62 |
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
|
63 |
_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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
|
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 |
|
0 | 75 |
class ServerConfiguration(CubicWebConfiguration): |
76 |
"""standalone RQL server""" |
|
77 |
name = 'repository' |
|
78 |
||
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
79 |
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
|
80 |
cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['sobjects', 'hooks']) |
0 | 81 |
|
82 |
options = merge_options(( |
|
83 |
# ctl configuration |
|
84 |
('host', |
|
85 |
{'type' : 'string', |
|
86 |
'default': None, |
|
87 |
'help': 'host name if not correctly detectable through gethostname', |
|
88 |
'group': 'main', 'inputlevel': 1, |
|
89 |
}), |
|
90 |
('pid-file', |
|
91 |
{'type' : 'string', |
|
92 |
'default': Method('default_pid_file'), |
|
93 |
'help': 'repository\'s pid file', |
|
94 |
'group': 'main', 'inputlevel': 2, |
|
95 |
}), |
|
96 |
('uid', |
|
97 |
{'type' : 'string', |
|
98 |
'default': None, |
|
99 |
'help': 'if this option is set, use the specified user to start \ |
|
100 |
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
|
101 |
'group': 'main', 'inputlevel': (CubicWebConfiguration.mode == 'installed') and 0 or 1, |
0 | 102 |
}), |
103 |
('session-time', |
|
104 |
{'type' : 'int', |
|
105 |
'default': 30*60, |
|
106 |
'help': 'session expiration time, default to 30 minutes', |
|
107 |
'group': 'main', 'inputlevel': 1, |
|
108 |
}), |
|
109 |
('connections-pool-size', |
|
110 |
{'type' : 'int', |
|
111 |
'default': 4, |
|
112 |
'help': 'size of the connections pools. Each source supporting multiple \ |
|
113 |
connections will have this number of opened connections.', |
|
114 |
'group': 'main', 'inputlevel': 1, |
|
115 |
}), |
|
116 |
('rql-cache-size', |
|
117 |
{'type' : 'int', |
|
118 |
'default': 300, |
|
119 |
'help': 'size of the parsed rql cache size.', |
|
120 |
'group': 'main', 'inputlevel': 1, |
|
121 |
}), |
|
1160
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
122 |
('delay-full-text-indexation', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
123 |
{'type' : 'yn', 'default': False, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
124 |
'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
|
125 |
' 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
|
126 |
'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
|
127 |
'system (using cron for instance).', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
128 |
'group': 'main', 'inputlevel': 1, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
129 |
}), |
1666 | 130 |
|
0 | 131 |
# email configuration |
132 |
('default-recipients-mode', |
|
133 |
{'type' : 'choice', |
|
134 |
'choices' : ('default-dest-addrs', 'users', 'none'), |
|
135 |
'default': 'default-dest-addrs', |
|
136 |
'help': 'when a notification should be sent with no specific rules \ |
|
137 |
to find recipients, recipients will be found according to this mode. Available \ |
|
138 |
modes are "default-dest-addrs" (emails specified in the configuration \ |
|
139 |
variable with the same name), "users" (every users which has activated \ |
|
140 |
account with an email set), "none" (no notification).', |
|
141 |
'group': 'email', 'inputlevel': 1, |
|
142 |
}), |
|
143 |
('default-dest-addrs', |
|
144 |
{'type' : 'csv', |
|
145 |
'default': (), |
|
146 |
'help': 'comma separated list of email addresses that will be used \ |
|
147 |
as default recipient when an email is sent and the notification has no \ |
|
148 |
specific recipient rules.', |
|
149 |
'group': 'email', 'inputlevel': 1, |
|
150 |
}), |
|
151 |
('supervising-addrs', |
|
152 |
{'type' : 'csv', |
|
153 |
'default': (), |
|
154 |
'help': 'comma separated list of email addresses that will be \ |
|
155 |
notified of every changes.', |
|
156 |
'group': 'email', 'inputlevel': 2, |
|
157 |
}), |
|
158 |
# 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
|
159 |
('pyro-host', |
3547
0c18a6c8d9b7
fix pyro-host option type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
160 |
{'type' : 'string', |
0 | 161 |
'default': None, |
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
162 |
'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
|
163 |
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
|
164 |
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
|
165 |
'group': 'pyro', 'inputlevel': 2, |
0 | 166 |
}), |
167 |
) + CubicWebConfiguration.options) |
|
1666 | 168 |
|
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
169 |
# 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
|
170 |
# necessary... |
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
171 |
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
|
172 |
|
0 | 173 |
# 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
|
174 |
read_instance_schema = True |
0 | 175 |
bootstrap_schema = True |
1666 | 176 |
|
0 | 177 |
# check user's state at login time |
178 |
consider_user_state = True |
|
1666 | 179 |
|
0 | 180 |
# hooks registration configuration |
181 |
# all hooks should be activated during normal execution |
|
182 |
core_hooks = True |
|
183 |
usergroup_hooks = True |
|
184 |
schema_hooks = True |
|
185 |
notification_hooks = True |
|
186 |
security_hooks = True |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
187 |
instance_hooks = True |
0 | 188 |
|
189 |
# should some hooks be deactivated during [pre|post]create script execution |
|
190 |
free_wheel = False |
|
1666 | 191 |
|
0 | 192 |
# list of enables sources when sources restriction is necessary |
193 |
# (eg repository initialization at least) |
|
194 |
_enabled_sources = None |
|
195 |
@wproperty |
|
196 |
def enabled_sources(self, sourceuris=None): |
|
197 |
self._enabled_sources = sourceuris |
|
198 |
clear_cache(self, 'sources') |
|
1666 | 199 |
|
0 | 200 |
def bootstrap_cubes(self): |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
201 |
from logilab.common.textutils import splitstrip |
0 | 202 |
for line in file(join(self.apphome, 'bootstrap_cubes')): |
203 |
line = line.strip() |
|
204 |
if not line or line.startswith('#'): |
|
205 |
continue |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
206 |
self.init_cubes(self.expand_cubes(splitstrip(line))) |
0 | 207 |
break |
208 |
else: |
|
209 |
# no cubes |
|
210 |
self.init_cubes(()) |
|
1666 | 211 |
|
0 | 212 |
def write_bootstrap_cubes_file(self, cubes): |
213 |
stream = file(join(self.apphome, 'bootstrap_cubes'), 'w') |
|
214 |
stream.write('# this is a generated file only used for bootstraping\n') |
|
215 |
stream.write('# you should not have to edit this\n') |
|
216 |
stream.write('%s\n' % ','.join(cubes)) |
|
217 |
stream.close() |
|
1666 | 218 |
|
0 | 219 |
def sources_file(self): |
220 |
return join(self.apphome, 'sources') |
|
1666 | 221 |
|
0 | 222 |
# this method has to be cached since when the server is running using a |
223 |
# restricted user, this user usually don't have access to the sources |
|
224 |
# configuration file (#16102) |
|
225 |
@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
|
226 |
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
|
227 |
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
|
228 |
|
0 | 229 |
def sources(self): |
230 |
"""return a dictionnaries containing sources definitions indexed by |
|
231 |
sources'uri |
|
232 |
""" |
|
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
|
233 |
allsources = self.read_sources_file() |
0 | 234 |
if self._enabled_sources is None: |
235 |
return allsources |
|
236 |
return dict((uri, config) for uri, config in allsources.items() |
|
237 |
if uri in self._enabled_sources or uri == 'admin') |
|
1666 | 238 |
|
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
shutil.copy(sourcesfile, sourcesfile + '.bak') |
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
|
244 |
generate_sources_file(sourcesfile, sourcescfg, ['admin', 'system']) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
245 |
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
|
246 |
|
0 | 247 |
def pyro_enabled(self): |
248 |
"""pyro is always enabled in standalone repository configuration""" |
|
249 |
return True |
|
1666 | 250 |
|
0 | 251 |
def load_hooks(self, vreg): |
252 |
hooks = {} |
|
253 |
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
|
254 |
apphookdefs = vreg['hooks'].all_objects() |
0 | 255 |
except RegistryNotFound: |
256 |
return hooks |
|
257 |
for hookdef in apphookdefs: |
|
258 |
for event, ertype in hookdef.register_to(): |
|
259 |
if ertype == 'Any': |
|
260 |
ertype = '' |
|
261 |
cb = hookdef.make_callback(event) |
|
262 |
hooks.setdefault(event, {}).setdefault(ertype, []).append(cb) |
|
263 |
return hooks |
|
1666 | 264 |
|
265 |
def load_schema(self, expand_cubes=False, **kwargs): |
|
0 | 266 |
from cubicweb.schema import CubicWebSchemaLoader |
267 |
if expand_cubes: |
|
268 |
# in case some new dependencies have been introduced, we have to |
|
269 |
# reinitialize cubes so the full filesystem schema is read |
|
270 |
origcubes = self.cubes() |
|
271 |
self._cubes = None |
|
272 |
self.init_cubes(self.expand_cubes(origcubes)) |
|
1666 | 273 |
schema = CubicWebSchemaLoader().load(self, **kwargs) |
0 | 274 |
if expand_cubes: |
275 |
# restaure original value |
|
276 |
self._cubes = origcubes |
|
277 |
return schema |
|
1666 | 278 |
|
0 | 279 |
def load_bootstrap_schema(self): |
280 |
from cubicweb.schema import BootstrapSchemaLoader |
|
281 |
schema = BootstrapSchemaLoader().load(self) |
|
282 |
schema.name = 'bootstrap' |
|
283 |
return schema |
|
1666 | 284 |
|
0 | 285 |
def set_sources_mode(self, sources): |
286 |
if 'migration' in sources: |
|
287 |
from cubicweb.server.sources import source_adapter |
|
288 |
assert len(sources) == 1 |
|
289 |
enabled_sources = [] |
|
290 |
for uri, config in self.sources().iteritems(): |
|
291 |
if uri == 'admin': |
|
292 |
continue |
|
293 |
if source_adapter(config).connect_for_migration: |
|
294 |
enabled_sources.append(uri) |
|
295 |
else: |
|
296 |
print 'not connecting to source', uri, 'during migration' |
|
297 |
elif 'all' in sources: |
|
298 |
assert len(sources) == 1 |
|
1133 | 299 |
enabled_sources = None |
0 | 300 |
else: |
301 |
known_sources = self.sources() |
|
302 |
for uri in sources: |
|
303 |
assert uri in known_sources, uri |
|
304 |
enabled_sources = sources |
|
305 |
self._enabled_sources = enabled_sources |
|
306 |
clear_cache(self, 'sources') |
|
1666 | 307 |
|
0 | 308 |
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
|
309 |
cnx=None, repo=None, connect=True, verbosity=None): |
0 | 310 |
"""return a migration handler instance""" |
311 |
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
|
312 |
if verbosity is None: |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
313 |
verbosity = getattr(self, 'verbosity', 0) |
0 | 314 |
return ServerMigrationHelper(self, schema, interactive=interactive, |
315 |
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
|
316 |
verbosity=verbosity) |