author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 17 Aug 2009 10:31:28 +0200 | |
branch | stable |
changeset 2870 | e3a5b7c3f767 |
parent 2730 | bb6fcb8c5d71 |
child 2809 | 04fa75d43af4 |
child 2959 | daabb9bc5233 |
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 |
|
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
|
18 |
from cubicweb.toolsutils import env_path, 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 |
if os.environ.get('APYCOT_ROOT'): |
|
79 |
root = os.environ['APYCOT_ROOT'] |
|
80 |
elif CubicWebConfiguration.mode == 'dev': |
|
81 |
BACKUP_DIR = CubicWebConfiguration.RUNTIME_DIR |
|
82 |
else: |
|
83 |
BACKUP_DIR = '/var/lib/cubicweb/backup/' |
|
84 |
||
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
85 |
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
|
86 |
cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['sobjects', 'hooks']) |
0 | 87 |
|
88 |
options = merge_options(( |
|
89 |
# ctl configuration |
|
90 |
('host', |
|
91 |
{'type' : 'string', |
|
92 |
'default': None, |
|
93 |
'help': 'host name if not correctly detectable through gethostname', |
|
94 |
'group': 'main', 'inputlevel': 1, |
|
95 |
}), |
|
96 |
('pid-file', |
|
97 |
{'type' : 'string', |
|
98 |
'default': Method('default_pid_file'), |
|
99 |
'help': 'repository\'s pid file', |
|
100 |
'group': 'main', 'inputlevel': 2, |
|
101 |
}), |
|
102 |
('uid', |
|
103 |
{'type' : 'string', |
|
104 |
'default': None, |
|
105 |
'help': 'if this option is set, use the specified user to start \ |
|
106 |
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
|
107 |
'group': 'main', 'inputlevel': (CubicWebConfiguration.mode == 'installed') and 0 or 1, |
0 | 108 |
}), |
109 |
('session-time', |
|
110 |
{'type' : 'int', |
|
111 |
'default': 30*60, |
|
112 |
'help': 'session expiration time, default to 30 minutes', |
|
113 |
'group': 'main', 'inputlevel': 1, |
|
114 |
}), |
|
115 |
('connections-pool-size', |
|
116 |
{'type' : 'int', |
|
117 |
'default': 4, |
|
118 |
'help': 'size of the connections pools. Each source supporting multiple \ |
|
119 |
connections will have this number of opened connections.', |
|
120 |
'group': 'main', 'inputlevel': 1, |
|
121 |
}), |
|
122 |
('rql-cache-size', |
|
123 |
{'type' : 'int', |
|
124 |
'default': 300, |
|
125 |
'help': 'size of the parsed rql cache size.', |
|
126 |
'group': 'main', 'inputlevel': 1, |
|
127 |
}), |
|
1160
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
128 |
('delay-full-text-indexation', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
129 |
{'type' : 'yn', 'default': False, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
130 |
'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
|
131 |
' 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
|
132 |
'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
|
133 |
'system (using cron for instance).', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
134 |
'group': 'main', 'inputlevel': 1, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
135 |
}), |
1666 | 136 |
|
0 | 137 |
# email configuration |
138 |
('default-recipients-mode', |
|
139 |
{'type' : 'choice', |
|
140 |
'choices' : ('default-dest-addrs', 'users', 'none'), |
|
141 |
'default': 'default-dest-addrs', |
|
142 |
'help': 'when a notification should be sent with no specific rules \ |
|
143 |
to find recipients, recipients will be found according to this mode. Available \ |
|
144 |
modes are "default-dest-addrs" (emails specified in the configuration \ |
|
145 |
variable with the same name), "users" (every users which has activated \ |
|
146 |
account with an email set), "none" (no notification).', |
|
147 |
'group': 'email', 'inputlevel': 1, |
|
148 |
}), |
|
149 |
('default-dest-addrs', |
|
150 |
{'type' : 'csv', |
|
151 |
'default': (), |
|
152 |
'help': 'comma separated list of email addresses that will be used \ |
|
153 |
as default recipient when an email is sent and the notification has no \ |
|
154 |
specific recipient rules.', |
|
155 |
'group': 'email', 'inputlevel': 1, |
|
156 |
}), |
|
157 |
('supervising-addrs', |
|
158 |
{'type' : 'csv', |
|
159 |
'default': (), |
|
160 |
'help': 'comma separated list of email addresses that will be \ |
|
161 |
notified of every changes.', |
|
162 |
'group': 'email', 'inputlevel': 2, |
|
163 |
}), |
|
164 |
# 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
|
165 |
('pyro-host', |
0 | 166 |
{'type' : 'int', |
167 |
'default': None, |
|
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
168 |
'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
|
169 |
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
|
170 |
and if not set, it will be choosen randomly', |
0 | 171 |
'group': 'pyro-server', 'inputlevel': 2, |
172 |
}), |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
173 |
('pyro-id', # XXX reuse pyro-instance-id |
0 | 174 |
{'type' : 'string', |
175 |
'default': None, |
|
176 |
'help': 'identifier of the repository in the pyro name server', |
|
177 |
'group': 'pyro-server', 'inputlevel': 2, |
|
178 |
}), |
|
179 |
) + CubicWebConfiguration.options) |
|
1666 | 180 |
|
0 | 181 |
# 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
|
182 |
read_instance_schema = True |
0 | 183 |
bootstrap_schema = True |
1666 | 184 |
|
0 | 185 |
# check user's state at login time |
186 |
consider_user_state = True |
|
1666 | 187 |
|
0 | 188 |
# hooks registration configuration |
189 |
# all hooks should be activated during normal execution |
|
190 |
core_hooks = True |
|
191 |
usergroup_hooks = True |
|
192 |
schema_hooks = True |
|
193 |
notification_hooks = True |
|
194 |
security_hooks = True |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2107
diff
changeset
|
195 |
instance_hooks = True |
0 | 196 |
|
197 |
# should some hooks be deactivated during [pre|post]create script execution |
|
198 |
free_wheel = False |
|
1666 | 199 |
|
0 | 200 |
# list of enables sources when sources restriction is necessary |
201 |
# (eg repository initialization at least) |
|
202 |
_enabled_sources = None |
|
203 |
@wproperty |
|
204 |
def enabled_sources(self, sourceuris=None): |
|
205 |
self._enabled_sources = sourceuris |
|
206 |
clear_cache(self, 'sources') |
|
1666 | 207 |
|
0 | 208 |
def bootstrap_cubes(self): |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
209 |
from logilab.common.textutils import splitstrip |
0 | 210 |
for line in file(join(self.apphome, 'bootstrap_cubes')): |
211 |
line = line.strip() |
|
212 |
if not line or line.startswith('#'): |
|
213 |
continue |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
214 |
self.init_cubes(self.expand_cubes(splitstrip(line))) |
0 | 215 |
break |
216 |
else: |
|
217 |
# no cubes |
|
218 |
self.init_cubes(()) |
|
1666 | 219 |
|
0 | 220 |
def write_bootstrap_cubes_file(self, cubes): |
221 |
stream = file(join(self.apphome, 'bootstrap_cubes'), 'w') |
|
222 |
stream.write('# this is a generated file only used for bootstraping\n') |
|
223 |
stream.write('# you should not have to edit this\n') |
|
224 |
stream.write('%s\n' % ','.join(cubes)) |
|
225 |
stream.close() |
|
1666 | 226 |
|
0 | 227 |
def sources_file(self): |
228 |
return join(self.apphome, 'sources') |
|
1666 | 229 |
|
0 | 230 |
# this method has to be cached since when the server is running using a |
231 |
# restricted user, this user usually don't have access to the sources |
|
232 |
# configuration file (#16102) |
|
233 |
@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
|
234 |
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
|
235 |
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
|
236 |
|
0 | 237 |
def sources(self): |
238 |
"""return a dictionnaries containing sources definitions indexed by |
|
239 |
sources'uri |
|
240 |
""" |
|
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
|
241 |
allsources = self.read_sources_file() |
0 | 242 |
if self._enabled_sources is None: |
243 |
return allsources |
|
244 |
return dict((uri, config) for uri, config in allsources.items() |
|
245 |
if uri in self._enabled_sources or uri == 'admin') |
|
1666 | 246 |
|
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
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
|
0 | 255 |
def pyro_enabled(self): |
256 |
"""pyro is always enabled in standalone repository configuration""" |
|
257 |
return True |
|
1666 | 258 |
|
0 | 259 |
def load_hooks(self, vreg): |
260 |
hooks = {} |
|
261 |
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
|
262 |
apphookdefs = vreg['hooks'].all_objects() |
0 | 263 |
except RegistryNotFound: |
264 |
return hooks |
|
265 |
for hookdef in apphookdefs: |
|
266 |
for event, ertype in hookdef.register_to(): |
|
267 |
if ertype == 'Any': |
|
268 |
ertype = '' |
|
269 |
cb = hookdef.make_callback(event) |
|
270 |
hooks.setdefault(event, {}).setdefault(ertype, []).append(cb) |
|
271 |
return hooks |
|
1666 | 272 |
|
273 |
def load_schema(self, expand_cubes=False, **kwargs): |
|
0 | 274 |
from cubicweb.schema import CubicWebSchemaLoader |
275 |
if expand_cubes: |
|
276 |
# in case some new dependencies have been introduced, we have to |
|
277 |
# reinitialize cubes so the full filesystem schema is read |
|
278 |
origcubes = self.cubes() |
|
279 |
self._cubes = None |
|
280 |
self.init_cubes(self.expand_cubes(origcubes)) |
|
1666 | 281 |
schema = CubicWebSchemaLoader().load(self, **kwargs) |
0 | 282 |
if expand_cubes: |
283 |
# restaure original value |
|
284 |
self._cubes = origcubes |
|
285 |
return schema |
|
1666 | 286 |
|
0 | 287 |
def load_bootstrap_schema(self): |
288 |
from cubicweb.schema import BootstrapSchemaLoader |
|
289 |
schema = BootstrapSchemaLoader().load(self) |
|
290 |
schema.name = 'bootstrap' |
|
291 |
return schema |
|
1666 | 292 |
|
0 | 293 |
def set_sources_mode(self, sources): |
294 |
if 'migration' in sources: |
|
295 |
from cubicweb.server.sources import source_adapter |
|
296 |
assert len(sources) == 1 |
|
297 |
enabled_sources = [] |
|
298 |
for uri, config in self.sources().iteritems(): |
|
299 |
if uri == 'admin': |
|
300 |
continue |
|
301 |
if source_adapter(config).connect_for_migration: |
|
302 |
enabled_sources.append(uri) |
|
303 |
else: |
|
304 |
print 'not connecting to source', uri, 'during migration' |
|
305 |
elif 'all' in sources: |
|
306 |
assert len(sources) == 1 |
|
1133 | 307 |
enabled_sources = None |
0 | 308 |
else: |
309 |
known_sources = self.sources() |
|
310 |
for uri in sources: |
|
311 |
assert uri in known_sources, uri |
|
312 |
enabled_sources = sources |
|
313 |
self._enabled_sources = enabled_sources |
|
314 |
clear_cache(self, 'sources') |
|
1666 | 315 |
|
0 | 316 |
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
|
317 |
cnx=None, repo=None, connect=True, verbosity=None): |
0 | 318 |
"""return a migration handler instance""" |
319 |
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
|
320 |
if verbosity is None: |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
321 |
verbosity = getattr(self, 'verbosity', 0) |
0 | 322 |
return ServerMigrationHelper(self, schema, interactive=interactive, |
323 |
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
|
324 |
verbosity=verbosity) |