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