author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 07 Oct 2010 17:25:24 +0200 | |
branch | stable |
changeset 6406 | 39663630ca3c |
parent 6192 | 80388edf4e88 |
child 6397 | 66401ba9332a |
child 6495 | 3187112bc7cc |
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 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5391
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
19 |
""" |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
20 |
.. _ResourceMode: |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
21 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
22 |
Resource mode |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
23 |
------------- |
0 | 24 |
|
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
25 |
A resource *mode* is a predifined set of settings for various resources |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
26 |
directories, such as cubes, instances, etc. to ease development with the |
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
27 |
framework. There are two running modes with *CubicWeb*: |
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
28 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
29 |
* 'user', resources are searched / created in the user home directory: |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
30 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
31 |
- instances are stored in :file:`~/etc/cubicweb.d` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
32 |
- temporary files (such as pid file) in :file:`/tmp` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
33 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
34 |
* 'system', resources are searched / created in the system directories (eg |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
35 |
usually requiring root access): |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
36 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
37 |
- instances are stored in :file:`<INSTALL_PREFIX>/etc/cubicweb.d` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
38 |
- temporary files (such as pid file) in :file:`/var/run/cubicweb` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
39 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
40 |
where `<INSTALL_PREFIX>` is the detected installation prefix ('/usr/local' for |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
41 |
instance). |
1493 | 42 |
|
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
|
43 |
|
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
44 |
Notice that each resource path may be explicitly set using an environment |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
45 |
variable if the default doesn't suit your needs. Here are the default resource |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
46 |
directories that are affected 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
|
47 |
|
648d6dbec630
system/user modes + CWDEV 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 |
* '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
|
49 |
|
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
50 |
CW_INSTANCES_DIR = <INSTALL_PREFIX>/etc/cubicweb.d/ |
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
|
51 |
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
|
52 |
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
|
53 |
|
6192
80388edf4e88
[doc] improve doc thanks to user feedback
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6143
diff
changeset
|
54 |
* 'user': :: |
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
|
55 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
|
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
60 |
Cubes search path is also affected, see the :ref:Cube section. |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
61 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
62 |
By default, the mode automatically set to 'user' if a :file:`.hg` directory is found |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
63 |
in the cubicweb package, else it's set to 'system'. You can force this by setting |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
64 |
the :envvar:`CW_MODE` environment variable to either 'user' or 'system' so you can |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
65 |
easily: |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
66 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
67 |
* use system wide installation but user specific instances and all, without root |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
68 |
privileges on the system (`export CW_MODE=user`) |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
69 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
70 |
* use local checkout of cubicweb on system wide instances (requires root |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
71 |
privileges on the system (`export CW_MODE=system`) |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
72 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
73 |
If you've a doubt about the mode you're currently running, check the first line |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
74 |
outputed by the :command:`cubicweb-ctl list` command. |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
75 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
76 |
Also, if cubicweb is a mercurial checkout located in `<CW_SOFTWARE_ROOT>`: |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
77 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
78 |
* main cubes directory is `<CW_SOFTWARE_ROOT>/../cubes`. You can specify |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
79 |
another one with :envvar:`CW_INSTANCES_DIR` environment variable or simply |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
80 |
add some other directories by using :envvar:`CW_CUBES_PATH` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
81 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
82 |
* cubicweb migration files are searched in `<CW_SOFTWARE_ROOT>/misc/migration` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
83 |
instead of `<INSTALL_PREFIX>/share/cubicweb/migration/`. |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
84 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
85 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
86 |
.. _ConfigurationEnv: |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
87 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
88 |
Environment configuration |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
89 |
------------------------- |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
90 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
91 |
Python |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
92 |
`````` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
93 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
94 |
If you installed *CubicWeb* by cloning the Mercurial forest or from source |
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
95 |
distribution, then you will need to update the environment variable PYTHONPATH by |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
96 |
adding the path to the forest `cubicweb`: |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
97 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
98 |
Add the following lines to either :file:`.bashrc` or :file:`.bash_profile` to |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
99 |
configure your development environment :: |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
100 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
101 |
export PYTHONPATH=/full/path/to/cubicweb-forest |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
102 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
103 |
If you installed *CubicWeb* with packages, no configuration is required and your |
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
104 |
new cubes will be placed in `/usr/share/cubicweb/cubes` and your instances will |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
105 |
be placed in `/etc/cubicweb.d`. |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
106 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
107 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
108 |
CubicWeb |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
109 |
```````` |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
110 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
111 |
Here are all environment variables that may be used to configure *CubicWeb*: |
3639 | 112 |
|
113 |
.. envvar:: CW_MODE |
|
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
114 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
115 |
Resource mode: user or system, as explained in :ref:`ResourceMode`. |
3639 | 116 |
|
1493 | 117 |
.. envvar:: CW_CUBES_PATH |
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
118 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
119 |
Augments the default search path for cubes. You may specify several |
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
120 |
directories using ':' as separator (';' under windows environment). |
3639 | 121 |
|
122 |
.. envvar:: CW_INSTANCES_DIR |
|
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
123 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
124 |
Directory where cubicweb instances will be found. |
1493 | 125 |
|
3639 | 126 |
.. envvar:: CW_INSTANCES_DATA_DIR |
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
127 |
|
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
128 |
Directory where cubicweb instances data will be written (backup file...) |
3639 | 129 |
|
130 |
.. envvar:: CW_RUNTIME_DIR |
|
5135
f15286235aef
[doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5086
diff
changeset
|
131 |
|
3639 | 132 |
Directory where pid files will be written |
0 | 133 |
""" |
5885
5d908f1a7659
[config] use hashlib to avoid warning w/ py2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5817
diff
changeset
|
134 |
|
0 | 135 |
__docformat__ = "restructuredtext en" |
1948 | 136 |
_ = unicode |
0 | 137 |
|
138 |
import sys |
|
139 |
import os |
|
140 |
import logging |
|
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
141 |
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
|
142 |
from threading import Lock |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
143 |
from os.path import (exists, join, expanduser, abspath, normpath, |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
144 |
basename, isdir, dirname) |
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
|
145 |
from warnings import warn |
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
|
146 |
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
|
147 |
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
|
148 |
from logilab.common.logging_ext import set_log_methods, init_log |
0 | 149 |
from logilab.common.configuration import (Configuration, Method, |
150 |
ConfigurationMixIn, merge_options) |
|
151 |
||
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
152 |
from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
153 |
ConfigurationError, Binary) |
1132 | 154 |
from cubicweb.toolsutils import env_path, create_dir |
0 | 155 |
|
156 |
CONFIGURATIONS = [] |
|
157 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
158 |
SMTP_LOCK = Lock() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
159 |
|
0 | 160 |
|
161 |
class metaconfiguration(type): |
|
162 |
"""metaclass to automaticaly register configuration""" |
|
163 |
def __new__(mcs, name, bases, classdict): |
|
164 |
cls = super(metaconfiguration, mcs).__new__(mcs, name, bases, classdict) |
|
165 |
if classdict.get('name'): |
|
166 |
CONFIGURATIONS.append(cls) |
|
167 |
return cls |
|
168 |
||
169 |
def configuration_cls(name): |
|
170 |
"""return the configuration class registered with the given name""" |
|
171 |
try: |
|
172 |
return [c for c in CONFIGURATIONS if c.name == name][0] |
|
173 |
except IndexError: |
|
174 |
raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
|
175 |
||
176 |
def possible_configurations(directory): |
|
177 |
"""return a list of installed configurations in a directory |
|
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4889
diff
changeset
|
178 |
according to \*-ctl files |
0 | 179 |
""" |
180 |
return [name for name in ('repository', 'twisted', 'all-in-one') |
|
181 |
if exists(join(directory, '%s.conf' % name))] |
|
182 |
||
183 |
def guess_configuration(directory): |
|
184 |
"""try to guess the configuration to use for a directory. If multiple |
|
185 |
configurations are found, ConfigurationError is raised |
|
186 |
""" |
|
187 |
modes = possible_configurations(directory) |
|
188 |
if len(modes) != 1: |
|
189 |
raise ConfigurationError('unable to guess configuration from %r %s' |
|
190 |
% (directory, modes)) |
|
191 |
return modes[0] |
|
192 |
||
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
193 |
def _find_prefix(start_path=CW_SOFTWARE_ROOT): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
194 |
"""Runs along the parent directories of *start_path* (default to cubicweb source directory) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
195 |
looking for one containing a 'share/cubicweb' directory. |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
196 |
The first matching directory is assumed as the prefix installation of cubicweb |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
197 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
198 |
Returns the matching prefix or None. |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
199 |
""" |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
200 |
prefix = start_path |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
201 |
old_prefix = None |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
202 |
if not isdir(start_path): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
203 |
prefix = dirname(start_path) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
204 |
while not isdir(join(prefix, 'share', 'cubicweb')) and prefix != old_prefix: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
205 |
old_prefix = prefix |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
206 |
prefix = dirname(prefix) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
207 |
if isdir(join(prefix, 'share', 'cubicweb')): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
208 |
return prefix |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
209 |
return sys.prefix |
0 | 210 |
|
211 |
# persistent options definition |
|
212 |
PERSISTENT_OPTIONS = ( |
|
213 |
('encoding', |
|
214 |
{'type' : 'string', |
|
215 |
'default': 'UTF-8', |
|
216 |
'help': _('user interface encoding'), |
|
217 |
'group': 'ui', 'sitewide': True, |
|
1446 | 218 |
}), |
0 | 219 |
('language', |
220 |
{'type' : 'string', |
|
221 |
'default': 'en', |
|
222 |
'vocabulary': Method('available_languages'), |
|
223 |
'help': _('language of the user interface'), |
|
1446 | 224 |
'group': 'ui', |
0 | 225 |
}), |
226 |
('date-format', |
|
227 |
{'type' : 'string', |
|
228 |
'default': '%Y/%m/%d', |
|
229 |
'help': _('how to format date in the ui ("man strftime" for format description)'), |
|
1446 | 230 |
'group': 'ui', |
0 | 231 |
}), |
232 |
('datetime-format', |
|
233 |
{'type' : 'string', |
|
234 |
'default': '%Y/%m/%d %H:%M', |
|
235 |
'help': _('how to format date and time in the ui ("man strftime" for format description)'), |
|
1446 | 236 |
'group': 'ui', |
0 | 237 |
}), |
238 |
('time-format', |
|
239 |
{'type' : 'string', |
|
240 |
'default': '%H:%M', |
|
241 |
'help': _('how to format time in the ui ("man strftime" for format description)'), |
|
1446 | 242 |
'group': 'ui', |
0 | 243 |
}), |
244 |
('float-format', |
|
245 |
{'type' : 'string', |
|
246 |
'default': '%.3f', |
|
247 |
'help': _('how to format float numbers in the ui'), |
|
1446 | 248 |
'group': 'ui', |
0 | 249 |
}), |
250 |
('default-text-format', |
|
251 |
{'type' : 'choice', |
|
252 |
'choices': ('text/plain', 'text/rest', 'text/html'), |
|
253 |
'default': 'text/html', # use fckeditor in the web ui |
|
254 |
'help': _('default text format for rich text fields.'), |
|
1446 | 255 |
'group': 'ui', |
0 | 256 |
}), |
257 |
('short-line-size', |
|
258 |
{'type' : 'int', |
|
5391
fe3fe2b2b60a
[config] augment default value for short-line-size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5264
diff
changeset
|
259 |
'default': 80, |
0 | 260 |
'help': _('maximum number of characters in short description'), |
261 |
'group': 'navigation', |
|
262 |
}), |
|
263 |
) |
|
264 |
||
265 |
def register_persistent_options(options): |
|
266 |
global PERSISTENT_OPTIONS |
|
267 |
PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options) |
|
1446 | 268 |
|
0 | 269 |
CFGTYPE2ETYPE_MAP = { |
270 |
'string': 'String', |
|
271 |
'choice': 'String', |
|
272 |
'yn': 'Boolean', |
|
273 |
'int': 'Int', |
|
274 |
'float' : 'Float', |
|
275 |
} |
|
1446 | 276 |
|
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
|
277 |
_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
|
278 |
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
|
279 |
|
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
|
280 |
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
|
281 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
282 |
try: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
283 |
_INSTALL_PREFIX = os.environ['CW_INSTALL_PREFIX'] |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
284 |
except KeyError: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
285 |
_INSTALL_PREFIX = _find_prefix() |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
286 |
|
0 | 287 |
class CubicWebNoAppConfiguration(ConfigurationMixIn): |
288 |
"""base class for cubicweb configuration without a specific instance directory |
|
289 |
""" |
|
290 |
__metaclass__ = metaconfiguration |
|
291 |
# to set in concrete configuration |
|
292 |
name = None |
|
293 |
# log messages format (see logging module documentation for available keys) |
|
294 |
log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s' |
|
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
295 |
# the format below can be useful to debug multi thread issues: |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
296 |
# log_format = '%(asctime)s - [%(threadName)s] (%(name)s) %(levelname)s: %(message)s' |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
297 |
# nor remove appobjects based on unused interface [???] |
0 | 298 |
cleanup_interface_sobjects = True |
299 |
||
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
300 |
if (CWDEV and _forced_mode != 'system'): |
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
|
301 |
mode = 'user' |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
302 |
_CUBES_DIR = join(CW_SOFTWARE_ROOT, '../cubes') |
0 | 303 |
else: |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
304 |
mode = _forced_mode or 'system' |
5022
7e09702aa766
fix _cubes dir
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
305 |
_CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes') |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
306 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
307 |
CUBES_DIR = env_path('CW_CUBES_DIR', _CUBES_DIR, 'cubes', checkexists=False) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
308 |
CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep) |
0 | 309 |
|
1046
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
310 |
options = ( |
0 | 311 |
('log-threshold', |
312 |
{'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
|
313 |
'default': 'WARNING', |
0 | 314 |
'help': 'server\'s log level', |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
315 |
'group': 'main', 'level': 1, |
0 | 316 |
}), |
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
|
317 |
# 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
|
318 |
('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
|
319 |
{'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
|
320 |
'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
|
321 |
'help': 'identifier of the CubicWeb instance in the Pyro name server', |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
322 |
'group': 'pyro', 'level': 1, |
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
|
323 |
}), |
0 | 324 |
('pyro-ns-host', |
325 |
{'type' : 'string', |
|
378
c0cd7398edff
revert local debug checkin
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
369
diff
changeset
|
326 |
'default': '', |
0 | 327 |
'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
|
328 |
broadcast query. It may contains port information using <host>:<port> notation.', |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
329 |
'group': 'pyro', 'level': 1, |
0 | 330 |
}), |
331 |
('pyro-ns-group', |
|
332 |
{'type' : 'string', |
|
333 |
'default': 'cubicweb', |
|
334 |
'help': 'Pyro name server\'s group where the repository will be \ |
|
335 |
registered.', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
336 |
'group': 'pyro', 'level': 1, |
0 | 337 |
}), |
338 |
# common configuration options which are potentially required as soon as |
|
339 |
# you're using "base" application objects (ie to really server/web |
|
340 |
# specific) |
|
341 |
('base-url', |
|
342 |
{'type' : 'string', |
|
343 |
'default': None, |
|
344 |
'help': 'web server root url', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
345 |
'group': 'main', 'level': 1, |
0 | 346 |
}), |
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
|
347 |
('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
|
348 |
{'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
|
349 |
'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
|
350 |
'help': 'allow users to login with their primary email if set', |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
351 |
'group': 'main', 'level': 2, |
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
|
352 |
}), |
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
|
353 |
('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
|
354 |
{'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
|
355 |
'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
|
356 |
'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
|
357 |
'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
|
358 |
'single cubicweb instance'), |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
359 |
'group': 'main', 'level': 1, |
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
|
360 |
}), |
0 | 361 |
('mangle-emails', |
362 |
{'type' : 'yn', |
|
363 |
'default': False, |
|
364 |
'help': "don't display actual email addresses but mangle them if \ |
|
365 |
this option is set to yes", |
|
5456
d040889fac4e
merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
diff
changeset
|
366 |
'group': 'email', 'level': 3, |
0 | 367 |
}), |
368 |
) |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
369 |
# static and class methods used to get instance independant resources ## |
0 | 370 |
@staticmethod |
371 |
def cubicweb_version(): |
|
372 |
"""return installed cubicweb version""" |
|
373 |
from logilab.common.changelog import Version |
|
374 |
from cubicweb import __pkginfo__ |
|
375 |
version = __pkginfo__.numversion |
|
376 |
assert len(version) == 3, version |
|
377 |
return Version(version) |
|
1446 | 378 |
|
0 | 379 |
@staticmethod |
380 |
def persistent_options_configuration(): |
|
381 |
return Configuration(options=PERSISTENT_OPTIONS) |
|
382 |
||
383 |
@classmethod |
|
384 |
def shared_dir(cls): |
|
385 |
"""return the shared data directory (i.e. directory where standard |
|
386 |
library views and data may be found) |
|
387 |
""" |
|
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
|
388 |
if CWDEV: |
0 | 389 |
return join(CW_SOFTWARE_ROOT, 'web') |
1039 | 390 |
return cls.cube_dir('shared') |
1446 | 391 |
|
0 | 392 |
@classmethod |
393 |
def i18n_lib_dir(cls): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
394 |
"""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
|
395 |
if CWDEV: |
0 | 396 |
return join(CW_SOFTWARE_ROOT, 'i18n') |
397 |
return join(cls.shared_dir(), 'i18n') |
|
398 |
||
399 |
@classmethod |
|
400 |
def available_cubes(cls): |
|
5298
66b0987716f9
[config] fix #799884: do not attempt to load stuff with incorrect names which sit in cubes/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
401 |
import re |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
402 |
cubes = set() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
403 |
for directory in cls.cubes_search_path(): |
5086
bd13d9268b44
[cleanup] exists imported, use it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
404 |
if not 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
|
405 |
cls.error('unexistant directory in cubes search path: %s' |
5298
66b0987716f9
[config] fix #799884: do not attempt to load stuff with incorrect names which sit in cubes/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
406 |
% directory) |
4001
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
407 |
continue |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
408 |
for cube in os.listdir(directory): |
5298
66b0987716f9
[config] fix #799884: do not attempt to load stuff with incorrect names which sit in cubes/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
409 |
if cube == 'shared': |
5026
1f8238eaec9b
[config] more cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5025
diff
changeset
|
410 |
continue |
5298
66b0987716f9
[config] fix #799884: do not attempt to load stuff with incorrect names which sit in cubes/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
411 |
if not re.match('[_A-Za-z][_A-Za-z0-9]*$', cube): |
66b0987716f9
[config] fix #799884: do not attempt to load stuff with incorrect names which sit in cubes/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
412 |
continue # skip invalid python package name |
66b0987716f9
[config] fix #799884: do not attempt to load stuff with incorrect names which sit in cubes/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
413 |
cubedir = join(directory, cube) |
66b0987716f9
[config] fix #799884: do not attempt to load stuff with incorrect names which sit in cubes/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
414 |
if isdir(cubedir) and exists(join(cubedir, '__init__.py')): |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
415 |
cubes.add(cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
416 |
return sorted(cubes) |
1446 | 417 |
|
0 | 418 |
@classmethod |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
419 |
def cubes_search_path(cls): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
420 |
"""return the path of directories where cubes should be searched""" |
5049
1b5c873029a1
take care to empty string in cubes search path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5048
diff
changeset
|
421 |
path = [abspath(normpath(directory)) for directory in cls.CUBES_PATH |
1b5c873029a1
take care to empty string in cubes search path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5048
diff
changeset
|
422 |
if directory.strip() and exists(directory.strip())] |
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
|
423 |
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
|
424 |
path.append(cls.CUBES_DIR) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
425 |
return path |
1446 | 426 |
|
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
|
427 |
@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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
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
|
432 |
extrapath[cubesdir] = 'cubes' |
4325 | 433 |
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
|
434 |
|
0 | 435 |
@classmethod |
436 |
def cube_dir(cls, cube): |
|
437 |
"""return the cube directory for the given cube id, |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
438 |
raise `ConfigurationError` if it doesn't exists |
0 | 439 |
""" |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
440 |
for directory in cls.cubes_search_path(): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
441 |
cubedir = join(directory, cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
442 |
if exists(cubedir): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
443 |
return cubedir |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
444 |
raise ConfigurationError('no cube %s in %s' % (cube, cls.cubes_search_path())) |
0 | 445 |
|
446 |
@classmethod |
|
447 |
def cube_migration_scripts_dir(cls, cube): |
|
448 |
"""cube migration scripts directory""" |
|
449 |
return join(cls.cube_dir(cube), 'migration') |
|
1446 | 450 |
|
0 | 451 |
@classmethod |
452 |
def cube_pkginfo(cls, cube): |
|
453 |
"""return the information module for the given cube""" |
|
454 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
455 |
try: |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
456 |
parent = __import__('cubes.%s.__pkginfo__' % cube) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
457 |
return getattr(parent, cube).__pkginfo__ |
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
458 |
except Exception, ex: |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
459 |
raise ConfigurationError( |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
460 |
'unable to find packaging information for cube %s (%s: %s)' |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
461 |
% (cube, ex.__class__.__name__, ex)) |
0 | 462 |
|
463 |
@classmethod |
|
464 |
def cube_version(cls, cube): |
|
1446 | 465 |
"""return the version of the cube located in the given directory |
0 | 466 |
""" |
467 |
from logilab.common.changelog import Version |
|
468 |
version = cls.cube_pkginfo(cube).numversion |
|
469 |
assert len(version) == 3, version |
|
470 |
return Version(version) |
|
471 |
||
472 |
@classmethod |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
473 |
def _cube_deps(cls, cube, key, oldkey): |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
474 |
"""return cubicweb cubes used by the given cube""" |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
475 |
pkginfo = cls.cube_pkginfo(cube) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
476 |
try: |
5163
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
477 |
# explicit __xxx_cubes__ attribute |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
478 |
deps = getattr(pkginfo, key) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
479 |
except AttributeError: |
5163
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
480 |
# deduce cubes from generic __xxx__ attribute |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
481 |
try: |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
482 |
gendeps = getattr(pkginfo, key.replace('_cubes', '')) |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
483 |
except AttributeError: |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
484 |
# bw compat |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
485 |
if hasattr(pkginfo, oldkey): |
5381
1e6f23066067
[config] include cube name in warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
486 |
warn('[3.8] cube %s: %s is deprecated, use %s dict' |
1e6f23066067
[config] include cube name in warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
487 |
% (cube, oldkey, key), DeprecationWarning) |
5163
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
488 |
deps = getattr(pkginfo, oldkey) |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
489 |
else: |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
490 |
deps = {} |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
491 |
else: |
5163
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
492 |
deps = dict( (x[len('cubicweb-'):], v) |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
493 |
for x, v in gendeps.iteritems() |
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
494 |
if x.startswith('cubicweb-')) |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
495 |
if not isinstance(deps, dict): |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
496 |
deps = dict((key, None) for key in deps) |
5163
3079b8345915
[pkginfo] when only __depends__ is specified, deduced __depends_cubes__ from it (same thing for recommends) ; fix ad skel pkginfo on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5159
diff
changeset
|
497 |
warn('[3.8] cube %s should define %s as a dict' % (cube, key), |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
498 |
DeprecationWarning) |
5917
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
499 |
for depcube in deps: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
500 |
try: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
501 |
newname = CW_MIGRATION_MAP[depcube] |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
502 |
except KeyError: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
503 |
pass |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
504 |
else: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
505 |
deps[newname] = deps.pop(depcube) |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
506 |
return deps |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
507 |
|
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
508 |
@classmethod |
0 | 509 |
def cube_dependencies(cls, cube): |
510 |
"""return cubicweb cubes used by the given cube""" |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
511 |
return cls._cube_deps(cube, '__depends_cubes__', '__use__') |
0 | 512 |
|
513 |
@classmethod |
|
514 |
def cube_recommends(cls, cube): |
|
515 |
"""return cubicweb cubes recommended by the given cube""" |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
516 |
return cls._cube_deps(cube, '__recommends_cubes__', '__recommend__') |
0 | 517 |
|
518 |
@classmethod |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
519 |
def expand_cubes(cls, cubes, with_recommends=False): |
0 | 520 |
"""expand the given list of top level cubes used by adding recursivly |
521 |
each cube dependencies |
|
522 |
""" |
|
523 |
cubes = list(cubes) |
|
524 |
todo = cubes[:] |
|
5917
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
525 |
if with_recommends: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
526 |
available = set(cls.available_cubes()) |
0 | 527 |
while todo: |
528 |
cube = todo.pop(0) |
|
529 |
for depcube in cls.cube_dependencies(cube): |
|
530 |
if depcube not in cubes: |
|
531 |
cubes.append(depcube) |
|
532 |
todo.append(depcube) |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
533 |
if with_recommends: |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
534 |
for depcube in cls.cube_recommends(cube): |
5917
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
535 |
if depcube not in cubes and depcube in available: |
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
536 |
cubes.append(depcube) |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
537 |
todo.append(depcube) |
0 | 538 |
return cubes |
539 |
||
540 |
@classmethod |
|
541 |
def reorder_cubes(cls, cubes): |
|
542 |
"""reorder cubes from the top level cubes to inner dependencies |
|
543 |
cubes |
|
544 |
""" |
|
5322
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
545 |
from logilab.common.graph import ordered_nodes, UnorderableGraph |
0 | 546 |
graph = {} |
547 |
for cube in cubes: |
|
548 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
549 |
graph[cube] = set(dep for dep in cls.cube_dependencies(cube) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
550 |
if dep in cubes) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
551 |
graph[cube] |= set(dep for dep in cls.cube_recommends(cube) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
552 |
if dep in cubes) |
5322
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
553 |
try: |
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
554 |
return ordered_nodes(graph) |
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
555 |
except UnorderableGraph, ex: |
0 | 556 |
raise ConfigurationError('cycles in cubes dependencies: %s' |
5322
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
557 |
% ex.cycles) |
1446 | 558 |
|
0 | 559 |
@classmethod |
560 |
def cls_adjust_sys_path(cls): |
|
561 |
"""update python path if necessary""" |
|
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
562 |
cubes_parent_dir = normpath(join(cls.CUBES_DIR, '..')) |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
563 |
if not cubes_parent_dir in sys.path: |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
564 |
sys.path.insert(0, cubes_parent_dir) |
0 | 565 |
try: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
566 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
567 |
cubes.__path__ = cls.cubes_search_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
568 |
except ImportError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
569 |
return # cubes dir doesn't exists |
0 | 570 |
|
571 |
@classmethod |
|
572 |
def load_cwctl_plugins(cls): |
|
573 |
from logilab.common.modutils import load_module_from_file |
|
574 |
cls.cls_adjust_sys_path() |
|
575 |
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
|
576 |
'server/serverctl.py', |
0 | 577 |
'devtools/devctl.py', 'goa/goactl.py'): |
578 |
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
|
579 |
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
|
580 |
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
|
581 |
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
|
582 |
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
|
583 |
(ctlfile, err)) |
0 | 584 |
cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
585 |
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
|
586 |
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
|
587 |
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
|
588 |
initfile = join(cls.cube_dir(cube), '__init__.py') |
0 | 589 |
if exists(pluginfile): |
590 |
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
|
591 |
__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
|
592 |
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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
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
|
597 |
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
|
598 |
try: |
0 | 599 |
__import__('cubes.%s.ecplugin' % cube) |
600 |
cls.info('loaded cubicweb-ctl plugin from %s', cube) |
|
601 |
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
|
602 |
cls.exception('while loading plugin %s', oldpluginfile) |
0 | 603 |
elif exists(initfile): |
604 |
try: |
|
605 |
__import__('cubes.%s' % cube) |
|
606 |
except: |
|
607 |
cls.exception('while loading cube %s', cube) |
|
608 |
else: |
|
1446 | 609 |
cls.warning('no __init__ file in cube %s', cube) |
0 | 610 |
|
611 |
@classmethod |
|
612 |
def init_available_cubes(cls): |
|
613 |
"""cubes may register some sources (svnfile for instance) in their |
|
614 |
__init__ file, so they should be loaded early in the startup process |
|
615 |
""" |
|
616 |
for cube in cls.available_cubes(): |
|
617 |
try: |
|
618 |
__import__('cubes.%s' % cube) |
|
619 |
except Exception, ex: |
|
620 |
cls.warning("can't init cube %s: %s", cube, ex) |
|
1446 | 621 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
622 |
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
|
623 |
cube_appobject_path = set(['entities']) |
0 | 624 |
|
625 |
@classmethod |
|
626 |
def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None): |
|
627 |
"""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
|
628 |
directories that should be loaded by the instance objects registry. |
0 | 629 |
|
630 |
:param evobjpath: |
|
631 |
optional list of sub-directories (or files without the .py ext) of |
|
632 |
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
|
633 |
if they exists. If not give, default to `cubicweb_appobject_path` class |
0 | 634 |
attribute. |
635 |
:param tvobjpath: |
|
636 |
optional list of sub-directories (or files without the .py ext) of |
|
637 |
directories given in `templpath` that should be tested and added to |
|
638 |
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
|
639 |
`cube_appobject_path` class attribute. |
0 | 640 |
""" |
641 |
vregpath = cls.build_vregistry_cubicweb_path(evobjpath) |
|
642 |
vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath) |
|
643 |
return vregpath |
|
644 |
||
645 |
@classmethod |
|
646 |
def build_vregistry_cubicweb_path(cls, evobjpath=None): |
|
647 |
vregpath = [] |
|
648 |
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
|
649 |
evobjpath = cls.cubicweb_appobject_path |
0 | 650 |
for subdir in evobjpath: |
651 |
path = join(CW_SOFTWARE_ROOT, subdir) |
|
652 |
if exists(path): |
|
653 |
vregpath.append(path) |
|
654 |
return vregpath |
|
655 |
||
656 |
@classmethod |
|
657 |
def build_vregistry_cube_path(cls, templpath, tvobjpath=None): |
|
658 |
vregpath = [] |
|
659 |
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
|
660 |
tvobjpath = cls.cube_appobject_path |
0 | 661 |
for directory in templpath: |
662 |
for subdir in tvobjpath: |
|
663 |
path = join(directory, subdir) |
|
664 |
if exists(path): |
|
665 |
vregpath.append(path) |
|
666 |
elif exists(path + '.py'): |
|
667 |
vregpath.append(path + '.py') |
|
668 |
return vregpath |
|
1446 | 669 |
|
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
670 |
def __init__(self, debugmode=False): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
671 |
register_stored_procedures() |
0 | 672 |
ConfigurationMixIn.__init__(self) |
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
673 |
self.debugmode = debugmode |
0 | 674 |
self.adjust_sys_path() |
675 |
self.load_defaults() |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
676 |
# will be properly initialized later by _gettext_init |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
677 |
self.translations = {'en': (unicode, lambda ctx, msgid: unicode(msgid) )} |
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
678 |
self._site_loaded = set() |
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
|
679 |
# 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
|
680 |
# 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
|
681 |
# 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
|
682 |
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
|
683 |
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
|
684 |
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
|
685 |
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
|
686 |
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
|
687 |
cw_rest_init() |
0 | 688 |
|
689 |
def adjust_sys_path(self): |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
690 |
# overriden in CubicWebConfiguration |
0 | 691 |
self.cls_adjust_sys_path() |
1446 | 692 |
|
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
693 |
def init_log(self, logthreshold=None, logfile=None, syslog=False): |
0 | 694 |
"""init the log service""" |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
695 |
if logthreshold is None: |
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
696 |
if self.debugmode: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
697 |
logthreshold = 'DEBUG' |
0 | 698 |
else: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
699 |
logthreshold = self['log-threshold'] |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
700 |
if sys.platform == 'win32': |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
701 |
# no logrotate on win32, so use logging rotation facilities |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
702 |
# for now, hard code weekly rotation every sunday, and 52 weeks kept |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
703 |
# idea: make this configurable? |
5655 | 704 |
init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format, |
5646
c9550c1239f0
various brown paper bag fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5640
diff
changeset
|
705 |
rotation_parameters={'when': 'W6', # every sunday |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
706 |
'interval': 1, |
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
707 |
'backupCount': 52}) |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
708 |
else: |
5655 | 709 |
init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format) |
0 | 710 |
# configure simpleTal logger |
711 |
logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
|
712 |
||
713 |
def vregistry_path(self): |
|
714 |
"""return a list of files or directories where the registry will look |
|
715 |
for application objects. By default return nothing in NoApp config. |
|
716 |
""" |
|
717 |
return [] |
|
1446 | 718 |
|
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
719 |
apphome = None |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
720 |
|
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
721 |
def load_site_cubicweb(self, paths=None): |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
722 |
"""load instance's specific site_cubicweb file""" |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
723 |
if paths is None: |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
724 |
paths = self.cubes_path() |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
725 |
if self.apphome is not None: |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
726 |
paths = [self.apphome] + paths |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
727 |
for path in reversed(paths): |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
728 |
sitefile = join(path, 'site_cubicweb.py') |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
729 |
if exists(sitefile) and not sitefile in self._site_loaded: |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
730 |
self._load_site_cubicweb(sitefile) |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
731 |
self._site_loaded.add(sitefile) |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
732 |
else: |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
733 |
sitefile = join(path, 'site_erudi.py') |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
734 |
if exists(sitefile) and not sitefile in self._site_loaded: |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
735 |
self._load_site_cubicweb(sitefile) |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
736 |
self._site_loaded.add(sitefile) |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
737 |
self.warning('[3.5] site_erudi.py is deprecated, should be ' |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
738 |
'renamed to site_cubicweb.py') |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
739 |
|
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
740 |
def _load_site_cubicweb(self, sitefile): |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
741 |
# XXX extrapath argument to load_module_from_file only in lgc > 0.50.2 |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
742 |
from logilab.common.modutils import load_module_from_modpath, modpath_from_file |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
743 |
module = load_module_from_modpath(modpath_from_file(sitefile, self.extrapath)) |
6087
bdfbd6aa5758
[debug] change severity of 'site_cubicweb loaded' message to debug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5960
diff
changeset
|
744 |
self.debug('%s loaded', sitefile) |
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
745 |
return module |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
746 |
|
0 | 747 |
def eproperty_definitions(self): |
748 |
cfg = self.persistent_options_configuration() |
|
749 |
for section, options in cfg.options_by_section(): |
|
750 |
section = section.lower() |
|
751 |
for optname, optdict, value in options: |
|
752 |
key = '%s.%s' % (section, optname) |
|
753 |
type, vocab = self.map_option(optdict) |
|
754 |
default = cfg.option_default(optname, optdict) |
|
755 |
pdef = {'type': type, 'vocabulary': vocab, 'default': default, |
|
756 |
'help': optdict['help'], |
|
757 |
'sitewide': optdict.get('sitewide', False)} |
|
758 |
yield key, pdef |
|
1446 | 759 |
|
0 | 760 |
def map_option(self, optdict): |
761 |
try: |
|
762 |
vocab = optdict['choices'] |
|
763 |
except KeyError: |
|
764 |
vocab = optdict.get('vocabulary') |
|
765 |
if isinstance(vocab, Method): |
|
766 |
vocab = getattr(self, vocab.method, ()) |
|
767 |
return CFGTYPE2ETYPE_MAP[optdict['type']], vocab |
|
768 |
||
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
|
769 |
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
|
770 |
"""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
|
771 |
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
|
772 |
""" |
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
|
773 |
return None |
1446 | 774 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
775 |
|
0 | 776 |
class CubicWebConfiguration(CubicWebNoAppConfiguration): |
777 |
"""base class for cubicweb server and web configurations""" |
|
1446 | 778 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
779 |
if CubicWebNoAppConfiguration.mode == 'user': |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
780 |
_INSTANCES_DIR = expanduser('~/etc/cubicweb.d/') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
781 |
else: #mode = 'system' |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
782 |
if _INSTALL_PREFIX == '/usr': |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
783 |
_INSTANCES_DIR = '/etc/cubicweb.d/' |
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
|
784 |
else: |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
785 |
_INSTANCES_DIR = join(_INSTALL_PREFIX, 'etc', 'cubicweb.d') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
786 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
787 |
if os.environ.get('APYCOT_ROOT'): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
788 |
_cubes_init = join(CubicWebNoAppConfiguration.CUBES_DIR, '__init__.py') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
789 |
if not exists(_cubes_init): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
790 |
file(join(_cubes_init), 'w').close() |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
791 |
if not exists(_INSTANCES_DIR): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
792 |
os.makedirs(_INSTANCES_DIR) |
0 | 793 |
|
794 |
# for some commands (creation...) we don't want to initialize gettext |
|
795 |
set_language = True |
|
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2449
diff
changeset
|
796 |
# 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
|
797 |
repairing = False |
1446 | 798 |
|
0 | 799 |
options = CubicWebNoAppConfiguration.options + ( |
800 |
('log-file', |
|
801 |
{'type' : 'string', |
|
802 |
'default': Method('default_log_file'), |
|
803 |
'help': 'file where output logs should be written', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
804 |
'group': 'main', 'level': 2, |
0 | 805 |
}), |
806 |
# email configuration |
|
807 |
('smtp-host', |
|
808 |
{'type' : 'string', |
|
809 |
'default': 'mail', |
|
810 |
'help': 'hostname of the SMTP mail server', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
811 |
'group': 'email', 'level': 1, |
0 | 812 |
}), |
813 |
('smtp-port', |
|
814 |
{'type' : 'int', |
|
815 |
'default': 25, |
|
816 |
'help': 'listening port of the SMTP mail server', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
817 |
'group': 'email', 'level': 1, |
0 | 818 |
}), |
819 |
('sender-name', |
|
820 |
{'type' : 'string', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
821 |
'default': Method('default_instance_id'), |
0 | 822 |
'help': 'name used as HELO name for outgoing emails from the \ |
823 |
repository.', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
824 |
'group': 'email', 'level': 2, |
0 | 825 |
}), |
826 |
('sender-addr', |
|
827 |
{'type' : 'string', |
|
2351
dddee537e4d5
don't use internal address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
828 |
'default': 'cubicweb@mydomain.com', |
0 | 829 |
'help': 'email address used as HELO address for outgoing emails from \ |
830 |
the repository', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
831 |
'group': 'email', 'level': 1, |
0 | 832 |
}), |
833 |
) |
|
834 |
||
835 |
@classmethod |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
836 |
def instances_dir(cls): |
0 | 837 |
"""return the control directory""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
838 |
return env_path('CW_INSTANCES_DIR', cls._INSTANCES_DIR, 'registry') |
1446 | 839 |
|
0 | 840 |
@classmethod |
841 |
def migration_scripts_dir(cls): |
|
842 |
"""cubicweb migration scripts directory""" |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
843 |
if CWDEV: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
844 |
return join(CW_SOFTWARE_ROOT, 'misc', 'migration') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
845 |
mdir = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'migration') |
5028 | 846 |
if not exists(mdir): |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
847 |
raise ConfigurationError('migration path %s doesn\'t exist' % mdir) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
848 |
return mdir |
0 | 849 |
|
850 |
@classmethod |
|
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
851 |
def config_for(cls, appid, config=None, debugmode=False): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
852 |
"""return a configuration instance for the given instance identifier |
0 | 853 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
854 |
config = config or guess_configuration(cls.instance_home(appid)) |
0 | 855 |
configcls = configuration_cls(config) |
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
856 |
return configcls(appid, debugmode) |
1446 | 857 |
|
0 | 858 |
@classmethod |
859 |
def possible_configurations(cls, appid): |
|
860 |
"""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
|
861 |
instance id |
0 | 862 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
863 |
home = cls.instance_home(appid) |
0 | 864 |
return possible_configurations(home) |
1446 | 865 |
|
0 | 866 |
@classmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
867 |
def instance_home(cls, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
868 |
"""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
|
869 |
instance id |
0 | 870 |
""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
871 |
home = join(cls.instances_dir(), appid) |
0 | 872 |
if not exists(home): |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
873 |
raise ConfigurationError('no such instance %s (check it exists with' |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
874 |
' "cubicweb-ctl list")' % appid) |
0 | 875 |
return home |
876 |
||
877 |
MODES = ('common', 'repository', 'Any', 'web') |
|
878 |
MCOMPAT = {'all-in-one': MODES, |
|
879 |
'repository': ('common', 'repository', 'Any'), |
|
880 |
'twisted' : ('common', 'web'),} |
|
881 |
@classmethod |
|
882 |
def accept_mode(cls, mode): |
|
883 |
#assert mode in cls.MODES, mode |
|
884 |
return mode in cls.MCOMPAT[cls.name] |
|
1446 | 885 |
|
0 | 886 |
# default configuration methods ########################################### |
1446 | 887 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
888 |
def default_instance_id(self): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
889 |
"""return the instance identifier, useful for option which need this |
0 | 890 |
as default value |
891 |
""" |
|
892 |
return self.appid |
|
893 |
||
894 |
def default_log_file(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
895 |
"""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
|
896 |
if self.mode == 'user': |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
897 |
import tempfile |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
898 |
basepath = join(tempfile.gettempdir(), '%s-%s' % ( |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
899 |
basename(self.appid), self.name)) |
0 | 900 |
path = basepath + '.log' |
901 |
i = 1 |
|
902 |
while exists(path) and i < 100: # arbitrary limit to avoid infinite loop |
|
903 |
try: |
|
904 |
file(path, 'a') |
|
905 |
break |
|
906 |
except IOError: |
|
907 |
path = '%s-%s.log' % (basepath, i) |
|
908 |
i += 1 |
|
909 |
return path |
|
910 |
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
|
1446 | 911 |
|
0 | 912 |
def default_pid_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
913 |
"""return default path to the pid file of the instance'server""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
914 |
if self.mode == 'system': |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
915 |
# XXX not under _INSTALL_PREFIX, right? |
5960
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
916 |
default = '/var/run/cubicweb/' |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
917 |
else: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
918 |
import tempfile |
5960
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
919 |
default = tempfile.gettempdir() |
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
920 |
# runtime directory created on startup if necessary, don't check it |
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
921 |
# exists |
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
922 |
rtdir = env_path('CW_RUNTIME_DIR', default, 'run time', |
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
923 |
checkexists=False) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
924 |
return join(rtdir, '%s-%s.pid' % (self.appid, self.name)) |
1446 | 925 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
926 |
# instance methods used to get instance specific resources ############# |
1446 | 927 |
|
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
928 |
def __init__(self, appid, debugmode=False): |
0 | 929 |
self.appid = appid |
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
930 |
CubicWebNoAppConfiguration.__init__(self, debugmode) |
0 | 931 |
self._cubes = None |
932 |
self.load_file_configuration(self.main_config_file()) |
|
933 |
||
934 |
def adjust_sys_path(self): |
|
935 |
CubicWebNoAppConfiguration.adjust_sys_path(self) |
|
936 |
# adding apphome to python path is not usually necessary in production |
|
937 |
# environments, but necessary for tests |
|
938 |
if self.apphome and not self.apphome in sys.path: |
|
939 |
sys.path.insert(0, self.apphome) |
|
940 |
||
941 |
@property |
|
942 |
def apphome(self): |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
943 |
return join(self.instances_dir(), self.appid) |
1446 | 944 |
|
0 | 945 |
@property |
946 |
def appdatahome(self): |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
947 |
if self.mode == 'system': |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
948 |
# XXX not under _INSTALL_PREFIX, right? |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
949 |
iddir = '/var/lib/cubicweb/instances/' |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
950 |
else: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
951 |
iddir = self.instances_dir() |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
952 |
iddir = env_path('CW_INSTANCES_DATA_DIR', iddir, 'additional data') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
953 |
return join(iddir, self.appid) |
1446 | 954 |
|
0 | 955 |
def init_cubes(self, cubes): |
1681
1586c0ed9a92
nicer assertion message
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1521
diff
changeset
|
956 |
assert self._cubes is None, self._cubes |
0 | 957 |
self._cubes = self.reorder_cubes(cubes) |
958 |
# load cubes'__init__.py file first |
|
959 |
for cube in cubes: |
|
960 |
__import__('cubes.%s' % cube) |
|
961 |
self.load_site_cubicweb() |
|
962 |
# reload config file in cases options are defined in cubes __init__ |
|
963 |
# or site_cubicweb files |
|
964 |
self.load_file_configuration(self.main_config_file()) |
|
965 |
# configuration initialization hook |
|
966 |
self.load_configuration() |
|
1446 | 967 |
|
0 | 968 |
def cubes(self): |
969 |
"""return the list of cubes used by this instance |
|
970 |
||
971 |
result is ordered from the top level cubes to inner dependencies |
|
972 |
cubes |
|
973 |
""" |
|
974 |
assert self._cubes is not None |
|
975 |
return self._cubes |
|
1446 | 976 |
|
0 | 977 |
def cubes_path(self): |
978 |
"""return the list of path to cubes used by this instance, from outer |
|
979 |
most to inner most cubes |
|
980 |
""" |
|
981 |
return [self.cube_dir(p) for p in self.cubes()] |
|
982 |
||
983 |
def add_cubes(self, cubes): |
|
984 |
"""add given cubes to the list of used cubes""" |
|
985 |
if not isinstance(cubes, list): |
|
986 |
cubes = list(cubes) |
|
987 |
self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
|
1446 | 988 |
|
0 | 989 |
def main_config_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
990 |
"""return instance's control configuration file""" |
0 | 991 |
return join(self.apphome, '%s.conf' % self.name) |
1446 | 992 |
|
0 | 993 |
def save(self): |
994 |
"""write down current configuration""" |
|
995 |
self.generate_config(open(self.main_config_file(), 'w')) |
|
996 |
||
5933
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
997 |
def check_writeable_uid_directory(self, path): |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
998 |
"""check given directory path exists, belongs to the user running the |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
999 |
server process and is writeable. |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1000 |
|
6135
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1001 |
If not, try to fix this, letting exception propagate when not possible. |
5933
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1002 |
""" |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1003 |
if not exists(path): |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1004 |
os.makedirs(path) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1005 |
if self['uid']: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1006 |
try: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1007 |
uid = int(self['uid']) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1008 |
except ValueError: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1009 |
from pwd import getpwnam |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1010 |
uid = getpwnam(self['uid']).pw_uid |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1011 |
else: |
6135
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1012 |
try: |
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1013 |
uid = os.getuid() |
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1014 |
except AttributeError: # we are on windows |
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1015 |
return |
5933
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1016 |
fstat = os.stat(path) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1017 |
if fstat.st_uid != uid: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1018 |
os.chown(path, uid, os.getgid()) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1019 |
import stat |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1020 |
if not (fstat.st_mode & stat.S_IWUSR): |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1021 |
os.chmod(path, fstat.st_mode | stat.S_IWUSR) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1022 |
|
0 | 1023 |
@cached |
1024 |
def instance_md5_version(self): |
|
5885
5d908f1a7659
[config] use hashlib to avoid warning w/ py2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5817
diff
changeset
|
1025 |
import hashlib |
0 | 1026 |
infos = [] |
1027 |
for pkg in self.cubes(): |
|
1028 |
version = self.cube_version(pkg) |
|
1029 |
infos.append('%s-%s' % (pkg, version)) |
|
5885
5d908f1a7659
[config] use hashlib to avoid warning w/ py2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5817
diff
changeset
|
1030 |
return hashlib.md5(';'.join(infos)).hexdigest() |
1446 | 1031 |
|
0 | 1032 |
def load_configuration(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1033 |
"""load instance's configuration files""" |
0 | 1034 |
super(CubicWebConfiguration, self).load_configuration() |
1035 |
if self.apphome and self.set_language: |
|
1036 |
# init gettext |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
1037 |
self._gettext_init() |
1446 | 1038 |
|
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1039 |
def _load_site_cubicweb(self, sitefile): |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1040 |
# overriden to register cube specific options |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1041 |
mod = super(CubicWebConfiguration, self)._load_site_cubicweb(sitefile) |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1042 |
if getattr(mod, 'options', None): |
5817
e4207221f3f5
[config] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5812
diff
changeset
|
1043 |
self.register_options(mod.options) |
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1044 |
self.load_defaults() |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1045 |
|
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1046 |
def init_log(self, logthreshold=None, force=False): |
0 | 1047 |
"""init the log service""" |
1048 |
if not force and hasattr(self, '_logging_initialized'): |
|
1049 |
return |
|
1050 |
self._logging_initialized = True |
|
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
1051 |
CubicWebNoAppConfiguration.init_log(self, logthreshold, |
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
|
1052 |
logfile=self.get('log-file')) |
0 | 1053 |
# read a config file if it exists |
1054 |
logconfig = join(self.apphome, 'logging.conf') |
|
1055 |
if exists(logconfig): |
|
1056 |
logging.fileConfig(logconfig) |
|
1057 |
||
1058 |
def available_languages(self, *args): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1059 |
"""return available translation for an instance, by looking for |
0 | 1060 |
compiled catalog |
1061 |
||
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4889
diff
changeset
|
1062 |
take \*args to be usable as a vocabulary method |
0 | 1063 |
""" |
1064 |
from glob import glob |
|
1065 |
yield 'en' # ensure 'en' is yielded even if no .mo found |
|
1066 |
for path in glob(join(self.apphome, 'i18n', |
|
3118 | 1067 |
'*', 'LC_MESSAGES')): |
1068 |
lang = path.split(os.sep)[-2] |
|
0 | 1069 |
if lang != 'en': |
1070 |
yield lang |
|
1446 | 1071 |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
1072 |
def _gettext_init(self): |
0 | 1073 |
"""set language for gettext""" |
1074 |
from gettext import translation |
|
1075 |
path = join(self.apphome, 'i18n') |
|
1076 |
for language in self.available_languages(): |
|
1077 |
self.info("loading language %s", language) |
|
1078 |
try: |
|
1079 |
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
|
1080 |
self.translations[language] = (tr.ugettext, tr.upgettext) |
0 | 1081 |
except (ImportError, AttributeError, IOError): |
1082 |
self.exception('localisation support error for language %s', |
|
1446 | 1083 |
language) |
1084 |
||
0 | 1085 |
def vregistry_path(self): |
1086 |
"""return a list of files or directories where the registry will look |
|
1087 |
for application objects |
|
1088 |
""" |
|
1089 |
templpath = list(reversed(self.cubes_path())) |
|
1090 |
if self.apphome: # may be unset in tests |
|
1091 |
templpath.append(self.apphome) |
|
1092 |
return self.build_vregistry_path(templpath) |
|
1093 |
||
1094 |
def set_sources_mode(self, sources): |
|
1095 |
if not 'all' in sources: |
|
1096 |
print 'warning: ignoring specified sources, requires a repository '\ |
|
1097 |
'configuration' |
|
1446 | 1098 |
|
0 | 1099 |
def migration_handler(self): |
1100 |
"""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
|
1101 |
from cubicweb.migration import MigrationHelper |
0 | 1102 |
return MigrationHelper(self, verbosity=self.verbosity) |
1103 |
||
1104 |
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
|
1105 |
from cubicweb import i18n |
0 | 1106 |
if langs is None: |
1107 |
langs = self.available_languages() |
|
1108 |
i18ndir = join(self.apphome, 'i18n') |
|
1109 |
if not exists(i18ndir): |
|
1110 |
create_dir(i18ndir) |
|
1111 |
sourcedirs = [join(path, 'i18n') for path in self.cubes_path()] |
|
1112 |
sourcedirs.append(self.i18n_lib_dir()) |
|
1113 |
return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs) |
|
1114 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1115 |
def sendmails(self, msgs): |
5198
cf8292f80384
[controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
1116 |
"""msgs: list of 2-uple (message object, recipients). Return False |
cf8292f80384
[controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
1117 |
if connection to the smtp server failed, else True. |
cf8292f80384
[controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
1118 |
""" |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1119 |
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
|
1120 |
SMTP_LOCK.acquire() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1121 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1122 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1123 |
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
|
1124 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1125 |
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
|
1126 |
server, port, ex) |
5198
cf8292f80384
[controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
1127 |
return False |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1128 |
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
|
1129 |
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
|
1130 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1131 |
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
|
1132 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1133 |
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
|
1134 |
recipients, ex) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1135 |
smtp.close() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1136 |
finally: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1137 |
SMTP_LOCK.release() |
5198
cf8292f80384
[controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
1138 |
return True |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1139 |
|
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1140 |
set_log_methods(CubicWebNoAppConfiguration, |
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
1141 |
logging.getLogger('cubicweb.configuration')) |
1446 | 1142 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1143 |
# 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
|
1144 |
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
|
1145 |
application_configuration = deprecated('use instance_configuration')(instance_configuration) |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1146 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1147 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1148 |
_EXT_REGISTERED = False |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1149 |
def register_stored_procedures(): |
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
1150 |
from logilab.database import FunctionDescr |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1151 |
from rql.utils import register_function, iter_funcnode_variables |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1152 |
from rql.nodes import SortTerm, Constant, VariableRef |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1153 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1154 |
global _EXT_REGISTERED |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1155 |
if _EXT_REGISTERED: |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1156 |
return |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1157 |
_EXT_REGISTERED = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1158 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1159 |
class COMMA_JOIN(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1160 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1161 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1162 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
1163 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1164 |
return ', '.join(sorted(term.get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1165 |
for term in iter_funcnode_variables(funcnode))) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1166 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1167 |
register_function(COMMA_JOIN) # XXX do not expose? |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1168 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1169 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1170 |
class CONCAT_STRINGS(COMMA_JOIN): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1171 |
aggregat = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1172 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1173 |
register_function(CONCAT_STRINGS) # XXX bw compat |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1174 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
1175 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1176 |
class GROUP_CONCAT(CONCAT_STRINGS): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1177 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1178 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1179 |
register_function(GROUP_CONCAT) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1180 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1181 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1182 |
class LIMIT_SIZE(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1183 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1184 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1185 |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4624
diff
changeset
|
1186 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1187 |
return funcnode.children[0].get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1188 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1189 |
register_function(LIMIT_SIZE) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1190 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1191 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1192 |
class TEXT_LIMIT_SIZE(LIMIT_SIZE): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1193 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1194 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1195 |
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
|
1196 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1197 |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1198 |
class FTIRANK(FunctionDescr): |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1199 |
"""return ranking of a variable that must be used as some has_text |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1200 |
relation subject in the query's restriction. Usually used to sort result |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1201 |
of full-text search by ranking. |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1202 |
""" |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1203 |
supported_backends = ('postgres',) |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1204 |
rtype = 'Float' |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1205 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1206 |
def st_check_backend(self, backend, funcnode): |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1207 |
"""overriden so that on backend not supporting fti ranking, the |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1208 |
function is removed when in an orderby clause, or replaced by a 1.0 |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1209 |
constant. |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1210 |
""" |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1211 |
if not self.supports(backend): |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1212 |
parent = funcnode.parent |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1213 |
while parent is not None and not isinstance(parent, SortTerm): |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1214 |
parent = parent.parent |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1215 |
if isinstance(parent, SortTerm): |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1216 |
parent.parent.remove(parent) |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1217 |
else: |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1218 |
funcnode.parent.replace(funcnode, Constant(1.0, 'Float')) |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1219 |
parent = funcnode |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1220 |
for vref in parent.iget_nodes(VariableRef): |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1221 |
vref.unregister_reference() |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1222 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1223 |
register_function(FTIRANK) |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1224 |
|
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5655
diff
changeset
|
1225 |
|
4322
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1226 |
class FSPATH(FunctionDescr): |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1227 |
"""return path of some bytes attribute stored using the Bytes |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1228 |
File-System Storage (bfss) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1229 |
""" |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1230 |
rtype = 'Bytes' # XXX return a String? potential pb with fs encoding |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1231 |
|
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1232 |
def update_cb_stack(self, stack): |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1233 |
assert len(stack) == 1 |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1234 |
stack[0] = self.source_execute |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1235 |
|
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1236 |
def as_sql(self, backend, args): |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1237 |
raise NotImplementedError('source only callback') |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1238 |
|
5630
40d7c7e180f1
[storage] source's callback has a new prototype, update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
1239 |
def source_execute(self, source, session, value): |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1240 |
fpath = source.binary_to_str(value) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1241 |
try: |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1242 |
return Binary(fpath) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1243 |
except OSError, ex: |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1244 |
self.critical("can't open %s: %s", fpath, ex) |
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4938
diff
changeset
|
1245 |
return None |
4322
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1246 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1247 |
register_function(FSPATH) |