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