author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 15 Dec 2009 17:00:58 +0100 | |
branch | stable |
changeset 4122 | 3c3d2a102d4c |
parent 4118 | 8a9a00a9405c |
child 4120 | 21517d42f2ed |
permissions | -rw-r--r-- |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
180
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
0 | 2 |
"""common configuration utilities for cubicweb |
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1948
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1493 | 7 |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
8 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
9 |
If cubicweb is a mercurial checkout (eg `CWDEV` is true), located in |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
10 |
`CW_SOFTWARE_ROOT`: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
11 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
12 |
* main cubes directory is `<CW_SOFTWARE_ROOT>/../cubes`. You can specify |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
13 |
another one with `CW_INSTANCES_DIR` environment variable or simply add some |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
14 |
other directories by using `CW_CUBES_PATH`. |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
15 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
16 |
* cubicweb migration files are by default searched in |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
17 |
`<CW_SOFTWARE_ROOT>/misc/migration` instead of |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
18 |
`/usr/share/cubicweb/migration/`(unless another emplacement is specified |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
19 |
using `CW_MIGRATION_DIR`. |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
20 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
21 |
* Cubicweb will start in 'user' mode (see below) |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
22 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
23 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
24 |
On startup, Cubicweb is using a specific *mode*. A mode corresponds to some |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
25 |
default setting for various resource directories. There are currently 2 main |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
26 |
modes : 'system', for system wide installation, and 'user', fur user local |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
27 |
installation (e.g. no root privileges). |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
28 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
29 |
'user' mode is activated automatically when cubicweb is a mercurial checkout |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
30 |
(e.g. has a .hg directory). You can also force mode by using the `CW_MODE` |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
31 |
environment variable, to: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
32 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
33 |
* use system wide installation but user specific instances and all, without root |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
34 |
privileges on the system (`export CW_MODE=user`) |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
35 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
36 |
* use local checkout of cubicweb on system wide instances (requires root |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
37 |
privileges on the system (`export CW_MODE=system`) |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
38 |
|
3639 | 39 |
Here is the default resource directories settings according to mode: |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
40 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
41 |
* 'system': :: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
42 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
43 |
CW_INSTANCES_DIR = /etc/cubicweb.d/ |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
44 |
CW_INSTANCES_DATA_DIR = /var/lib/cubicweb/instances/ |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
45 |
CW_RUNTIME_DIR = /var/run/cubicweb/ |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
46 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
47 |
* 'user': :: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
48 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
49 |
CW_INSTANCES_DIR = ~/etc/cubicweb.d/ |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
50 |
CW_INSTANCES_DATA_DIR = ~/etc/cubicweb.d/ |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
51 |
CW_RUNTIME_DIR = /tmp |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
52 |
|
3639 | 53 |
|
54 |
.. envvar:: CW_MODE |
|
55 |
Resource mode: user or system |
|
56 |
||
1493 | 57 |
.. envvar:: CW_CUBES_PATH |
3639 | 58 |
Augments the default search path for cubes |
59 |
||
60 |
.. envvar:: CW_INSTANCES_DIR |
|
61 |
Directory where cubicweb instances will be found |
|
1493 | 62 |
|
3639 | 63 |
.. envvar:: CW_INSTANCES_DATA_DIR |
64 |
Directory where cubicweb instances data will be written |
|
65 |
||
66 |
.. envvar:: CW_RUNTIME_DIR |
|
67 |
Directory where pid files will be written |
|
68 |
||
69 |
.. envvar:: CW_MIGRATION_DIR |
|
70 |
Directory where cubicweb migration files will be found |
|
71 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1681
diff
changeset
|
72 |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1948
diff
changeset
|
73 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 74 |
""" |
75 |
__docformat__ = "restructuredtext en" |
|
1948 | 76 |
_ = unicode |
0 | 77 |
|
78 |
import sys |
|
79 |
import os |
|
80 |
import logging |
|
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
81 |
from smtplib import SMTP |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
82 |
from threading import Lock |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
83 |
from os.path import exists, join, expanduser, abspath, normpath, basename, isdir |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
3059
diff
changeset
|
84 |
import tempfile |
0 | 85 |
|
86 |
from logilab.common.decorators import cached |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
87 |
from logilab.common.deprecation import deprecated |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
88 |
from logilab.common.logging_ext import set_log_methods, init_log |
0 | 89 |
from logilab.common.configuration import (Configuration, Method, |
90 |
ConfigurationMixIn, merge_options) |
|
91 |
||
92 |
from cubicweb import CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, ConfigurationError |
|
1132 | 93 |
from cubicweb.toolsutils import env_path, create_dir |
0 | 94 |
|
95 |
CONFIGURATIONS = [] |
|
96 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
97 |
SMTP_LOCK = Lock() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
98 |
|
0 | 99 |
|
100 |
class metaconfiguration(type): |
|
101 |
"""metaclass to automaticaly register configuration""" |
|
102 |
def __new__(mcs, name, bases, classdict): |
|
103 |
cls = super(metaconfiguration, mcs).__new__(mcs, name, bases, classdict) |
|
104 |
if classdict.get('name'): |
|
105 |
CONFIGURATIONS.append(cls) |
|
106 |
return cls |
|
107 |
||
108 |
def configuration_cls(name): |
|
109 |
"""return the configuration class registered with the given name""" |
|
110 |
try: |
|
111 |
return [c for c in CONFIGURATIONS if c.name == name][0] |
|
112 |
except IndexError: |
|
113 |
raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
|
114 |
||
115 |
def possible_configurations(directory): |
|
116 |
"""return a list of installed configurations in a directory |
|
117 |
according to *-ctl files |
|
118 |
""" |
|
119 |
return [name for name in ('repository', 'twisted', 'all-in-one') |
|
120 |
if exists(join(directory, '%s.conf' % name))] |
|
121 |
||
122 |
def guess_configuration(directory): |
|
123 |
"""try to guess the configuration to use for a directory. If multiple |
|
124 |
configurations are found, ConfigurationError is raised |
|
125 |
""" |
|
126 |
modes = possible_configurations(directory) |
|
127 |
if len(modes) != 1: |
|
128 |
raise ConfigurationError('unable to guess configuration from %r %s' |
|
129 |
% (directory, modes)) |
|
130 |
return modes[0] |
|
131 |
||
132 |
||
133 |
# persistent options definition |
|
134 |
PERSISTENT_OPTIONS = ( |
|
135 |
('encoding', |
|
136 |
{'type' : 'string', |
|
137 |
'default': 'UTF-8', |
|
138 |
'help': _('user interface encoding'), |
|
139 |
'group': 'ui', 'sitewide': True, |
|
1446 | 140 |
}), |
0 | 141 |
('language', |
142 |
{'type' : 'string', |
|
143 |
'default': 'en', |
|
144 |
'vocabulary': Method('available_languages'), |
|
145 |
'help': _('language of the user interface'), |
|
1446 | 146 |
'group': 'ui', |
0 | 147 |
}), |
148 |
('date-format', |
|
149 |
{'type' : 'string', |
|
150 |
'default': '%Y/%m/%d', |
|
151 |
'help': _('how to format date in the ui ("man strftime" for format description)'), |
|
1446 | 152 |
'group': 'ui', |
0 | 153 |
}), |
154 |
('datetime-format', |
|
155 |
{'type' : 'string', |
|
156 |
'default': '%Y/%m/%d %H:%M', |
|
157 |
'help': _('how to format date and time in the ui ("man strftime" for format description)'), |
|
1446 | 158 |
'group': 'ui', |
0 | 159 |
}), |
160 |
('time-format', |
|
161 |
{'type' : 'string', |
|
162 |
'default': '%H:%M', |
|
163 |
'help': _('how to format time in the ui ("man strftime" for format description)'), |
|
1446 | 164 |
'group': 'ui', |
0 | 165 |
}), |
166 |
('float-format', |
|
167 |
{'type' : 'string', |
|
168 |
'default': '%.3f', |
|
169 |
'help': _('how to format float numbers in the ui'), |
|
1446 | 170 |
'group': 'ui', |
0 | 171 |
}), |
172 |
('default-text-format', |
|
173 |
{'type' : 'choice', |
|
174 |
'choices': ('text/plain', 'text/rest', 'text/html'), |
|
175 |
'default': 'text/html', # use fckeditor in the web ui |
|
176 |
'help': _('default text format for rich text fields.'), |
|
1446 | 177 |
'group': 'ui', |
0 | 178 |
}), |
179 |
('short-line-size', |
|
180 |
{'type' : 'int', |
|
181 |
'default': 40, |
|
182 |
'help': _('maximum number of characters in short description'), |
|
183 |
'group': 'navigation', |
|
184 |
}), |
|
185 |
) |
|
186 |
||
187 |
def register_persistent_options(options): |
|
188 |
global PERSISTENT_OPTIONS |
|
189 |
PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options) |
|
1446 | 190 |
|
0 | 191 |
CFGTYPE2ETYPE_MAP = { |
192 |
'string': 'String', |
|
193 |
'choice': 'String', |
|
194 |
'yn': 'Boolean', |
|
195 |
'int': 'Int', |
|
196 |
'float' : 'Float', |
|
197 |
} |
|
1446 | 198 |
|
3059
1be8bf42bc5d
consider CW_MODE='system', the opposite of 'user' (eg use 'installed' mode while using the forest)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2762
diff
changeset
|
199 |
_forced_mode = os.environ.get('CW_MODE') |
1be8bf42bc5d
consider CW_MODE='system', the opposite of 'user' (eg use 'installed' mode while using the forest)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2762
diff
changeset
|
200 |
assert _forced_mode in (None, 'system', 'user') |
1be8bf42bc5d
consider CW_MODE='system', the opposite of 'user' (eg use 'installed' mode while using the forest)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2762
diff
changeset
|
201 |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
202 |
CWDEV = exists(join(CW_SOFTWARE_ROOT, '.hg')) |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
203 |
|
0 | 204 |
class CubicWebNoAppConfiguration(ConfigurationMixIn): |
205 |
"""base class for cubicweb configuration without a specific instance directory |
|
206 |
""" |
|
207 |
__metaclass__ = metaconfiguration |
|
208 |
# to set in concrete configuration |
|
209 |
name = None |
|
210 |
# log messages format (see logging module documentation for available keys) |
|
211 |
log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s' |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
212 |
# nor remove appobjects based on unused interface |
0 | 213 |
cleanup_interface_sobjects = True |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
214 |
# debug mode |
3641
cf30e4498674
fix debug attribute conflict on configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3640
diff
changeset
|
215 |
debugmode = False |
0 | 216 |
|
217 |
if os.environ.get('APYCOT_ROOT'): |
|
218 |
mode = 'test' |
|
3915
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
219 |
if CWDEV: |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
220 |
CUBES_DIR = '%(APYCOT_ROOT)s/local/share/cubicweb/cubes/' % os.environ |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
221 |
# create __init__ file |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
222 |
file(join(CUBES_DIR, '__init__.py'), 'w').close() |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
223 |
else: |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
224 |
CUBES_DIR = '/usr/share/cubicweb/cubes/' |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
225 |
elif (CWDEV and _forced_mode != 'system'): |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
226 |
mode = 'user' |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
227 |
CUBES_DIR = abspath(normpath(join(CW_SOFTWARE_ROOT, '../cubes'))) |
0 | 228 |
else: |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
229 |
if _forced_mode == 'user': |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
230 |
mode = 'user' |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
231 |
else: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
232 |
mode = 'system' |
0 | 233 |
CUBES_DIR = '/usr/share/cubicweb/cubes/' |
234 |
||
1046
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
235 |
options = ( |
0 | 236 |
('log-threshold', |
237 |
{'type' : 'string', # XXX use a dedicated type? |
|
238 |
'default': 'ERROR', |
|
239 |
'help': 'server\'s log level', |
|
240 |
'group': 'main', 'inputlevel': 1, |
|
241 |
}), |
|
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:
3275
diff
changeset
|
242 |
# pyro options |
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:
3275
diff
changeset
|
243 |
('pyro-instance-id', |
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:
3275
diff
changeset
|
244 |
{'type' : 'string', |
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:
3275
diff
changeset
|
245 |
'default': Method('default_instance_id'), |
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:
3275
diff
changeset
|
246 |
'help': 'identifier of the CubicWeb instance in the Pyro name server', |
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:
3275
diff
changeset
|
247 |
'group': 'pyro', 'inputlevel': 1, |
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:
3275
diff
changeset
|
248 |
}), |
0 | 249 |
('pyro-ns-host', |
250 |
{'type' : 'string', |
|
378
c0cd7398edff
revert local debug checkin
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
369
diff
changeset
|
251 |
'default': '', |
0 | 252 |
'help': 'Pyro name server\'s host. If not set, will be detected by a \ |
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
253 |
broadcast query. It may contains port information using <host>:<port> notation.', |
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:
3275
diff
changeset
|
254 |
'group': 'pyro', 'inputlevel': 1, |
0 | 255 |
}), |
256 |
('pyro-ns-group', |
|
257 |
{'type' : 'string', |
|
258 |
'default': 'cubicweb', |
|
259 |
'help': 'Pyro name server\'s group where the repository will be \ |
|
260 |
registered.', |
|
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:
3275
diff
changeset
|
261 |
'group': 'pyro', 'inputlevel': 1, |
0 | 262 |
}), |
263 |
# common configuration options which are potentially required as soon as |
|
264 |
# you're using "base" application objects (ie to really server/web |
|
265 |
# specific) |
|
266 |
('base-url', |
|
267 |
{'type' : 'string', |
|
268 |
'default': None, |
|
269 |
'help': 'web server root url', |
|
270 |
'group': 'main', 'inputlevel': 1, |
|
271 |
}), |
|
2267
e1d2df3f1091
move login by email functionnality on the repository side to avoid buggy call to internal_session from the web interface side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2221
diff
changeset
|
272 |
('allow-email-login', |
e1d2df3f1091
move login by email functionnality on the repository side to avoid buggy call to internal_session from the web interface side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2221
diff
changeset
|
273 |
{'type' : 'yn', |
e1d2df3f1091
move login by email functionnality on the repository side to avoid buggy call to internal_session from the web interface side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2221
diff
changeset
|
274 |
'default': False, |
e1d2df3f1091
move login by email functionnality on the repository side to avoid buggy call to internal_session from the web interface side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2221
diff
changeset
|
275 |
'help': 'allow users to login with their primary email if set', |
e1d2df3f1091
move login by email functionnality on the repository side to avoid buggy call to internal_session from the web interface side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2221
diff
changeset
|
276 |
'group': 'main', 'inputlevel': 2, |
e1d2df3f1091
move login by email functionnality on the repository side to avoid buggy call to internal_session from the web interface side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2221
diff
changeset
|
277 |
}), |
1520
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
278 |
('use-request-subdomain', |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
279 |
{'type' : 'yn', |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
280 |
'default': None, |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
281 |
'help': ('if set, base-url subdomain is replaced by the request\'s ' |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
282 |
'host, to help managing sites with several subdomains in a ' |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
283 |
'single cubicweb instance'), |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
284 |
'group': 'main', 'inputlevel': 1, |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
285 |
}), |
0 | 286 |
('mangle-emails', |
287 |
{'type' : 'yn', |
|
288 |
'default': False, |
|
289 |
'help': "don't display actual email addresses but mangle them if \ |
|
290 |
this option is set to yes", |
|
291 |
'group': 'email', 'inputlevel': 2, |
|
292 |
}), |
|
1046
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
293 |
('disable-appobjects', |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
294 |
{'type' : 'csv', 'default': (), |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
295 |
'help': 'comma separated list of identifiers of application objects (<registry>.<oid>) to disable', |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
296 |
'group': 'appobjects', 'inputlevel': 2, |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
297 |
}), |
0 | 298 |
) |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
299 |
# static and class methods used to get instance independant resources ## |
1446 | 300 |
|
0 | 301 |
@staticmethod |
302 |
def cubicweb_version(): |
|
303 |
"""return installed cubicweb version""" |
|
304 |
from logilab.common.changelog import Version |
|
305 |
from cubicweb import __pkginfo__ |
|
306 |
version = __pkginfo__.numversion |
|
307 |
assert len(version) == 3, version |
|
308 |
return Version(version) |
|
1446 | 309 |
|
0 | 310 |
@staticmethod |
311 |
def persistent_options_configuration(): |
|
312 |
return Configuration(options=PERSISTENT_OPTIONS) |
|
313 |
||
314 |
@classmethod |
|
315 |
def shared_dir(cls): |
|
316 |
"""return the shared data directory (i.e. directory where standard |
|
317 |
library views and data may be found) |
|
318 |
""" |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
319 |
if CWDEV: |
0 | 320 |
return join(CW_SOFTWARE_ROOT, 'web') |
1039 | 321 |
return cls.cube_dir('shared') |
1446 | 322 |
|
0 | 323 |
@classmethod |
324 |
def i18n_lib_dir(cls): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
325 |
"""return instance's i18n directory""" |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
326 |
if CWDEV: |
0 | 327 |
return join(CW_SOFTWARE_ROOT, 'i18n') |
328 |
return join(cls.shared_dir(), 'i18n') |
|
329 |
||
330 |
@classmethod |
|
331 |
def available_cubes(cls): |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
332 |
cubes = set() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
333 |
for directory in cls.cubes_search_path(): |
4001
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
334 |
if not os.path.exists(directory): |
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
335 |
self.error('unexistant directory in cubes search path: %s' |
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
336 |
% directory) |
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
337 |
continue |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
338 |
for cube in os.listdir(directory): |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
339 |
if isdir(join(directory, cube)) and not cube == 'shared': |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
340 |
cubes.add(cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
341 |
return sorted(cubes) |
1446 | 342 |
|
0 | 343 |
@classmethod |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
344 |
def cubes_search_path(cls): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
345 |
"""return the path of directories where cubes should be searched""" |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
346 |
path = [] |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
347 |
try: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
348 |
for directory in os.environ['CW_CUBES_PATH'].split(os.pathsep): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
349 |
directory = abspath(normpath(directory)) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
350 |
if exists(directory) and not directory in path: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
351 |
path.append(directory) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
352 |
except KeyError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
353 |
pass |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
354 |
if not cls.CUBES_DIR in path: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
355 |
path.append(cls.CUBES_DIR) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
356 |
return path |
1446 | 357 |
|
0 | 358 |
@classmethod |
359 |
def cube_dir(cls, cube): |
|
360 |
"""return the cube directory for the given cube id, |
|
361 |
raise ConfigurationError if it doesn't exists |
|
362 |
""" |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
363 |
for directory in cls.cubes_search_path(): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
364 |
cubedir = join(directory, cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
365 |
if exists(cubedir): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
366 |
return cubedir |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
367 |
raise ConfigurationError('no cube %s in %s' % (cube, cls.cubes_search_path())) |
0 | 368 |
|
369 |
@classmethod |
|
370 |
def cube_migration_scripts_dir(cls, cube): |
|
371 |
"""cube migration scripts directory""" |
|
372 |
return join(cls.cube_dir(cube), 'migration') |
|
1446 | 373 |
|
0 | 374 |
@classmethod |
375 |
def cube_pkginfo(cls, cube): |
|
376 |
"""return the information module for the given cube""" |
|
377 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
378 |
try: |
|
379 |
return getattr(__import__('cubes.%s.__pkginfo__' % cube), cube).__pkginfo__ |
|
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
380 |
except Exception, ex: |
0 | 381 |
raise ConfigurationError('unable to find packaging information for ' |
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
382 |
'cube %s (%s: %s)' % (cube, ex.__class__.__name__, ex)) |
0 | 383 |
|
384 |
@classmethod |
|
385 |
def cube_version(cls, cube): |
|
1446 | 386 |
"""return the version of the cube located in the given directory |
0 | 387 |
""" |
388 |
from logilab.common.changelog import Version |
|
389 |
version = cls.cube_pkginfo(cube).numversion |
|
390 |
assert len(version) == 3, version |
|
391 |
return Version(version) |
|
392 |
||
393 |
@classmethod |
|
394 |
def cube_dependencies(cls, cube): |
|
395 |
"""return cubicweb cubes used by the given cube""" |
|
396 |
return getattr(cls.cube_pkginfo(cube), '__use__', ()) |
|
397 |
||
398 |
@classmethod |
|
399 |
def cube_recommends(cls, cube): |
|
400 |
"""return cubicweb cubes recommended by the given cube""" |
|
401 |
return getattr(cls.cube_pkginfo(cube), '__recommend__', ()) |
|
402 |
||
403 |
@classmethod |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
404 |
def expand_cubes(cls, cubes, with_recommends=False): |
0 | 405 |
"""expand the given list of top level cubes used by adding recursivly |
406 |
each cube dependencies |
|
407 |
""" |
|
408 |
cubes = list(cubes) |
|
409 |
todo = cubes[:] |
|
410 |
while todo: |
|
411 |
cube = todo.pop(0) |
|
412 |
for depcube in cls.cube_dependencies(cube): |
|
413 |
if depcube not in cubes: |
|
414 |
depcube = CW_MIGRATION_MAP.get(depcube, depcube) |
|
415 |
cubes.append(depcube) |
|
416 |
todo.append(depcube) |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
417 |
if with_recommends: |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
418 |
for depcube in cls.cube_recommends(cube): |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
419 |
if depcube not in cubes: |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
420 |
depcube = CW_MIGRATION_MAP.get(depcube, depcube) |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
421 |
cubes.append(depcube) |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
422 |
todo.append(depcube) |
0 | 423 |
return cubes |
424 |
||
425 |
@classmethod |
|
426 |
def reorder_cubes(cls, cubes): |
|
427 |
"""reorder cubes from the top level cubes to inner dependencies |
|
428 |
cubes |
|
429 |
""" |
|
430 |
from logilab.common.graph import get_cycles |
|
431 |
graph = {} |
|
432 |
for cube in cubes: |
|
433 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
434 |
deps = cls.cube_dependencies(cube) + \ |
|
435 |
cls.cube_recommends(cube) |
|
436 |
graph[cube] = set(dep for dep in deps if dep in cubes) |
|
437 |
cycles = get_cycles(graph) |
|
438 |
if cycles: |
|
439 |
cycles = '\n'.join(' -> '.join(cycle) for cycle in cycles) |
|
440 |
raise ConfigurationError('cycles in cubes dependencies: %s' |
|
441 |
% cycles) |
|
442 |
cubes = [] |
|
443 |
while graph: |
|
444 |
# sorted to get predictable results |
|
445 |
for cube, deps in sorted(graph.items()): |
|
446 |
if not deps: |
|
447 |
cubes.append(cube) |
|
448 |
del graph[cube] |
|
449 |
for deps in graph.itervalues(): |
|
450 |
try: |
|
451 |
deps.remove(cube) |
|
452 |
except KeyError: |
|
453 |
continue |
|
454 |
return tuple(reversed(cubes)) |
|
1446 | 455 |
|
0 | 456 |
@classmethod |
457 |
def cls_adjust_sys_path(cls): |
|
458 |
"""update python path if necessary""" |
|
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
459 |
cubes_parent_dir = normpath(join(cls.CUBES_DIR, '..')) |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
460 |
if not cubes_parent_dir in sys.path: |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
461 |
sys.path.insert(0, cubes_parent_dir) |
0 | 462 |
try: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
463 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
464 |
cubes.__path__ = cls.cubes_search_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
465 |
except ImportError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
466 |
return # cubes dir doesn't exists |
0 | 467 |
|
468 |
@classmethod |
|
469 |
def load_cwctl_plugins(cls): |
|
470 |
from logilab.common.modutils import load_module_from_file |
|
471 |
cls.cls_adjust_sys_path() |
|
472 |
for ctlfile in ('web/webctl.py', 'etwist/twctl.py', |
|
473 |
'server/serverctl.py', 'hercule.py', |
|
474 |
'devtools/devctl.py', 'goa/goactl.py'): |
|
475 |
if exists(join(CW_SOFTWARE_ROOT, ctlfile)): |
|
3269
02a918f108a7
prevent some command providers to stop using cubicweb-ctl (current case : goactl when vobject is not there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3118
diff
changeset
|
476 |
try: |
02a918f108a7
prevent some command providers to stop using cubicweb-ctl (current case : goactl when vobject is not there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3118
diff
changeset
|
477 |
load_module_from_file(join(CW_SOFTWARE_ROOT, ctlfile)) |
02a918f108a7
prevent some command providers to stop using cubicweb-ctl (current case : goactl when vobject is not there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3118
diff
changeset
|
478 |
except ImportError, err: |
4095
72fd2d4cc782
changed log severity from critical to info if a plugin cannot be loaded
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4001
diff
changeset
|
479 |
cls.info('could not import the command provider %s (cause : %s)' % |
3269
02a918f108a7
prevent some command providers to stop using cubicweb-ctl (current case : goactl when vobject is not there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3118
diff
changeset
|
480 |
(ctlfile, err)) |
0 | 481 |
cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
482 |
for cube in cls.available_cubes(): |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
483 |
pluginfile = join(cls.cube_dir(cube), 'ecplugin.py') |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
484 |
initfile = join(cls.cube_dir(cube), '__init__.py') |
0 | 485 |
if exists(pluginfile): |
486 |
try: |
|
487 |
__import__('cubes.%s.ecplugin' % cube) |
|
488 |
cls.info('loaded cubicweb-ctl plugin from %s', cube) |
|
489 |
except: |
|
490 |
cls.exception('while loading plugin %s', pluginfile) |
|
491 |
elif exists(initfile): |
|
492 |
try: |
|
493 |
__import__('cubes.%s' % cube) |
|
494 |
except: |
|
495 |
cls.exception('while loading cube %s', cube) |
|
496 |
else: |
|
1446 | 497 |
cls.warning('no __init__ file in cube %s', cube) |
0 | 498 |
|
499 |
@classmethod |
|
500 |
def init_available_cubes(cls): |
|
501 |
"""cubes may register some sources (svnfile for instance) in their |
|
502 |
__init__ file, so they should be loaded early in the startup process |
|
503 |
""" |
|
504 |
for cube in cls.available_cubes(): |
|
505 |
try: |
|
506 |
__import__('cubes.%s' % cube) |
|
507 |
except Exception, ex: |
|
508 |
cls.warning("can't init cube %s: %s", cube, ex) |
|
1446 | 509 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
510 |
cubicweb_appobject_path = set(['entities']) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
511 |
cube_appobject_path = set(['entities']) |
0 | 512 |
|
513 |
@classmethod |
|
514 |
def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None): |
|
515 |
"""given a list of directories, return a list of sub files and |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
516 |
directories that should be loaded by the instance objects registry. |
0 | 517 |
|
518 |
:param evobjpath: |
|
519 |
optional list of sub-directories (or files without the .py ext) of |
|
520 |
the cubicweb library that should be tested and added to the output list |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
521 |
if they exists. If not give, default to `cubicweb_appobject_path` class |
0 | 522 |
attribute. |
523 |
:param tvobjpath: |
|
524 |
optional list of sub-directories (or files without the .py ext) of |
|
525 |
directories given in `templpath` that should be tested and added to |
|
526 |
the output list if they exists. If not give, default to |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
527 |
`cube_appobject_path` class attribute. |
0 | 528 |
""" |
529 |
vregpath = cls.build_vregistry_cubicweb_path(evobjpath) |
|
530 |
vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath) |
|
531 |
return vregpath |
|
532 |
||
533 |
@classmethod |
|
534 |
def build_vregistry_cubicweb_path(cls, evobjpath=None): |
|
535 |
vregpath = [] |
|
536 |
if evobjpath is None: |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
537 |
evobjpath = cls.cubicweb_appobject_path |
0 | 538 |
for subdir in evobjpath: |
539 |
path = join(CW_SOFTWARE_ROOT, subdir) |
|
540 |
if exists(path): |
|
541 |
vregpath.append(path) |
|
542 |
return vregpath |
|
543 |
||
544 |
@classmethod |
|
545 |
def build_vregistry_cube_path(cls, templpath, tvobjpath=None): |
|
546 |
vregpath = [] |
|
547 |
if tvobjpath is None: |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
548 |
tvobjpath = cls.cube_appobject_path |
0 | 549 |
for directory in templpath: |
550 |
for subdir in tvobjpath: |
|
551 |
path = join(directory, subdir) |
|
552 |
if exists(path): |
|
553 |
vregpath.append(path) |
|
554 |
elif exists(path + '.py'): |
|
555 |
vregpath.append(path + '.py') |
|
556 |
return vregpath |
|
1446 | 557 |
|
0 | 558 |
def __init__(self): |
559 |
ConfigurationMixIn.__init__(self) |
|
560 |
self.adjust_sys_path() |
|
561 |
self.load_defaults() |
|
1446 | 562 |
self.translations = {} |
4118
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
563 |
# don't register ReStructured Text directives by simple import, avoid pb |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
564 |
# with eg sphinx. |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
565 |
# XXX should be done properly with a function from cw.uicfg |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
566 |
try: |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
567 |
from cubicweb.ext.rest import cw_rest_init |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
568 |
except ImportError: |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
569 |
pass |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
570 |
else: |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4095
diff
changeset
|
571 |
cw_rest_init() |
0 | 572 |
|
573 |
def adjust_sys_path(self): |
|
574 |
self.cls_adjust_sys_path() |
|
1446 | 575 |
|
576 |
def init_log(self, logthreshold=None, debug=False, |
|
0 | 577 |
logfile=None, syslog=False): |
578 |
"""init the log service""" |
|
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
579 |
if logthreshold is None: |
0 | 580 |
if debug: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
581 |
logthreshold = 'DEBUG' |
0 | 582 |
else: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
583 |
logthreshold = self['log-threshold'] |
3641
cf30e4498674
fix debug attribute conflict on configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3640
diff
changeset
|
584 |
self.debugmode = debug |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
585 |
init_log(debug, syslog, logthreshold, logfile, self.log_format) |
0 | 586 |
# configure simpleTal logger |
587 |
logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
|
588 |
||
589 |
def vregistry_path(self): |
|
590 |
"""return a list of files or directories where the registry will look |
|
591 |
for application objects. By default return nothing in NoApp config. |
|
592 |
""" |
|
593 |
return [] |
|
1446 | 594 |
|
0 | 595 |
def eproperty_definitions(self): |
596 |
cfg = self.persistent_options_configuration() |
|
597 |
for section, options in cfg.options_by_section(): |
|
598 |
section = section.lower() |
|
599 |
for optname, optdict, value in options: |
|
600 |
key = '%s.%s' % (section, optname) |
|
601 |
type, vocab = self.map_option(optdict) |
|
602 |
default = cfg.option_default(optname, optdict) |
|
603 |
pdef = {'type': type, 'vocabulary': vocab, 'default': default, |
|
604 |
'help': optdict['help'], |
|
605 |
'sitewide': optdict.get('sitewide', False)} |
|
606 |
yield key, pdef |
|
1446 | 607 |
|
0 | 608 |
def map_option(self, optdict): |
609 |
try: |
|
610 |
vocab = optdict['choices'] |
|
611 |
except KeyError: |
|
612 |
vocab = optdict.get('vocabulary') |
|
613 |
if isinstance(vocab, Method): |
|
614 |
vocab = getattr(self, vocab.method, ()) |
|
615 |
return CFGTYPE2ETYPE_MAP[optdict['type']], vocab |
|
616 |
||
3564
b03cc2416cd5
[config] dumb implementation of default_instance_id on no app config since it's referenced
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
617 |
def default_instance_id(self): |
b03cc2416cd5
[config] dumb implementation of default_instance_id on no app config since it's referenced
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
618 |
"""return the instance identifier, useful for option which need this |
b03cc2416cd5
[config] dumb implementation of default_instance_id on no app config since it's referenced
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
619 |
as default value |
b03cc2416cd5
[config] dumb implementation of default_instance_id on no app config since it's referenced
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
620 |
""" |
b03cc2416cd5
[config] dumb implementation of default_instance_id on no app config since it's referenced
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
621 |
return None |
1446 | 622 |
|
0 | 623 |
class CubicWebConfiguration(CubicWebNoAppConfiguration): |
624 |
"""base class for cubicweb server and web configurations""" |
|
1446 | 625 |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
626 |
INSTANCES_DATA_DIR = None |
0 | 627 |
if CubicWebNoAppConfiguration.mode == 'test': |
628 |
root = os.environ['APYCOT_ROOT'] |
|
629 |
REGISTRY_DIR = '%s/etc/cubicweb.d/' % root |
|
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
3059
diff
changeset
|
630 |
RUNTIME_DIR = tempfile.gettempdir() |
3915
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
631 |
if CWDEV: |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
632 |
MIGRATION_DIR = '%s/local/share/cubicweb/migration/' % root |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
633 |
else: |
2d23304289a6
allow to test cubes within apycot using cubicweb from the debian package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
634 |
MIGRATION_DIR = '/usr/share/cubicweb/migration/' |
0 | 635 |
if not exists(REGISTRY_DIR): |
636 |
os.makedirs(REGISTRY_DIR) |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
637 |
else: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
638 |
if CubicWebNoAppConfiguration.mode == 'user': |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
639 |
REGISTRY_DIR = expanduser('~/etc/cubicweb.d/') |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
640 |
RUNTIME_DIR = tempfile.gettempdir() |
3640 | 641 |
INSTANCES_DATA_DIR = REGISTRY_DIR |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
642 |
else: #mode = 'system' |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
643 |
REGISTRY_DIR = '/etc/cubicweb.d/' |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
644 |
RUNTIME_DIR = '/var/run/cubicweb/' |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
645 |
INSTANCES_DATA_DIR = '/var/lib/cubicweb/instances/' |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
646 |
if CWDEV: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
647 |
MIGRATION_DIR = join(CW_SOFTWARE_ROOT, 'misc', 'migration') |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
648 |
else: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
649 |
MIGRATION_DIR = '/usr/share/cubicweb/migration/' |
0 | 650 |
|
651 |
# for some commands (creation...) we don't want to initialize gettext |
|
652 |
set_language = True |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
653 |
# set this to true to avoid false error message while creating an instance |
0 | 654 |
creating = False |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2449
diff
changeset
|
655 |
# set this to true to allow somethings which would'nt be possible |
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2449
diff
changeset
|
656 |
repairing = False |
1446 | 657 |
|
0 | 658 |
options = CubicWebNoAppConfiguration.options + ( |
659 |
('log-file', |
|
660 |
{'type' : 'string', |
|
661 |
'default': Method('default_log_file'), |
|
662 |
'help': 'file where output logs should be written', |
|
663 |
'group': 'main', 'inputlevel': 2, |
|
664 |
}), |
|
665 |
# email configuration |
|
666 |
('smtp-host', |
|
667 |
{'type' : 'string', |
|
668 |
'default': 'mail', |
|
669 |
'help': 'hostname of the SMTP mail server', |
|
670 |
'group': 'email', 'inputlevel': 1, |
|
671 |
}), |
|
672 |
('smtp-port', |
|
673 |
{'type' : 'int', |
|
674 |
'default': 25, |
|
675 |
'help': 'listening port of the SMTP mail server', |
|
676 |
'group': 'email', 'inputlevel': 1, |
|
677 |
}), |
|
678 |
('sender-name', |
|
679 |
{'type' : 'string', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
680 |
'default': Method('default_instance_id'), |
0 | 681 |
'help': 'name used as HELO name for outgoing emails from the \ |
682 |
repository.', |
|
683 |
'group': 'email', 'inputlevel': 2, |
|
684 |
}), |
|
685 |
('sender-addr', |
|
686 |
{'type' : 'string', |
|
2351
dddee537e4d5
don't use internal address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
687 |
'default': 'cubicweb@mydomain.com', |
0 | 688 |
'help': 'email address used as HELO address for outgoing emails from \ |
689 |
the repository', |
|
690 |
'group': 'email', 'inputlevel': 1, |
|
691 |
}), |
|
692 |
) |
|
693 |
||
694 |
@classmethod |
|
695 |
def runtime_dir(cls): |
|
696 |
"""run time directory for pid file...""" |
|
2445
6f065b366d14
rename environment variables
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2351
diff
changeset
|
697 |
return env_path('CW_RUNTIME_DIR', cls.RUNTIME_DIR, 'run time') |
1446 | 698 |
|
0 | 699 |
@classmethod |
700 |
def registry_dir(cls): |
|
701 |
"""return the control directory""" |
|
2445
6f065b366d14
rename environment variables
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2351
diff
changeset
|
702 |
return env_path('CW_INSTANCES_DIR', cls.REGISTRY_DIR, 'registry') |
0 | 703 |
|
704 |
@classmethod |
|
705 |
def instance_data_dir(cls): |
|
706 |
"""return the instance data directory""" |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
707 |
return env_path('CW_INSTANCES_DATA_DIR', cls.INSTANCES_DATA_DIR, |
0 | 708 |
'additional data') |
1446 | 709 |
|
0 | 710 |
@classmethod |
711 |
def migration_scripts_dir(cls): |
|
712 |
"""cubicweb migration scripts directory""" |
|
2445
6f065b366d14
rename environment variables
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2351
diff
changeset
|
713 |
return env_path('CW_MIGRATION_DIR', cls.MIGRATION_DIR, 'migration') |
0 | 714 |
|
715 |
@classmethod |
|
716 |
def config_for(cls, appid, config=None): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
717 |
"""return a configuration instance for the given instance identifier |
0 | 718 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
719 |
config = config or guess_configuration(cls.instance_home(appid)) |
0 | 720 |
configcls = configuration_cls(config) |
721 |
return configcls(appid) |
|
1446 | 722 |
|
0 | 723 |
@classmethod |
724 |
def possible_configurations(cls, appid): |
|
725 |
"""return the name of possible configurations for the given |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
726 |
instance id |
0 | 727 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
728 |
home = cls.instance_home(appid) |
0 | 729 |
return possible_configurations(home) |
1446 | 730 |
|
0 | 731 |
@classmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
732 |
def instance_home(cls, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
733 |
"""return the home directory of the instance with the given |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
734 |
instance id |
0 | 735 |
""" |
736 |
home = join(cls.registry_dir(), appid) |
|
737 |
if not exists(home): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
738 |
raise ConfigurationError('no such instance %s (check it exists with "cubicweb-ctl list")' % appid) |
0 | 739 |
return home |
740 |
||
741 |
MODES = ('common', 'repository', 'Any', 'web') |
|
742 |
MCOMPAT = {'all-in-one': MODES, |
|
743 |
'repository': ('common', 'repository', 'Any'), |
|
744 |
'twisted' : ('common', 'web'),} |
|
745 |
@classmethod |
|
746 |
def accept_mode(cls, mode): |
|
747 |
#assert mode in cls.MODES, mode |
|
748 |
return mode in cls.MCOMPAT[cls.name] |
|
1446 | 749 |
|
0 | 750 |
# default configuration methods ########################################### |
1446 | 751 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
752 |
def default_instance_id(self): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
753 |
"""return the instance identifier, useful for option which need this |
0 | 754 |
as default value |
755 |
""" |
|
756 |
return self.appid |
|
757 |
||
758 |
def default_log_file(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
759 |
"""return default path to the log file of the instance'server""" |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
760 |
if self.mode == 'user': |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
3059
diff
changeset
|
761 |
basepath = join(tempfile.gettempdir(), '%s-%s' % (basename(self.appid), self.name)) |
0 | 762 |
path = basepath + '.log' |
763 |
i = 1 |
|
764 |
while exists(path) and i < 100: # arbitrary limit to avoid infinite loop |
|
765 |
try: |
|
766 |
file(path, 'a') |
|
767 |
break |
|
768 |
except IOError: |
|
769 |
path = '%s-%s.log' % (basepath, i) |
|
770 |
i += 1 |
|
771 |
return path |
|
772 |
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
|
1446 | 773 |
|
0 | 774 |
def default_pid_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
775 |
"""return default path to the pid file of the instance'server""" |
0 | 776 |
return join(self.runtime_dir(), '%s-%s.pid' % (self.appid, self.name)) |
1446 | 777 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
778 |
# instance methods used to get instance specific resources ############# |
1446 | 779 |
|
0 | 780 |
def __init__(self, appid): |
781 |
self.appid = appid |
|
782 |
CubicWebNoAppConfiguration.__init__(self) |
|
783 |
self._cubes = None |
|
784 |
self._site_loaded = set() |
|
785 |
self.load_file_configuration(self.main_config_file()) |
|
786 |
||
787 |
def adjust_sys_path(self): |
|
788 |
CubicWebNoAppConfiguration.adjust_sys_path(self) |
|
789 |
# adding apphome to python path is not usually necessary in production |
|
790 |
# environments, but necessary for tests |
|
791 |
if self.apphome and not self.apphome in sys.path: |
|
792 |
sys.path.insert(0, self.apphome) |
|
793 |
||
794 |
@property |
|
795 |
def apphome(self): |
|
796 |
return join(self.registry_dir(), self.appid) |
|
1446 | 797 |
|
0 | 798 |
@property |
799 |
def appdatahome(self): |
|
800 |
return join(self.instance_data_dir(), self.appid) |
|
1446 | 801 |
|
0 | 802 |
def init_cubes(self, cubes): |
1681
1586c0ed9a92
nicer assertion message
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1521
diff
changeset
|
803 |
assert self._cubes is None, self._cubes |
0 | 804 |
self._cubes = self.reorder_cubes(cubes) |
805 |
# load cubes'__init__.py file first |
|
806 |
for cube in cubes: |
|
807 |
__import__('cubes.%s' % cube) |
|
808 |
self.load_site_cubicweb() |
|
809 |
# reload config file in cases options are defined in cubes __init__ |
|
810 |
# or site_cubicweb files |
|
811 |
self.load_file_configuration(self.main_config_file()) |
|
812 |
# configuration initialization hook |
|
813 |
self.load_configuration() |
|
1446 | 814 |
|
0 | 815 |
def cubes(self): |
816 |
"""return the list of cubes used by this instance |
|
817 |
||
818 |
result is ordered from the top level cubes to inner dependencies |
|
819 |
cubes |
|
820 |
""" |
|
821 |
assert self._cubes is not None |
|
822 |
return self._cubes |
|
1446 | 823 |
|
0 | 824 |
def cubes_path(self): |
825 |
"""return the list of path to cubes used by this instance, from outer |
|
826 |
most to inner most cubes |
|
827 |
""" |
|
828 |
return [self.cube_dir(p) for p in self.cubes()] |
|
829 |
||
830 |
def add_cubes(self, cubes): |
|
831 |
"""add given cubes to the list of used cubes""" |
|
832 |
if not isinstance(cubes, list): |
|
833 |
cubes = list(cubes) |
|
834 |
self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
|
1446 | 835 |
|
0 | 836 |
def main_config_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
837 |
"""return instance's control configuration file""" |
0 | 838 |
return join(self.apphome, '%s.conf' % self.name) |
1446 | 839 |
|
0 | 840 |
def save(self): |
841 |
"""write down current configuration""" |
|
842 |
self.generate_config(open(self.main_config_file(), 'w')) |
|
843 |
||
844 |
@cached |
|
845 |
def instance_md5_version(self): |
|
846 |
import md5 |
|
847 |
infos = [] |
|
848 |
for pkg in self.cubes(): |
|
849 |
version = self.cube_version(pkg) |
|
850 |
infos.append('%s-%s' % (pkg, version)) |
|
851 |
return md5.new(';'.join(infos)).hexdigest() |
|
1446 | 852 |
|
0 | 853 |
def load_site_cubicweb(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
854 |
"""load instance's specific site_cubicweb file""" |
0 | 855 |
for path in reversed([self.apphome] + self.cubes_path()): |
856 |
sitefile = join(path, 'site_cubicweb.py') |
|
857 |
if exists(sitefile) and not sitefile in self._site_loaded: |
|
858 |
self._load_site_cubicweb(sitefile) |
|
859 |
self._site_loaded.add(sitefile) |
|
860 |
else: |
|
861 |
sitefile = join(path, 'site_erudi.py') |
|
862 |
if exists(sitefile) and not sitefile in self._site_loaded: |
|
863 |
self._load_site_cubicweb(sitefile) |
|
864 |
self._site_loaded.add(sitefile) |
|
865 |
self.warning('site_erudi.py is deprecated, should be renamed to site_cubicweb.py') |
|
1446 | 866 |
|
0 | 867 |
def _load_site_cubicweb(self, sitefile): |
2220
64aace08ae2f
add __file__ to context before loading site_cubicweb.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
868 |
context = {'__file__': sitefile} |
0 | 869 |
execfile(sitefile, context, context) |
870 |
self.info('%s loaded', sitefile) |
|
871 |
# cube specific options |
|
872 |
if context.get('options'): |
|
873 |
self.register_options(context['options']) |
|
874 |
self.load_defaults() |
|
1446 | 875 |
|
0 | 876 |
def load_configuration(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
877 |
"""load instance's configuration files""" |
0 | 878 |
super(CubicWebConfiguration, self).load_configuration() |
879 |
if self.apphome and self.set_language: |
|
880 |
# init gettext |
|
881 |
self._set_language() |
|
1446 | 882 |
|
0 | 883 |
def init_log(self, logthreshold=None, debug=False, force=False): |
884 |
"""init the log service""" |
|
885 |
if not force and hasattr(self, '_logging_initialized'): |
|
886 |
return |
|
887 |
self._logging_initialized = True |
|
888 |
CubicWebNoAppConfiguration.init_log(self, logthreshold, debug, |
|
2654
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
889 |
logfile=self.get('log-file')) |
0 | 890 |
# read a config file if it exists |
891 |
logconfig = join(self.apphome, 'logging.conf') |
|
892 |
if exists(logconfig): |
|
893 |
logging.fileConfig(logconfig) |
|
894 |
||
895 |
def available_languages(self, *args): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
896 |
"""return available translation for an instance, by looking for |
0 | 897 |
compiled catalog |
898 |
||
899 |
take *args to be usable as a vocabulary method |
|
900 |
""" |
|
901 |
from glob import glob |
|
902 |
yield 'en' # ensure 'en' is yielded even if no .mo found |
|
903 |
for path in glob(join(self.apphome, 'i18n', |
|
3118 | 904 |
'*', 'LC_MESSAGES')): |
905 |
lang = path.split(os.sep)[-2] |
|
0 | 906 |
if lang != 'en': |
907 |
yield lang |
|
1446 | 908 |
|
0 | 909 |
def _set_language(self): |
910 |
"""set language for gettext""" |
|
911 |
from gettext import translation |
|
912 |
path = join(self.apphome, 'i18n') |
|
913 |
for language in self.available_languages(): |
|
914 |
self.info("loading language %s", language) |
|
915 |
try: |
|
916 |
tr = translation('cubicweb', path, languages=[language]) |
|
3275
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3270
diff
changeset
|
917 |
self.translations[language] = (tr.ugettext, tr.upgettext) |
0 | 918 |
except (ImportError, AttributeError, IOError): |
919 |
self.exception('localisation support error for language %s', |
|
1446 | 920 |
language) |
921 |
||
0 | 922 |
def vregistry_path(self): |
923 |
"""return a list of files or directories where the registry will look |
|
924 |
for application objects |
|
925 |
""" |
|
926 |
templpath = list(reversed(self.cubes_path())) |
|
927 |
if self.apphome: # may be unset in tests |
|
928 |
templpath.append(self.apphome) |
|
929 |
return self.build_vregistry_path(templpath) |
|
930 |
||
931 |
def set_sources_mode(self, sources): |
|
932 |
if not 'all' in sources: |
|
933 |
print 'warning: ignoring specified sources, requires a repository '\ |
|
934 |
'configuration' |
|
1446 | 935 |
|
0 | 936 |
def migration_handler(self): |
937 |
"""return a migration handler instance""" |
|
938 |
from cubicweb.common.migration import MigrationHelper |
|
939 |
return MigrationHelper(self, verbosity=self.verbosity) |
|
940 |
||
941 |
def i18ncompile(self, langs=None): |
|
942 |
from cubicweb.common import i18n |
|
943 |
if langs is None: |
|
944 |
langs = self.available_languages() |
|
945 |
i18ndir = join(self.apphome, 'i18n') |
|
946 |
if not exists(i18ndir): |
|
947 |
create_dir(i18ndir) |
|
948 |
sourcedirs = [join(path, 'i18n') for path in self.cubes_path()] |
|
949 |
sourcedirs.append(self.i18n_lib_dir()) |
|
950 |
return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs) |
|
951 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
952 |
def sendmails(self, msgs): |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
953 |
"""msgs: list of 2-uple (message object, recipients)""" |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
954 |
server, port = self['smtp-host'], self['smtp-port'] |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
955 |
SMTP_LOCK.acquire() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
956 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
957 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
958 |
smtp = SMTP(server, port) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
959 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
960 |
self.exception("can't connect to smtp server %s:%s (%s)", |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
961 |
server, port, ex) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
962 |
return |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
963 |
heloaddr = '%s <%s>' % (self['sender-name'], self['sender-addr']) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
964 |
for msg, recipients in msgs: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
965 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
966 |
smtp.sendmail(heloaddr, recipients, msg.as_string()) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
967 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
968 |
self.exception("error sending mail to %s (%s)", |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
969 |
recipients, ex) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
970 |
smtp.close() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
971 |
finally: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
972 |
SMTP_LOCK.release() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
973 |
|
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
974 |
set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration')) |
1446 | 975 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
976 |
# alias to get a configuration instance from an instance id |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
977 |
instance_configuration = CubicWebConfiguration.config_for |
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
978 |
application_configuration = deprecated('use instance_configuration')(instance_configuration) |