author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 17 Mar 2010 09:21:58 +0100 | |
branch | stable |
changeset 4928 | cbca73dc9753 |
parent 4756 | a2c73b272c9b |
child 4834 | b718626a0e60 |
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 |
from os.path import join, exists |
|
11 |
||
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
|
12 |
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
|
13 |
ini_format_section |
0 | 14 |
from logilab.common.decorators import wproperty, cached, clear_cache |
15 |
||
3637 | 16 |
from cubicweb.toolsutils import read_config, restrict_perms_to_user |
0 | 17 |
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
|
18 |
from cubicweb.server import SOURCE_TYPES |
0 | 19 |
|
20 |
||
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
|
21 |
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
|
22 |
('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
|
23 |
'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
|
24 |
'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
|
25 |
'(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
|
26 |
'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
|
27 |
}), |
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 |
('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
|
29 |
'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
|
30 |
'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
|
31 |
'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
|
32 |
}), |
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 |
|
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
|
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 |
# make Method('default_instance_id') usable in db option defs (in native.py) |
3905 | 41 |
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
|
42 |
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
|
43 |
|
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 |
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
|
45 |
"""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
|
46 |
|
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 |
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
|
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 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
# 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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
_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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
_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
|
70 |
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
|
71 |
_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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
|
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 |
|
0 | 83 |
class ServerConfiguration(CubicWebConfiguration): |
84 |
"""standalone RQL server""" |
|
85 |
name = 'repository' |
|
86 |
||
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2810
diff
changeset
|
87 |
cubicweb_appobject_path = CubicWebConfiguration.cubicweb_appobject_path | set(['sobjects', 'hooks']) |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
88 |
cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['sobjects', 'hooks']) |
0 | 89 |
|
90 |
options = merge_options(( |
|
91 |
# ctl configuration |
|
92 |
('host', |
|
93 |
{'type' : 'string', |
|
94 |
'default': None, |
|
95 |
'help': 'host name if not correctly detectable through gethostname', |
|
96 |
'group': 'main', 'inputlevel': 1, |
|
97 |
}), |
|
98 |
('pid-file', |
|
99 |
{'type' : 'string', |
|
100 |
'default': Method('default_pid_file'), |
|
101 |
'help': 'repository\'s pid file', |
|
102 |
'group': 'main', 'inputlevel': 2, |
|
103 |
}), |
|
104 |
('uid', |
|
105 |
{'type' : 'string', |
|
106 |
'default': None, |
|
107 |
'help': 'if this option is set, use the specified user to start \ |
|
108 |
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
|
109 |
'group': 'main', 'inputlevel': (CubicWebConfiguration.mode == 'installed') and 0 or 1, |
0 | 110 |
}), |
111 |
('session-time', |
|
112 |
{'type' : 'int', |
|
113 |
'default': 30*60, |
|
114 |
'help': 'session expiration time, default to 30 minutes', |
|
115 |
'group': 'main', 'inputlevel': 1, |
|
116 |
}), |
|
117 |
('connections-pool-size', |
|
118 |
{'type' : 'int', |
|
119 |
'default': 4, |
|
120 |
'help': 'size of the connections pools. Each source supporting multiple \ |
|
121 |
connections will have this number of opened connections.', |
|
122 |
'group': 'main', 'inputlevel': 1, |
|
123 |
}), |
|
124 |
('rql-cache-size', |
|
125 |
{'type' : 'int', |
|
126 |
'default': 300, |
|
127 |
'help': 'size of the parsed rql cache size.', |
|
128 |
'group': 'main', 'inputlevel': 1, |
|
129 |
}), |
|
1160
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
130 |
('delay-full-text-indexation', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
131 |
{'type' : 'yn', 'default': False, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
132 |
'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
|
133 |
' 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
|
134 |
'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
|
135 |
'system (using cron for instance).', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
136 |
'group': 'main', 'inputlevel': 1, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
137 |
}), |
1666 | 138 |
|
0 | 139 |
# email configuration |
140 |
('default-recipients-mode', |
|
141 |
{'type' : 'choice', |
|
142 |
'choices' : ('default-dest-addrs', 'users', 'none'), |
|
143 |
'default': 'default-dest-addrs', |
|
144 |
'help': 'when a notification should be sent with no specific rules \ |
|
145 |
to find recipients, recipients will be found according to this mode. Available \ |
|
146 |
modes are "default-dest-addrs" (emails specified in the configuration \ |
|
147 |
variable with the same name), "users" (every users which has activated \ |
|
148 |
account with an email set), "none" (no notification).', |
|
149 |
'group': 'email', 'inputlevel': 1, |
|
150 |
}), |
|
151 |
('default-dest-addrs', |
|
152 |
{'type' : 'csv', |
|
153 |
'default': (), |
|
154 |
'help': 'comma separated list of email addresses that will be used \ |
|
155 |
as default recipient when an email is sent and the notification has no \ |
|
156 |
specific recipient rules.', |
|
157 |
'group': 'email', 'inputlevel': 1, |
|
158 |
}), |
|
159 |
('supervising-addrs', |
|
160 |
{'type' : 'csv', |
|
161 |
'default': (), |
|
162 |
'help': 'comma separated list of email addresses that will be \ |
|
163 |
notified of every changes.', |
|
164 |
'group': 'email', 'inputlevel': 2, |
|
165 |
}), |
|
166 |
# 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
|
167 |
('pyro-host', |
3547
0c18a6c8d9b7
fix pyro-host option type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
168 |
{'type' : 'string', |
0 | 169 |
'default': None, |
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
170 |
'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
|
171 |
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
|
172 |
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
|
173 |
'group': 'pyro', 'inputlevel': 2, |
0 | 174 |
}), |
175 |
) + CubicWebConfiguration.options) |
|
1666 | 176 |
|
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
177 |
# 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
|
178 |
# necessary... |
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
179 |
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
|
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 |
|
4756
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
188 |
# XXX hooks control stuff should probably be on the session, not on the config |
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
189 |
|
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2810
diff
changeset
|
190 |
# hooks activation configuration |
0 | 191 |
# all hooks should be activated during normal execution |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2810
diff
changeset
|
192 |
disabled_hooks_categories = set() |
4106
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
193 |
enabled_hooks_categories = set() |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
194 |
ALLOW_ALL = object() |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
195 |
DENY_ALL = object() |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
196 |
hooks_mode = ALLOW_ALL |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
197 |
|
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
198 |
@classmethod |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
199 |
def set_hooks_mode(cls, mode): |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
200 |
assert mode is cls.ALLOW_ALL or mode is cls.DENY_ALL |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
201 |
oldmode = cls.hooks_mode |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
202 |
cls.hooks_mode = mode |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
203 |
return oldmode |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
204 |
|
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
205 |
@classmethod |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
206 |
def disable_hook_category(cls, *categories): |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
207 |
changes = set() |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
208 |
if cls.hooks_mode is cls.DENY_ALL: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
209 |
for category in categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
210 |
if category in cls.enabled_hooks_categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
211 |
cls.enabled_hooks_categories.remove(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
212 |
changes.add(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
213 |
else: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
214 |
for category in categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
215 |
if category not in cls.disabled_hooks_categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
216 |
cls.disabled_hooks_categories.add(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
217 |
changes.add(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
218 |
return changes |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
219 |
|
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
220 |
@classmethod |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
221 |
def enable_hook_category(cls, *categories): |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
222 |
changes = set() |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
223 |
if cls.hooks_mode is cls.DENY_ALL: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
224 |
for category in categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
225 |
if category not in cls.enabled_hooks_categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
226 |
cls.enabled_hooks_categories.add(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
227 |
changes.add(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
228 |
else: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
229 |
for category in categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
230 |
if category in cls.disabled_hooks_categories: |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
231 |
cls.disabled_hooks_categories.remove(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
232 |
changes.add(category) |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
233 |
return changes |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
234 |
|
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
235 |
@classmethod |
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
236 |
def is_hook_activated(cls, hook): |
4756
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
237 |
return cls.is_hook_category_activated(hook.category) |
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
238 |
|
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
239 |
@classmethod |
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
240 |
def is_hook_category_activated(cls, category): |
4106
ea4e93f9b151
more advanced hooks control
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
241 |
if cls.hooks_mode is cls.DENY_ALL: |
4756
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
242 |
return category in cls.enabled_hooks_categories |
a2c73b272c9b
do not check for existant entity when relation of single card is added but integrity hooks are deactivated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
243 |
return category not in cls.disabled_hooks_categories |
0 | 244 |
|
245 |
# should some hooks be deactivated during [pre|post]create script execution |
|
246 |
free_wheel = False |
|
1666 | 247 |
|
0 | 248 |
# list of enables sources when sources restriction is necessary |
249 |
# (eg repository initialization at least) |
|
250 |
_enabled_sources = None |
|
251 |
@wproperty |
|
252 |
def enabled_sources(self, sourceuris=None): |
|
253 |
self._enabled_sources = sourceuris |
|
254 |
clear_cache(self, 'sources') |
|
1666 | 255 |
|
0 | 256 |
def bootstrap_cubes(self): |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
257 |
from logilab.common.textutils import splitstrip |
0 | 258 |
for line in file(join(self.apphome, 'bootstrap_cubes')): |
259 |
line = line.strip() |
|
260 |
if not line or line.startswith('#'): |
|
261 |
continue |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2493
diff
changeset
|
262 |
self.init_cubes(self.expand_cubes(splitstrip(line))) |
0 | 263 |
break |
264 |
else: |
|
265 |
# no cubes |
|
266 |
self.init_cubes(()) |
|
1666 | 267 |
|
0 | 268 |
def write_bootstrap_cubes_file(self, cubes): |
269 |
stream = file(join(self.apphome, 'bootstrap_cubes'), 'w') |
|
270 |
stream.write('# this is a generated file only used for bootstraping\n') |
|
271 |
stream.write('# you should not have to edit this\n') |
|
272 |
stream.write('%s\n' % ','.join(cubes)) |
|
273 |
stream.close() |
|
1666 | 274 |
|
0 | 275 |
def sources_file(self): |
276 |
return join(self.apphome, 'sources') |
|
1666 | 277 |
|
0 | 278 |
# this method has to be cached since when the server is running using a |
279 |
# restricted user, this user usually don't have access to the sources |
|
280 |
# configuration file (#16102) |
|
281 |
@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
|
282 |
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
|
283 |
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
|
284 |
|
0 | 285 |
def sources(self): |
286 |
"""return a dictionnaries containing sources definitions indexed by |
|
287 |
sources'uri |
|
288 |
""" |
|
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
|
289 |
allsources = self.read_sources_file() |
0 | 290 |
if self._enabled_sources is None: |
291 |
return allsources |
|
292 |
return dict((uri, config) for uri, config in allsources.items() |
|
293 |
if uri in self._enabled_sources or uri == 'admin') |
|
1666 | 294 |
|
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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
['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
|
302 |
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
|
303 |
|
0 | 304 |
def pyro_enabled(self): |
305 |
"""pyro is always enabled in standalone repository configuration""" |
|
306 |
return True |
|
1666 | 307 |
|
308 |
def load_schema(self, expand_cubes=False, **kwargs): |
|
0 | 309 |
from cubicweb.schema import CubicWebSchemaLoader |
310 |
if expand_cubes: |
|
311 |
# in case some new dependencies have been introduced, we have to |
|
312 |
# reinitialize cubes so the full filesystem schema is read |
|
313 |
origcubes = self.cubes() |
|
314 |
self._cubes = None |
|
315 |
self.init_cubes(self.expand_cubes(origcubes)) |
|
1666 | 316 |
schema = CubicWebSchemaLoader().load(self, **kwargs) |
0 | 317 |
if expand_cubes: |
318 |
# restaure original value |
|
319 |
self._cubes = origcubes |
|
320 |
return schema |
|
1666 | 321 |
|
0 | 322 |
def load_bootstrap_schema(self): |
323 |
from cubicweb.schema import BootstrapSchemaLoader |
|
324 |
schema = BootstrapSchemaLoader().load(self) |
|
325 |
schema.name = 'bootstrap' |
|
326 |
return schema |
|
1666 | 327 |
|
0 | 328 |
def set_sources_mode(self, sources): |
329 |
if 'migration' in sources: |
|
330 |
from cubicweb.server.sources import source_adapter |
|
331 |
assert len(sources) == 1 |
|
332 |
enabled_sources = [] |
|
333 |
for uri, config in self.sources().iteritems(): |
|
334 |
if uri == 'admin': |
|
335 |
continue |
|
336 |
if source_adapter(config).connect_for_migration: |
|
337 |
enabled_sources.append(uri) |
|
338 |
else: |
|
339 |
print 'not connecting to source', uri, 'during migration' |
|
340 |
elif 'all' in sources: |
|
341 |
assert len(sources) == 1 |
|
1133 | 342 |
enabled_sources = None |
0 | 343 |
else: |
344 |
known_sources = self.sources() |
|
345 |
for uri in sources: |
|
346 |
assert uri in known_sources, uri |
|
347 |
enabled_sources = sources |
|
348 |
self._enabled_sources = enabled_sources |
|
349 |
clear_cache(self, 'sources') |
|
1666 | 350 |
|
0 | 351 |
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
|
352 |
cnx=None, repo=None, connect=True, verbosity=None): |
0 | 353 |
"""return a migration handler instance""" |
354 |
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
|
355 |
if verbosity is None: |
9806571ea790
major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2489
diff
changeset
|
356 |
verbosity = getattr(self, 'verbosity', 0) |
0 | 357 |
return ServerMigrationHelper(self, schema, interactive=interactive, |
358 |
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
|
359 |
verbosity=verbosity) |