author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 25 Mar 2010 14:49:24 +0100 | |
branch | stable |
changeset 5018 | 2f2d9bc6dca4 |
parent 5013 | ad91f93bbb93 |
child 5021 | 58e89f3dfbae |
child 5043 | fe52dd3936cf |
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 |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4120
diff
changeset
|
5 |
:copyright: 2001-2010 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 |
|
4135
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
81 |
import tempfile |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
82 |
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
|
83 |
from threading import Lock |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
84 |
from os.path import exists, join, expanduser, abspath, normpath, basename, isdir |
4135
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
85 |
from warnings import warn |
0 | 86 |
|
4323
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
87 |
from logilab.common.decorators import cached, classproperty |
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
88 |
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
|
89 |
from logilab.common.logging_ext import set_log_methods, init_log |
0 | 90 |
from logilab.common.configuration import (Configuration, Method, |
91 |
ConfigurationMixIn, merge_options) |
|
92 |
||
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
93 |
from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
94 |
ConfigurationError, Binary) |
1132 | 95 |
from cubicweb.toolsutils import env_path, create_dir |
0 | 96 |
|
97 |
CONFIGURATIONS = [] |
|
98 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
99 |
SMTP_LOCK = Lock() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
100 |
|
0 | 101 |
|
102 |
class metaconfiguration(type): |
|
103 |
"""metaclass to automaticaly register configuration""" |
|
104 |
def __new__(mcs, name, bases, classdict): |
|
105 |
cls = super(metaconfiguration, mcs).__new__(mcs, name, bases, classdict) |
|
106 |
if classdict.get('name'): |
|
107 |
CONFIGURATIONS.append(cls) |
|
108 |
return cls |
|
109 |
||
110 |
def configuration_cls(name): |
|
111 |
"""return the configuration class registered with the given name""" |
|
112 |
try: |
|
113 |
return [c for c in CONFIGURATIONS if c.name == name][0] |
|
114 |
except IndexError: |
|
115 |
raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
|
116 |
||
117 |
def possible_configurations(directory): |
|
118 |
"""return a list of installed configurations in a directory |
|
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4889
diff
changeset
|
119 |
according to \*-ctl files |
0 | 120 |
""" |
121 |
return [name for name in ('repository', 'twisted', 'all-in-one') |
|
122 |
if exists(join(directory, '%s.conf' % name))] |
|
123 |
||
124 |
def guess_configuration(directory): |
|
125 |
"""try to guess the configuration to use for a directory. If multiple |
|
126 |
configurations are found, ConfigurationError is raised |
|
127 |
""" |
|
128 |
modes = possible_configurations(directory) |
|
129 |
if len(modes) != 1: |
|
130 |
raise ConfigurationError('unable to guess configuration from %r %s' |
|
131 |
% (directory, modes)) |
|
132 |
return modes[0] |
|
133 |
||
134 |
||
135 |
# persistent options definition |
|
136 |
PERSISTENT_OPTIONS = ( |
|
137 |
('encoding', |
|
138 |
{'type' : 'string', |
|
139 |
'default': 'UTF-8', |
|
140 |
'help': _('user interface encoding'), |
|
141 |
'group': 'ui', 'sitewide': True, |
|
1446 | 142 |
}), |
0 | 143 |
('language', |
144 |
{'type' : 'string', |
|
145 |
'default': 'en', |
|
146 |
'vocabulary': Method('available_languages'), |
|
147 |
'help': _('language of the user interface'), |
|
1446 | 148 |
'group': 'ui', |
0 | 149 |
}), |
150 |
('date-format', |
|
151 |
{'type' : 'string', |
|
152 |
'default': '%Y/%m/%d', |
|
153 |
'help': _('how to format date in the ui ("man strftime" for format description)'), |
|
1446 | 154 |
'group': 'ui', |
0 | 155 |
}), |
156 |
('datetime-format', |
|
157 |
{'type' : 'string', |
|
158 |
'default': '%Y/%m/%d %H:%M', |
|
159 |
'help': _('how to format date and time in the ui ("man strftime" for format description)'), |
|
1446 | 160 |
'group': 'ui', |
0 | 161 |
}), |
162 |
('time-format', |
|
163 |
{'type' : 'string', |
|
164 |
'default': '%H:%M', |
|
165 |
'help': _('how to format time in the ui ("man strftime" for format description)'), |
|
1446 | 166 |
'group': 'ui', |
0 | 167 |
}), |
168 |
('float-format', |
|
169 |
{'type' : 'string', |
|
170 |
'default': '%.3f', |
|
171 |
'help': _('how to format float numbers in the ui'), |
|
1446 | 172 |
'group': 'ui', |
0 | 173 |
}), |
174 |
('default-text-format', |
|
175 |
{'type' : 'choice', |
|
176 |
'choices': ('text/plain', 'text/rest', 'text/html'), |
|
177 |
'default': 'text/html', # use fckeditor in the web ui |
|
178 |
'help': _('default text format for rich text fields.'), |
|
1446 | 179 |
'group': 'ui', |
0 | 180 |
}), |
181 |
('short-line-size', |
|
182 |
{'type' : 'int', |
|
183 |
'default': 40, |
|
184 |
'help': _('maximum number of characters in short description'), |
|
185 |
'group': 'navigation', |
|
186 |
}), |
|
187 |
) |
|
188 |
||
189 |
def register_persistent_options(options): |
|
190 |
global PERSISTENT_OPTIONS |
|
191 |
PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options) |
|
1446 | 192 |
|
0 | 193 |
CFGTYPE2ETYPE_MAP = { |
194 |
'string': 'String', |
|
195 |
'choice': 'String', |
|
196 |
'yn': 'Boolean', |
|
197 |
'int': 'Int', |
|
198 |
'float' : 'Float', |
|
199 |
} |
|
1446 | 200 |
|
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
|
201 |
_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
|
202 |
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
|
203 |
|
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
|
204 |
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
|
205 |
|
0 | 206 |
class CubicWebNoAppConfiguration(ConfigurationMixIn): |
207 |
"""base class for cubicweb configuration without a specific instance directory |
|
208 |
""" |
|
209 |
__metaclass__ = metaconfiguration |
|
210 |
# to set in concrete configuration |
|
211 |
name = None |
|
212 |
# log messages format (see logging module documentation for available keys) |
|
213 |
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
|
214 |
# nor remove appobjects based on unused interface |
0 | 215 |
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
|
216 |
# debug mode |
3641
cf30e4498674
fix debug attribute conflict on configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3640
diff
changeset
|
217 |
debugmode = False |
0 | 218 |
|
219 |
if os.environ.get('APYCOT_ROOT'): |
|
220 |
mode = 'test' |
|
4889
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
221 |
# allow to test cubes within apycot using cubicweb not installed by |
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
222 |
# apycot |
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
223 |
if __file__.startswith(os.environ['APYCOT_ROOT']): |
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
|
224 |
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
|
225 |
# 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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
mode = 'user' |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
231 |
CUBES_DIR = abspath(normpath(join(CW_SOFTWARE_ROOT, '../cubes'))) |
0 | 232 |
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
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
mode = 'system' |
0 | 237 |
CUBES_DIR = '/usr/share/cubicweb/cubes/' |
238 |
||
1046
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
239 |
options = ( |
0 | 240 |
('log-threshold', |
241 |
{'type' : 'string', # XXX use a dedicated type? |
|
4624
1b46d5ece0d5
turn default logging threshold to warning (we usually want them), and log 'no schema for eid' pb using warning instead of error, so we see them in logs but not during migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4606
diff
changeset
|
242 |
'default': 'WARNING', |
0 | 243 |
'help': 'server\'s log level', |
244 |
'group': 'main', 'inputlevel': 1, |
|
245 |
}), |
|
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
|
246 |
# 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
|
247 |
('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
|
248 |
{'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
|
249 |
'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
|
250 |
'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
|
251 |
'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
|
252 |
}), |
0 | 253 |
('pyro-ns-host', |
254 |
{'type' : 'string', |
|
378
c0cd7398edff
revert local debug checkin
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
369
diff
changeset
|
255 |
'default': '', |
0 | 256 |
'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
|
257 |
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
|
258 |
'group': 'pyro', 'inputlevel': 1, |
0 | 259 |
}), |
260 |
('pyro-ns-group', |
|
261 |
{'type' : 'string', |
|
262 |
'default': 'cubicweb', |
|
263 |
'help': 'Pyro name server\'s group where the repository will be \ |
|
264 |
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
|
265 |
'group': 'pyro', 'inputlevel': 1, |
0 | 266 |
}), |
267 |
# common configuration options which are potentially required as soon as |
|
268 |
# you're using "base" application objects (ie to really server/web |
|
269 |
# specific) |
|
270 |
('base-url', |
|
271 |
{'type' : 'string', |
|
272 |
'default': None, |
|
273 |
'help': 'web server root url', |
|
274 |
'group': 'main', 'inputlevel': 1, |
|
275 |
}), |
|
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
|
276 |
('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
|
277 |
{'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
|
278 |
'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
|
279 |
'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
|
280 |
'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
|
281 |
}), |
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
|
282 |
('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
|
283 |
{'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
|
284 |
'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
|
285 |
'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
|
286 |
'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
|
287 |
'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
|
288 |
'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
|
289 |
}), |
0 | 290 |
('mangle-emails', |
291 |
{'type' : 'yn', |
|
292 |
'default': False, |
|
293 |
'help': "don't display actual email addresses but mangle them if \ |
|
294 |
this option is set to yes", |
|
295 |
'group': 'email', 'inputlevel': 2, |
|
296 |
}), |
|
297 |
) |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
298 |
# static and class methods used to get instance independant resources ## |
1446 | 299 |
|
0 | 300 |
@staticmethod |
301 |
def cubicweb_version(): |
|
302 |
"""return installed cubicweb version""" |
|
303 |
from logilab.common.changelog import Version |
|
304 |
from cubicweb import __pkginfo__ |
|
305 |
version = __pkginfo__.numversion |
|
306 |
assert len(version) == 3, version |
|
307 |
return Version(version) |
|
1446 | 308 |
|
0 | 309 |
@staticmethod |
310 |
def persistent_options_configuration(): |
|
311 |
return Configuration(options=PERSISTENT_OPTIONS) |
|
312 |
||
313 |
@classmethod |
|
314 |
def shared_dir(cls): |
|
315 |
"""return the shared data directory (i.e. directory where standard |
|
316 |
library views and data may be found) |
|
317 |
""" |
|
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
|
318 |
if CWDEV: |
0 | 319 |
return join(CW_SOFTWARE_ROOT, 'web') |
1039 | 320 |
return cls.cube_dir('shared') |
1446 | 321 |
|
0 | 322 |
@classmethod |
323 |
def i18n_lib_dir(cls): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
324 |
"""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
|
325 |
if CWDEV: |
0 | 326 |
return join(CW_SOFTWARE_ROOT, 'i18n') |
327 |
return join(cls.shared_dir(), 'i18n') |
|
328 |
||
329 |
@classmethod |
|
330 |
def available_cubes(cls): |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
331 |
cubes = set() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
332 |
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
|
333 |
if not os.path.exists(directory): |
4605
7f884ee28519
fix dumb name error triggering crash when some directory in cubes search path doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
334 |
cls.error('unexistant directory in cubes search path: %s' |
4001
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
335 |
% directory) |
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
336 |
continue |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
337 |
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
|
338 |
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
|
339 |
cubes.add(cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
340 |
return sorted(cubes) |
1446 | 341 |
|
0 | 342 |
@classmethod |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
343 |
def cubes_search_path(cls): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
344 |
"""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
|
345 |
path = [] |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
346 |
try: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
347 |
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
|
348 |
directory = abspath(normpath(directory)) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
349 |
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
|
350 |
path.append(directory) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
351 |
except KeyError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
352 |
pass |
4606
3b7ce7036b19
dont add CUBES_DIR to cubes search path if it doesn't exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4605
diff
changeset
|
353 |
if not cls.CUBES_DIR in path and exists(cls.CUBES_DIR): |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
354 |
path.append(cls.CUBES_DIR) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
355 |
return path |
1446 | 356 |
|
4323
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
357 |
@classproperty |
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
358 |
def extrapath(cls): |
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
359 |
extrapath = {} |
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
360 |
for cubesdir in cls.cubes_search_path(): |
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
361 |
if cubesdir != cls.CUBES_DIR: |
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
362 |
extrapath[cubesdir] = 'cubes' |
4325 | 363 |
return extrapath |
4323
aae19998dd93
move extra path computing as a configuration class property so we can reused it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4322
diff
changeset
|
364 |
|
0 | 365 |
@classmethod |
366 |
def cube_dir(cls, cube): |
|
367 |
"""return the cube directory for the given cube id, |
|
368 |
raise ConfigurationError if it doesn't exists |
|
369 |
""" |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
370 |
for directory in cls.cubes_search_path(): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
371 |
cubedir = join(directory, cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
372 |
if exists(cubedir): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
373 |
return cubedir |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
374 |
raise ConfigurationError('no cube %s in %s' % (cube, cls.cubes_search_path())) |
0 | 375 |
|
376 |
@classmethod |
|
377 |
def cube_migration_scripts_dir(cls, cube): |
|
378 |
"""cube migration scripts directory""" |
|
379 |
return join(cls.cube_dir(cube), 'migration') |
|
1446 | 380 |
|
0 | 381 |
@classmethod |
382 |
def cube_pkginfo(cls, cube): |
|
383 |
"""return the information module for the given cube""" |
|
384 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
385 |
try: |
|
386 |
return getattr(__import__('cubes.%s.__pkginfo__' % cube), cube).__pkginfo__ |
|
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
387 |
except Exception, ex: |
0 | 388 |
raise ConfigurationError('unable to find packaging information for ' |
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
389 |
'cube %s (%s: %s)' % (cube, ex.__class__.__name__, ex)) |
0 | 390 |
|
391 |
@classmethod |
|
392 |
def cube_version(cls, cube): |
|
1446 | 393 |
"""return the version of the cube located in the given directory |
0 | 394 |
""" |
395 |
from logilab.common.changelog import Version |
|
396 |
version = cls.cube_pkginfo(cube).numversion |
|
397 |
assert len(version) == 3, version |
|
398 |
return Version(version) |
|
399 |
||
400 |
@classmethod |
|
401 |
def cube_dependencies(cls, cube): |
|
402 |
"""return cubicweb cubes used by the given cube""" |
|
403 |
return getattr(cls.cube_pkginfo(cube), '__use__', ()) |
|
404 |
||
405 |
@classmethod |
|
406 |
def cube_recommends(cls, cube): |
|
407 |
"""return cubicweb cubes recommended by the given cube""" |
|
408 |
return getattr(cls.cube_pkginfo(cube), '__recommend__', ()) |
|
409 |
||
410 |
@classmethod |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
411 |
def expand_cubes(cls, cubes, with_recommends=False): |
0 | 412 |
"""expand the given list of top level cubes used by adding recursivly |
413 |
each cube dependencies |
|
414 |
""" |
|
415 |
cubes = list(cubes) |
|
416 |
todo = cubes[:] |
|
417 |
while todo: |
|
418 |
cube = todo.pop(0) |
|
419 |
for depcube in cls.cube_dependencies(cube): |
|
420 |
if depcube not in cubes: |
|
421 |
depcube = CW_MIGRATION_MAP.get(depcube, depcube) |
|
422 |
cubes.append(depcube) |
|
423 |
todo.append(depcube) |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
424 |
if with_recommends: |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
425 |
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
|
426 |
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
|
427 |
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
|
428 |
cubes.append(depcube) |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
429 |
todo.append(depcube) |
0 | 430 |
return cubes |
431 |
||
432 |
@classmethod |
|
433 |
def reorder_cubes(cls, cubes): |
|
434 |
"""reorder cubes from the top level cubes to inner dependencies |
|
435 |
cubes |
|
436 |
""" |
|
437 |
from logilab.common.graph import get_cycles |
|
438 |
graph = {} |
|
439 |
for cube in cubes: |
|
440 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
441 |
deps = cls.cube_dependencies(cube) + \ |
|
442 |
cls.cube_recommends(cube) |
|
443 |
graph[cube] = set(dep for dep in deps if dep in cubes) |
|
444 |
cycles = get_cycles(graph) |
|
445 |
if cycles: |
|
446 |
cycles = '\n'.join(' -> '.join(cycle) for cycle in cycles) |
|
447 |
raise ConfigurationError('cycles in cubes dependencies: %s' |
|
448 |
% cycles) |
|
449 |
cubes = [] |
|
450 |
while graph: |
|
451 |
# sorted to get predictable results |
|
452 |
for cube, deps in sorted(graph.items()): |
|
453 |
if not deps: |
|
454 |
cubes.append(cube) |
|
455 |
del graph[cube] |
|
456 |
for deps in graph.itervalues(): |
|
457 |
try: |
|
458 |
deps.remove(cube) |
|
459 |
except KeyError: |
|
460 |
continue |
|
461 |
return tuple(reversed(cubes)) |
|
1446 | 462 |
|
0 | 463 |
@classmethod |
464 |
def cls_adjust_sys_path(cls): |
|
465 |
"""update python path if necessary""" |
|
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
466 |
cubes_parent_dir = normpath(join(cls.CUBES_DIR, '..')) |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
467 |
if not cubes_parent_dir in sys.path: |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
468 |
sys.path.insert(0, cubes_parent_dir) |
0 | 469 |
try: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
470 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
471 |
cubes.__path__ = cls.cubes_search_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
472 |
except ImportError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
473 |
return # cubes dir doesn't exists |
0 | 474 |
|
475 |
@classmethod |
|
476 |
def load_cwctl_plugins(cls): |
|
477 |
from logilab.common.modutils import load_module_from_file |
|
478 |
cls.cls_adjust_sys_path() |
|
479 |
for ctlfile in ('web/webctl.py', 'etwist/twctl.py', |
|
4606
3b7ce7036b19
dont add CUBES_DIR to cubes search path if it doesn't exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4605
diff
changeset
|
480 |
'server/serverctl.py', |
0 | 481 |
'devtools/devctl.py', 'goa/goactl.py'): |
482 |
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
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
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
|
487 |
(ctlfile, err)) |
0 | 488 |
cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
489 |
for cube in cls.available_cubes(): |
|
4135
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
490 |
oldpluginfile = join(cls.cube_dir(cube), 'ecplugin.py') |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
491 |
pluginfile = join(cls.cube_dir(cube), 'ccplugin.py') |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
492 |
initfile = join(cls.cube_dir(cube), '__init__.py') |
0 | 493 |
if exists(pluginfile): |
494 |
try: |
|
4135
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
495 |
__import__('cubes.%s.ccplugin' % cube) |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
496 |
cls.info('loaded cubicweb-ctl plugin from %s', cube) |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
497 |
except: |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
498 |
cls.exception('while loading plugin %s', pluginfile) |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
499 |
elif exists(oldpluginfile): |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
500 |
warn('[3.6] %s: ecplugin module should be renamed to ccplugin' % cube, |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
501 |
DeprecationWarning) |
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
502 |
try: |
0 | 503 |
__import__('cubes.%s.ecplugin' % cube) |
504 |
cls.info('loaded cubicweb-ctl plugin from %s', cube) |
|
505 |
except: |
|
4135
cb0d0bf255f7
look for cubicweb-ctl plugins in the ccplugin.py file, keeping bw compat on ecplugin.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
506 |
cls.exception('while loading plugin %s', oldpluginfile) |
0 | 507 |
elif exists(initfile): |
508 |
try: |
|
509 |
__import__('cubes.%s' % cube) |
|
510 |
except: |
|
511 |
cls.exception('while loading cube %s', cube) |
|
512 |
else: |
|
1446 | 513 |
cls.warning('no __init__ file in cube %s', cube) |
0 | 514 |
|
515 |
@classmethod |
|
516 |
def init_available_cubes(cls): |
|
517 |
"""cubes may register some sources (svnfile for instance) in their |
|
518 |
__init__ file, so they should be loaded early in the startup process |
|
519 |
""" |
|
520 |
for cube in cls.available_cubes(): |
|
521 |
try: |
|
522 |
__import__('cubes.%s' % cube) |
|
523 |
except Exception, ex: |
|
524 |
cls.warning("can't init cube %s: %s", cube, ex) |
|
1446 | 525 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
526 |
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
|
527 |
cube_appobject_path = set(['entities']) |
0 | 528 |
|
529 |
@classmethod |
|
530 |
def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None): |
|
531 |
"""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
|
532 |
directories that should be loaded by the instance objects registry. |
0 | 533 |
|
534 |
:param evobjpath: |
|
535 |
optional list of sub-directories (or files without the .py ext) of |
|
536 |
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
|
537 |
if they exists. If not give, default to `cubicweb_appobject_path` class |
0 | 538 |
attribute. |
539 |
:param tvobjpath: |
|
540 |
optional list of sub-directories (or files without the .py ext) of |
|
541 |
directories given in `templpath` that should be tested and added to |
|
542 |
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
|
543 |
`cube_appobject_path` class attribute. |
0 | 544 |
""" |
545 |
vregpath = cls.build_vregistry_cubicweb_path(evobjpath) |
|
546 |
vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath) |
|
547 |
return vregpath |
|
548 |
||
549 |
@classmethod |
|
550 |
def build_vregistry_cubicweb_path(cls, evobjpath=None): |
|
551 |
vregpath = [] |
|
552 |
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
|
553 |
evobjpath = cls.cubicweb_appobject_path |
0 | 554 |
for subdir in evobjpath: |
555 |
path = join(CW_SOFTWARE_ROOT, subdir) |
|
556 |
if exists(path): |
|
557 |
vregpath.append(path) |
|
558 |
return vregpath |
|
559 |
||
560 |
@classmethod |
|
561 |
def build_vregistry_cube_path(cls, templpath, tvobjpath=None): |
|
562 |
vregpath = [] |
|
563 |
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
|
564 |
tvobjpath = cls.cube_appobject_path |
0 | 565 |
for directory in templpath: |
566 |
for subdir in tvobjpath: |
|
567 |
path = join(directory, subdir) |
|
568 |
if exists(path): |
|
569 |
vregpath.append(path) |
|
570 |
elif exists(path + '.py'): |
|
571 |
vregpath.append(path + '.py') |
|
572 |
return vregpath |
|
1446 | 573 |
|
0 | 574 |
def __init__(self): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
575 |
register_stored_procedures() |
0 | 576 |
ConfigurationMixIn.__init__(self) |
577 |
self.adjust_sys_path() |
|
578 |
self.load_defaults() |
|
1446 | 579 |
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
|
580 |
# 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
|
581 |
# 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
|
582 |
# 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
|
583 |
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
|
584 |
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
|
585 |
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
|
586 |
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
|
587 |
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
|
588 |
cw_rest_init() |
0 | 589 |
|
590 |
def adjust_sys_path(self): |
|
591 |
self.cls_adjust_sys_path() |
|
1446 | 592 |
|
593 |
def init_log(self, logthreshold=None, debug=False, |
|
0 | 594 |
logfile=None, syslog=False): |
595 |
"""init the log service""" |
|
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
596 |
if logthreshold is None: |
0 | 597 |
if debug: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
598 |
logthreshold = 'DEBUG' |
0 | 599 |
else: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
600 |
logthreshold = self['log-threshold'] |
3641
cf30e4498674
fix debug attribute conflict on configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3640
diff
changeset
|
601 |
self.debugmode = debug |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
602 |
init_log(debug, syslog, logthreshold, logfile, self.log_format) |
0 | 603 |
# configure simpleTal logger |
604 |
logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
|
605 |
||
606 |
def vregistry_path(self): |
|
607 |
"""return a list of files or directories where the registry will look |
|
608 |
for application objects. By default return nothing in NoApp config. |
|
609 |
""" |
|
610 |
return [] |
|
1446 | 611 |
|
0 | 612 |
def eproperty_definitions(self): |
613 |
cfg = self.persistent_options_configuration() |
|
614 |
for section, options in cfg.options_by_section(): |
|
615 |
section = section.lower() |
|
616 |
for optname, optdict, value in options: |
|
617 |
key = '%s.%s' % (section, optname) |
|
618 |
type, vocab = self.map_option(optdict) |
|
619 |
default = cfg.option_default(optname, optdict) |
|
620 |
pdef = {'type': type, 'vocabulary': vocab, 'default': default, |
|
621 |
'help': optdict['help'], |
|
622 |
'sitewide': optdict.get('sitewide', False)} |
|
623 |
yield key, pdef |
|
1446 | 624 |
|
0 | 625 |
def map_option(self, optdict): |
626 |
try: |
|
627 |
vocab = optdict['choices'] |
|
628 |
except KeyError: |
|
629 |
vocab = optdict.get('vocabulary') |
|
630 |
if isinstance(vocab, Method): |
|
631 |
vocab = getattr(self, vocab.method, ()) |
|
632 |
return CFGTYPE2ETYPE_MAP[optdict['type']], vocab |
|
633 |
||
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
|
634 |
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
|
635 |
"""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
|
636 |
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
|
637 |
""" |
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
|
638 |
return None |
1446 | 639 |
|
0 | 640 |
class CubicWebConfiguration(CubicWebNoAppConfiguration): |
641 |
"""base class for cubicweb server and web configurations""" |
|
1446 | 642 |
|
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
|
643 |
INSTANCES_DATA_DIR = None |
4889
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
644 |
if os.environ.get('APYCOT_ROOT'): |
0 | 645 |
root = os.environ['APYCOT_ROOT'] |
646 |
REGISTRY_DIR = '%s/etc/cubicweb.d/' % root |
|
4889
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
647 |
if not exists(REGISTRY_DIR): |
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
648 |
os.makedirs(REGISTRY_DIR) |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
3059
diff
changeset
|
649 |
RUNTIME_DIR = tempfile.gettempdir() |
4889
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
650 |
# allow to test cubes within apycot using cubicweb not installed by |
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
651 |
# apycot |
b3e2de8f53cd
fix apycot detection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
652 |
if __file__.startswith(os.environ['APYCOT_ROOT']): |
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
|
653 |
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
|
654 |
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
|
655 |
MIGRATION_DIR = '/usr/share/cubicweb/migration/' |
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
|
656 |
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
|
657 |
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
|
658 |
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
|
659 |
RUNTIME_DIR = tempfile.gettempdir() |
3640 | 660 |
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
|
661 |
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
|
662 |
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
|
663 |
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
|
664 |
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
|
665 |
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
|
666 |
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
|
667 |
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
|
668 |
MIGRATION_DIR = '/usr/share/cubicweb/migration/' |
0 | 669 |
|
670 |
# for some commands (creation...) we don't want to initialize gettext |
|
671 |
set_language = True |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
672 |
# set this to true to avoid false error message while creating an instance |
0 | 673 |
creating = False |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2449
diff
changeset
|
674 |
# 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
|
675 |
repairing = False |
1446 | 676 |
|
0 | 677 |
options = CubicWebNoAppConfiguration.options + ( |
678 |
('log-file', |
|
679 |
{'type' : 'string', |
|
680 |
'default': Method('default_log_file'), |
|
681 |
'help': 'file where output logs should be written', |
|
682 |
'group': 'main', 'inputlevel': 2, |
|
683 |
}), |
|
684 |
# email configuration |
|
685 |
('smtp-host', |
|
686 |
{'type' : 'string', |
|
687 |
'default': 'mail', |
|
688 |
'help': 'hostname of the SMTP mail server', |
|
689 |
'group': 'email', 'inputlevel': 1, |
|
690 |
}), |
|
691 |
('smtp-port', |
|
692 |
{'type' : 'int', |
|
693 |
'default': 25, |
|
694 |
'help': 'listening port of the SMTP mail server', |
|
695 |
'group': 'email', 'inputlevel': 1, |
|
696 |
}), |
|
697 |
('sender-name', |
|
698 |
{'type' : 'string', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
699 |
'default': Method('default_instance_id'), |
0 | 700 |
'help': 'name used as HELO name for outgoing emails from the \ |
701 |
repository.', |
|
702 |
'group': 'email', 'inputlevel': 2, |
|
703 |
}), |
|
704 |
('sender-addr', |
|
705 |
{'type' : 'string', |
|
2351
dddee537e4d5
don't use internal address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
706 |
'default': 'cubicweb@mydomain.com', |
0 | 707 |
'help': 'email address used as HELO address for outgoing emails from \ |
708 |
the repository', |
|
709 |
'group': 'email', 'inputlevel': 1, |
|
710 |
}), |
|
711 |
) |
|
712 |
||
713 |
@classmethod |
|
714 |
def runtime_dir(cls): |
|
715 |
"""run time directory for pid file...""" |
|
2445
6f065b366d14
rename environment variables
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2351
diff
changeset
|
716 |
return env_path('CW_RUNTIME_DIR', cls.RUNTIME_DIR, 'run time') |
1446 | 717 |
|
0 | 718 |
@classmethod |
719 |
def registry_dir(cls): |
|
720 |
"""return the control directory""" |
|
2445
6f065b366d14
rename environment variables
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2351
diff
changeset
|
721 |
return env_path('CW_INSTANCES_DIR', cls.REGISTRY_DIR, 'registry') |
0 | 722 |
|
723 |
@classmethod |
|
724 |
def instance_data_dir(cls): |
|
725 |
"""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
|
726 |
return env_path('CW_INSTANCES_DATA_DIR', cls.INSTANCES_DATA_DIR, |
0 | 727 |
'additional data') |
1446 | 728 |
|
0 | 729 |
@classmethod |
730 |
def migration_scripts_dir(cls): |
|
731 |
"""cubicweb migration scripts directory""" |
|
2445
6f065b366d14
rename environment variables
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2351
diff
changeset
|
732 |
return env_path('CW_MIGRATION_DIR', cls.MIGRATION_DIR, 'migration') |
0 | 733 |
|
734 |
@classmethod |
|
735 |
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
|
736 |
"""return a configuration instance for the given instance identifier |
0 | 737 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
738 |
config = config or guess_configuration(cls.instance_home(appid)) |
0 | 739 |
configcls = configuration_cls(config) |
740 |
return configcls(appid) |
|
1446 | 741 |
|
0 | 742 |
@classmethod |
743 |
def possible_configurations(cls, appid): |
|
744 |
"""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
|
745 |
instance id |
0 | 746 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
747 |
home = cls.instance_home(appid) |
0 | 748 |
return possible_configurations(home) |
1446 | 749 |
|
0 | 750 |
@classmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
751 |
def instance_home(cls, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
752 |
"""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
|
753 |
instance id |
0 | 754 |
""" |
755 |
home = join(cls.registry_dir(), appid) |
|
756 |
if not exists(home): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
757 |
raise ConfigurationError('no such instance %s (check it exists with "cubicweb-ctl list")' % appid) |
0 | 758 |
return home |
759 |
||
760 |
MODES = ('common', 'repository', 'Any', 'web') |
|
761 |
MCOMPAT = {'all-in-one': MODES, |
|
762 |
'repository': ('common', 'repository', 'Any'), |
|
763 |
'twisted' : ('common', 'web'),} |
|
764 |
@classmethod |
|
765 |
def accept_mode(cls, mode): |
|
766 |
#assert mode in cls.MODES, mode |
|
767 |
return mode in cls.MCOMPAT[cls.name] |
|
1446 | 768 |
|
0 | 769 |
# default configuration methods ########################################### |
1446 | 770 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
771 |
def default_instance_id(self): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
772 |
"""return the instance identifier, useful for option which need this |
0 | 773 |
as default value |
774 |
""" |
|
775 |
return self.appid |
|
776 |
||
777 |
def default_log_file(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
778 |
"""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
|
779 |
if self.mode == 'user': |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
3059
diff
changeset
|
780 |
basepath = join(tempfile.gettempdir(), '%s-%s' % (basename(self.appid), self.name)) |
0 | 781 |
path = basepath + '.log' |
782 |
i = 1 |
|
783 |
while exists(path) and i < 100: # arbitrary limit to avoid infinite loop |
|
784 |
try: |
|
785 |
file(path, 'a') |
|
786 |
break |
|
787 |
except IOError: |
|
788 |
path = '%s-%s.log' % (basepath, i) |
|
789 |
i += 1 |
|
790 |
return path |
|
791 |
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
|
1446 | 792 |
|
0 | 793 |
def default_pid_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
794 |
"""return default path to the pid file of the instance'server""" |
0 | 795 |
return join(self.runtime_dir(), '%s-%s.pid' % (self.appid, self.name)) |
1446 | 796 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
797 |
# instance methods used to get instance specific resources ############# |
1446 | 798 |
|
0 | 799 |
def __init__(self, appid): |
800 |
self.appid = appid |
|
801 |
CubicWebNoAppConfiguration.__init__(self) |
|
802 |
self._cubes = None |
|
803 |
self._site_loaded = set() |
|
804 |
self.load_file_configuration(self.main_config_file()) |
|
805 |
||
806 |
def adjust_sys_path(self): |
|
807 |
CubicWebNoAppConfiguration.adjust_sys_path(self) |
|
808 |
# adding apphome to python path is not usually necessary in production |
|
809 |
# environments, but necessary for tests |
|
810 |
if self.apphome and not self.apphome in sys.path: |
|
811 |
sys.path.insert(0, self.apphome) |
|
812 |
||
813 |
@property |
|
814 |
def apphome(self): |
|
815 |
return join(self.registry_dir(), self.appid) |
|
1446 | 816 |
|
0 | 817 |
@property |
818 |
def appdatahome(self): |
|
819 |
return join(self.instance_data_dir(), self.appid) |
|
1446 | 820 |
|
0 | 821 |
def init_cubes(self, cubes): |
1681
1586c0ed9a92
nicer assertion message
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1521
diff
changeset
|
822 |
assert self._cubes is None, self._cubes |
0 | 823 |
self._cubes = self.reorder_cubes(cubes) |
824 |
# load cubes'__init__.py file first |
|
825 |
for cube in cubes: |
|
826 |
__import__('cubes.%s' % cube) |
|
827 |
self.load_site_cubicweb() |
|
828 |
# reload config file in cases options are defined in cubes __init__ |
|
829 |
# or site_cubicweb files |
|
830 |
self.load_file_configuration(self.main_config_file()) |
|
831 |
# configuration initialization hook |
|
832 |
self.load_configuration() |
|
1446 | 833 |
|
0 | 834 |
def cubes(self): |
835 |
"""return the list of cubes used by this instance |
|
836 |
||
837 |
result is ordered from the top level cubes to inner dependencies |
|
838 |
cubes |
|
839 |
""" |
|
840 |
assert self._cubes is not None |
|
841 |
return self._cubes |
|
1446 | 842 |
|
0 | 843 |
def cubes_path(self): |
844 |
"""return the list of path to cubes used by this instance, from outer |
|
845 |
most to inner most cubes |
|
846 |
""" |
|
847 |
return [self.cube_dir(p) for p in self.cubes()] |
|
848 |
||
849 |
def add_cubes(self, cubes): |
|
850 |
"""add given cubes to the list of used cubes""" |
|
851 |
if not isinstance(cubes, list): |
|
852 |
cubes = list(cubes) |
|
853 |
self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
|
1446 | 854 |
|
0 | 855 |
def main_config_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
856 |
"""return instance's control configuration file""" |
0 | 857 |
return join(self.apphome, '%s.conf' % self.name) |
1446 | 858 |
|
0 | 859 |
def save(self): |
860 |
"""write down current configuration""" |
|
861 |
self.generate_config(open(self.main_config_file(), 'w')) |
|
862 |
||
863 |
@cached |
|
864 |
def instance_md5_version(self): |
|
865 |
import md5 |
|
866 |
infos = [] |
|
867 |
for pkg in self.cubes(): |
|
868 |
version = self.cube_version(pkg) |
|
869 |
infos.append('%s-%s' % (pkg, version)) |
|
870 |
return md5.new(';'.join(infos)).hexdigest() |
|
1446 | 871 |
|
0 | 872 |
def load_site_cubicweb(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
873 |
"""load instance's specific site_cubicweb file""" |
0 | 874 |
for path in reversed([self.apphome] + self.cubes_path()): |
875 |
sitefile = join(path, 'site_cubicweb.py') |
|
876 |
if exists(sitefile) and not sitefile in self._site_loaded: |
|
877 |
self._load_site_cubicweb(sitefile) |
|
878 |
self._site_loaded.add(sitefile) |
|
879 |
else: |
|
880 |
sitefile = join(path, 'site_erudi.py') |
|
881 |
if exists(sitefile) and not sitefile in self._site_loaded: |
|
882 |
self._load_site_cubicweb(sitefile) |
|
883 |
self._site_loaded.add(sitefile) |
|
4326
b930d140d321
add approximated version number to deprecation warning
syt@www.fleurdetomate.fr
parents:
4325
diff
changeset
|
884 |
self.warning('[3.5] site_erudi.py is deprecated, should be renamed to site_cubicweb.py') |
1446 | 885 |
|
0 | 886 |
def _load_site_cubicweb(self, sitefile): |
4324
e817a54cdbc1
we need extrapath when trying to import site_cubicweb files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4323
diff
changeset
|
887 |
# XXX extrapath argument to load_module_from_file only in lgc > 0.46 |
e817a54cdbc1
we need extrapath when trying to import site_cubicweb files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4323
diff
changeset
|
888 |
from logilab.common.modutils import load_module_from_modpath, modpath_from_file |
e817a54cdbc1
we need extrapath when trying to import site_cubicweb files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4323
diff
changeset
|
889 |
def load_module_from_file(filepath, path=None, use_sys=1, extrapath=None): |
e817a54cdbc1
we need extrapath when trying to import site_cubicweb files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4323
diff
changeset
|
890 |
return load_module_from_modpath(modpath_from_file(filepath, extrapath), |
e817a54cdbc1
we need extrapath when trying to import site_cubicweb files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4323
diff
changeset
|
891 |
path, use_sys) |
e817a54cdbc1
we need extrapath when trying to import site_cubicweb files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4323
diff
changeset
|
892 |
module = load_module_from_file(sitefile, extrapath=self.extrapath) |
0 | 893 |
self.info('%s loaded', sitefile) |
894 |
# cube specific options |
|
4120
21517d42f2ed
load site_cubicweb as a module instead of execing it, avoid reimport pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4118
diff
changeset
|
895 |
if getattr(module, 'options', None): |
21517d42f2ed
load site_cubicweb as a module instead of execing it, avoid reimport pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4118
diff
changeset
|
896 |
self.register_options(module.options) |
0 | 897 |
self.load_defaults() |
1446 | 898 |
|
0 | 899 |
def load_configuration(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
900 |
"""load instance's configuration files""" |
0 | 901 |
super(CubicWebConfiguration, self).load_configuration() |
902 |
if self.apphome and self.set_language: |
|
903 |
# init gettext |
|
904 |
self._set_language() |
|
1446 | 905 |
|
0 | 906 |
def init_log(self, logthreshold=None, debug=False, force=False): |
907 |
"""init the log service""" |
|
908 |
if not force and hasattr(self, '_logging_initialized'): |
|
909 |
return |
|
910 |
self._logging_initialized = True |
|
911 |
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
|
912 |
logfile=self.get('log-file')) |
0 | 913 |
# read a config file if it exists |
914 |
logconfig = join(self.apphome, 'logging.conf') |
|
915 |
if exists(logconfig): |
|
916 |
logging.fileConfig(logconfig) |
|
917 |
||
918 |
def available_languages(self, *args): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
919 |
"""return available translation for an instance, by looking for |
0 | 920 |
compiled catalog |
921 |
||
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4889
diff
changeset
|
922 |
take \*args to be usable as a vocabulary method |
0 | 923 |
""" |
924 |
from glob import glob |
|
925 |
yield 'en' # ensure 'en' is yielded even if no .mo found |
|
926 |
for path in glob(join(self.apphome, 'i18n', |
|
3118 | 927 |
'*', 'LC_MESSAGES')): |
928 |
lang = path.split(os.sep)[-2] |
|
0 | 929 |
if lang != 'en': |
930 |
yield lang |
|
1446 | 931 |
|
0 | 932 |
def _set_language(self): |
933 |
"""set language for gettext""" |
|
934 |
from gettext import translation |
|
935 |
path = join(self.apphome, 'i18n') |
|
936 |
for language in self.available_languages(): |
|
937 |
self.info("loading language %s", language) |
|
938 |
try: |
|
939 |
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
|
940 |
self.translations[language] = (tr.ugettext, tr.upgettext) |
0 | 941 |
except (ImportError, AttributeError, IOError): |
942 |
self.exception('localisation support error for language %s', |
|
1446 | 943 |
language) |
944 |
||
0 | 945 |
def vregistry_path(self): |
946 |
"""return a list of files or directories where the registry will look |
|
947 |
for application objects |
|
948 |
""" |
|
949 |
templpath = list(reversed(self.cubes_path())) |
|
950 |
if self.apphome: # may be unset in tests |
|
951 |
templpath.append(self.apphome) |
|
952 |
return self.build_vregistry_path(templpath) |
|
953 |
||
954 |
def set_sources_mode(self, sources): |
|
955 |
if not 'all' in sources: |
|
956 |
print 'warning: ignoring specified sources, requires a repository '\ |
|
957 |
'configuration' |
|
1446 | 958 |
|
0 | 959 |
def migration_handler(self): |
960 |
"""return a migration handler instance""" |
|
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4001
diff
changeset
|
961 |
from cubicweb.migration import MigrationHelper |
0 | 962 |
return MigrationHelper(self, verbosity=self.verbosity) |
963 |
||
964 |
def i18ncompile(self, langs=None): |
|
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4001
diff
changeset
|
965 |
from cubicweb import i18n |
0 | 966 |
if langs is None: |
967 |
langs = self.available_languages() |
|
968 |
i18ndir = join(self.apphome, 'i18n') |
|
969 |
if not exists(i18ndir): |
|
970 |
create_dir(i18ndir) |
|
971 |
sourcedirs = [join(path, 'i18n') for path in self.cubes_path()] |
|
972 |
sourcedirs.append(self.i18n_lib_dir()) |
|
973 |
return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs) |
|
974 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
975 |
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
|
976 |
"""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
|
977 |
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
|
978 |
SMTP_LOCK.acquire() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
979 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
980 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
981 |
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
|
982 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
983 |
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
|
984 |
server, port, ex) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
985 |
return |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
986 |
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
|
987 |
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
|
988 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
989 |
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
|
990 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
991 |
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
|
992 |
recipients, ex) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
993 |
smtp.close() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
994 |
finally: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
995 |
SMTP_LOCK.release() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
996 |
|
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
997 |
set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration')) |
1446 | 998 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
999 |
# 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
|
1000 |
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
|
1001 |
application_configuration = deprecated('use instance_configuration')(instance_configuration) |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1002 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1003 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1004 |
_EXT_REGISTERED = False |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1005 |
def register_stored_procedures(): |
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
1006 |
from logilab.database import FunctionDescr |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1007 |
from rql.utils import register_function, iter_funcnode_variables |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1008 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1009 |
global _EXT_REGISTERED |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1010 |
if _EXT_REGISTERED: |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1011 |
return |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1012 |
_EXT_REGISTERED = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1013 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1014 |
class COMMA_JOIN(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1015 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1016 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1017 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
1018 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1019 |
return ', '.join(sorted(term.get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1020 |
for term in iter_funcnode_variables(funcnode))) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1021 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1022 |
register_function(COMMA_JOIN) # XXX do not expose? |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1023 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1024 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1025 |
class CONCAT_STRINGS(COMMA_JOIN): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1026 |
aggregat = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1027 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1028 |
register_function(CONCAT_STRINGS) # XXX bw compat |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1029 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
1030 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1031 |
class GROUP_CONCAT(CONCAT_STRINGS): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1032 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1033 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1034 |
register_function(GROUP_CONCAT) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1035 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1036 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1037 |
class LIMIT_SIZE(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1038 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1039 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1040 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
1041 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1042 |
return funcnode.children[0].get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1043 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1044 |
register_function(LIMIT_SIZE) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1045 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1046 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1047 |
class TEXT_LIMIT_SIZE(LIMIT_SIZE): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1048 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1049 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1050 |
register_function(TEXT_LIMIT_SIZE) |
4322
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1051 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1052 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1053 |
class FSPATH(FunctionDescr): |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1054 |
"""return path of some bytes attribute stored using the Bytes |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1055 |
File-System Storage (bfss) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1056 |
""" |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1057 |
rtype = 'Bytes' # XXX return a String? potential pb with fs encoding |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1058 |
|
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1059 |
def update_cb_stack(self, stack): |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1060 |
assert len(stack) == 1 |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1061 |
stack[0] = self.source_execute |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1062 |
|
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1063 |
def as_sql(self, backend, args): |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1064 |
raise NotImplementedError('source only callback') |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1065 |
|
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1066 |
def source_execute(self, source, value): |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1067 |
fpath = source.binary_to_str(value) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1068 |
try: |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1069 |
return Binary(fpath) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1070 |
except OSError, ex: |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1071 |
self.critical("can't open %s: %s", fpath, ex) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1072 |
return None |
4322
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1073 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1074 |
register_function(FSPATH) |