author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Mon, 05 Jul 2010 15:58:36 +0200 | |
changeset 5882 | 4c7a0b139830 |
parent 5818 | 6d8c479fcd98 |
child 5890 | 141b935a38fc |
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 |
|
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
54 |
* 'user': :: |
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
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 |
""" |
134 |
__docformat__ = "restructuredtext en" |
|
1948 | 135 |
_ = unicode |
0 | 136 |
|
137 |
import sys |
|
138 |
import os |
|
139 |
import logging |
|
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
from logilab.common.logging_ext import set_log_methods, init_log |
0 | 148 |
from logilab.common.configuration import (Configuration, Method, |
149 |
ConfigurationMixIn, merge_options) |
|
150 |
||
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
|
151 |
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
|
152 |
ConfigurationError, Binary) |
1132 | 153 |
from cubicweb.toolsutils import env_path, create_dir |
0 | 154 |
|
155 |
CONFIGURATIONS = [] |
|
156 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
157 |
SMTP_LOCK = Lock() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
158 |
|
0 | 159 |
|
160 |
class metaconfiguration(type): |
|
161 |
"""metaclass to automaticaly register configuration""" |
|
162 |
def __new__(mcs, name, bases, classdict): |
|
163 |
cls = super(metaconfiguration, mcs).__new__(mcs, name, bases, classdict) |
|
164 |
if classdict.get('name'): |
|
165 |
CONFIGURATIONS.append(cls) |
|
166 |
return cls |
|
167 |
||
168 |
def configuration_cls(name): |
|
169 |
"""return the configuration class registered with the given name""" |
|
170 |
try: |
|
171 |
return [c for c in CONFIGURATIONS if c.name == name][0] |
|
172 |
except IndexError: |
|
173 |
raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
|
174 |
||
175 |
def possible_configurations(directory): |
|
176 |
"""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
|
177 |
according to \*-ctl files |
0 | 178 |
""" |
179 |
return [name for name in ('repository', 'twisted', 'all-in-one') |
|
180 |
if exists(join(directory, '%s.conf' % name))] |
|
181 |
||
182 |
def guess_configuration(directory): |
|
183 |
"""try to guess the configuration to use for a directory. If multiple |
|
184 |
configurations are found, ConfigurationError is raised |
|
185 |
""" |
|
186 |
modes = possible_configurations(directory) |
|
187 |
if len(modes) != 1: |
|
188 |
raise ConfigurationError('unable to guess configuration from %r %s' |
|
189 |
% (directory, modes)) |
|
190 |
return modes[0] |
|
191 |
||
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
192 |
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
|
193 |
"""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
|
194 |
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
|
195 |
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
|
196 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
197 |
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
|
198 |
""" |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
return prefix |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
208 |
return sys.prefix |
0 | 209 |
|
210 |
# persistent options definition |
|
211 |
PERSISTENT_OPTIONS = ( |
|
212 |
('encoding', |
|
213 |
{'type' : 'string', |
|
214 |
'default': 'UTF-8', |
|
215 |
'help': _('user interface encoding'), |
|
216 |
'group': 'ui', 'sitewide': True, |
|
1446 | 217 |
}), |
0 | 218 |
('language', |
219 |
{'type' : 'string', |
|
220 |
'default': 'en', |
|
221 |
'vocabulary': Method('available_languages'), |
|
222 |
'help': _('language of the user interface'), |
|
1446 | 223 |
'group': 'ui', |
0 | 224 |
}), |
225 |
('date-format', |
|
226 |
{'type' : 'string', |
|
227 |
'default': '%Y/%m/%d', |
|
228 |
'help': _('how to format date in the ui ("man strftime" for format description)'), |
|
1446 | 229 |
'group': 'ui', |
0 | 230 |
}), |
231 |
('datetime-format', |
|
232 |
{'type' : 'string', |
|
233 |
'default': '%Y/%m/%d %H:%M', |
|
234 |
'help': _('how to format date and time in the ui ("man strftime" for format description)'), |
|
1446 | 235 |
'group': 'ui', |
0 | 236 |
}), |
237 |
('time-format', |
|
238 |
{'type' : 'string', |
|
239 |
'default': '%H:%M', |
|
240 |
'help': _('how to format time in the ui ("man strftime" for format description)'), |
|
1446 | 241 |
'group': 'ui', |
0 | 242 |
}), |
243 |
('float-format', |
|
244 |
{'type' : 'string', |
|
245 |
'default': '%.3f', |
|
246 |
'help': _('how to format float numbers in the ui'), |
|
1446 | 247 |
'group': 'ui', |
0 | 248 |
}), |
249 |
('default-text-format', |
|
250 |
{'type' : 'choice', |
|
251 |
'choices': ('text/plain', 'text/rest', 'text/html'), |
|
252 |
'default': 'text/html', # use fckeditor in the web ui |
|
253 |
'help': _('default text format for rich text fields.'), |
|
1446 | 254 |
'group': 'ui', |
0 | 255 |
}), |
256 |
('short-line-size', |
|
257 |
{'type' : 'int', |
|
5391
fe3fe2b2b60a
[config] augment default value for short-line-size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5264
diff
changeset
|
258 |
'default': 80, |
0 | 259 |
'help': _('maximum number of characters in short description'), |
260 |
'group': 'navigation', |
|
261 |
}), |
|
262 |
) |
|
263 |
||
264 |
def register_persistent_options(options): |
|
265 |
global PERSISTENT_OPTIONS |
|
266 |
PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options) |
|
1446 | 267 |
|
0 | 268 |
CFGTYPE2ETYPE_MAP = { |
269 |
'string': 'String', |
|
270 |
'choice': 'String', |
|
271 |
'yn': 'Boolean', |
|
272 |
'int': 'Int', |
|
273 |
'float' : 'Float', |
|
274 |
} |
|
1446 | 275 |
|
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
|
276 |
_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
|
277 |
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
|
278 |
|
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
|
279 |
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
|
280 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
281 |
try: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
282 |
_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
|
283 |
except KeyError: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
284 |
_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
|
285 |
|
0 | 286 |
class CubicWebNoAppConfiguration(ConfigurationMixIn): |
287 |
"""base class for cubicweb configuration without a specific instance directory |
|
288 |
""" |
|
289 |
__metaclass__ = metaconfiguration |
|
290 |
# to set in concrete configuration |
|
291 |
name = None |
|
292 |
# log messages format (see logging module documentation for available keys) |
|
293 |
log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s' |
|
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
294 |
# the format below can be useful to debug multi thread issues: |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
295 |
# 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
|
296 |
# nor remove appobjects based on unused interface [???] |
0 | 297 |
cleanup_interface_sobjects = True |
298 |
||
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
299 |
|
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) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
499 |
return deps |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
500 |
|
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
501 |
@classmethod |
0 | 502 |
def cube_dependencies(cls, cube): |
503 |
"""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
|
504 |
return cls._cube_deps(cube, '__depends_cubes__', '__use__') |
0 | 505 |
|
506 |
@classmethod |
|
507 |
def cube_recommends(cls, cube): |
|
508 |
"""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
|
509 |
return cls._cube_deps(cube, '__recommends_cubes__', '__recommend__') |
0 | 510 |
|
511 |
@classmethod |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
512 |
def expand_cubes(cls, cubes, with_recommends=False): |
0 | 513 |
"""expand the given list of top level cubes used by adding recursivly |
514 |
each cube dependencies |
|
515 |
""" |
|
516 |
cubes = list(cubes) |
|
517 |
todo = cubes[:] |
|
518 |
while todo: |
|
519 |
cube = todo.pop(0) |
|
520 |
for depcube in cls.cube_dependencies(cube): |
|
521 |
if depcube not in cubes: |
|
522 |
depcube = CW_MIGRATION_MAP.get(depcube, depcube) |
|
523 |
cubes.append(depcube) |
|
524 |
todo.append(depcube) |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
525 |
if with_recommends: |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
526 |
for depcube in cls.cube_recommends(cube): |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
527 |
if depcube not in cubes: |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
528 |
depcube = CW_MIGRATION_MAP.get(depcube, depcube) |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
529 |
cubes.append(depcube) |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
530 |
todo.append(depcube) |
0 | 531 |
return cubes |
532 |
||
533 |
@classmethod |
|
534 |
def reorder_cubes(cls, cubes): |
|
535 |
"""reorder cubes from the top level cubes to inner dependencies |
|
536 |
cubes |
|
537 |
""" |
|
5322
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
538 |
from logilab.common.graph import ordered_nodes, UnorderableGraph |
0 | 539 |
graph = {} |
540 |
for cube in cubes: |
|
541 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
542 |
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
|
543 |
if dep in cubes) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
544 |
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
|
545 |
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
|
546 |
try: |
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
547 |
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
|
548 |
except UnorderableGraph, ex: |
0 | 549 |
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
|
550 |
% ex.cycles) |
1446 | 551 |
|
0 | 552 |
@classmethod |
553 |
def cls_adjust_sys_path(cls): |
|
554 |
"""update python path if necessary""" |
|
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
555 |
cubes_parent_dir = normpath(join(cls.CUBES_DIR, '..')) |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
556 |
if not cubes_parent_dir in sys.path: |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
557 |
sys.path.insert(0, cubes_parent_dir) |
0 | 558 |
try: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
559 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
560 |
cubes.__path__ = cls.cubes_search_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
561 |
except ImportError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
562 |
return # cubes dir doesn't exists |
0 | 563 |
|
564 |
@classmethod |
|
565 |
def load_cwctl_plugins(cls): |
|
566 |
from logilab.common.modutils import load_module_from_file |
|
567 |
cls.cls_adjust_sys_path() |
|
568 |
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
|
569 |
'server/serverctl.py', |
0 | 570 |
'devtools/devctl.py', 'goa/goactl.py'): |
571 |
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
|
572 |
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
|
573 |
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
|
574 |
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
|
575 |
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
|
576 |
(ctlfile, err)) |
0 | 577 |
cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
578 |
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
|
579 |
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
|
580 |
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
|
581 |
initfile = join(cls.cube_dir(cube), '__init__.py') |
0 | 582 |
if exists(pluginfile): |
583 |
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
|
584 |
__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
|
585 |
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
|
586 |
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
|
587 |
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
|
588 |
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
|
589 |
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
|
590 |
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
|
591 |
try: |
0 | 592 |
__import__('cubes.%s.ecplugin' % cube) |
593 |
cls.info('loaded cubicweb-ctl plugin from %s', cube) |
|
594 |
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
|
595 |
cls.exception('while loading plugin %s', oldpluginfile) |
0 | 596 |
elif exists(initfile): |
597 |
try: |
|
598 |
__import__('cubes.%s' % cube) |
|
599 |
except: |
|
600 |
cls.exception('while loading cube %s', cube) |
|
601 |
else: |
|
1446 | 602 |
cls.warning('no __init__ file in cube %s', cube) |
0 | 603 |
|
604 |
@classmethod |
|
605 |
def init_available_cubes(cls): |
|
606 |
"""cubes may register some sources (svnfile for instance) in their |
|
607 |
__init__ file, so they should be loaded early in the startup process |
|
608 |
""" |
|
609 |
for cube in cls.available_cubes(): |
|
610 |
try: |
|
611 |
__import__('cubes.%s' % cube) |
|
612 |
except Exception, ex: |
|
613 |
cls.warning("can't init cube %s: %s", cube, ex) |
|
1446 | 614 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
615 |
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
|
616 |
cube_appobject_path = set(['entities']) |
0 | 617 |
|
618 |
@classmethod |
|
619 |
def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None): |
|
620 |
"""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
|
621 |
directories that should be loaded by the instance objects registry. |
0 | 622 |
|
623 |
:param evobjpath: |
|
624 |
optional list of sub-directories (or files without the .py ext) of |
|
625 |
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
|
626 |
if they exists. If not give, default to `cubicweb_appobject_path` class |
0 | 627 |
attribute. |
628 |
:param tvobjpath: |
|
629 |
optional list of sub-directories (or files without the .py ext) of |
|
630 |
directories given in `templpath` that should be tested and added to |
|
631 |
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
|
632 |
`cube_appobject_path` class attribute. |
0 | 633 |
""" |
634 |
vregpath = cls.build_vregistry_cubicweb_path(evobjpath) |
|
635 |
vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath) |
|
636 |
return vregpath |
|
637 |
||
638 |
@classmethod |
|
639 |
def build_vregistry_cubicweb_path(cls, evobjpath=None): |
|
640 |
vregpath = [] |
|
641 |
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
|
642 |
evobjpath = cls.cubicweb_appobject_path |
0 | 643 |
for subdir in evobjpath: |
644 |
path = join(CW_SOFTWARE_ROOT, subdir) |
|
645 |
if exists(path): |
|
646 |
vregpath.append(path) |
|
647 |
return vregpath |
|
648 |
||
649 |
@classmethod |
|
650 |
def build_vregistry_cube_path(cls, templpath, tvobjpath=None): |
|
651 |
vregpath = [] |
|
652 |
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
|
653 |
tvobjpath = cls.cube_appobject_path |
0 | 654 |
for directory in templpath: |
655 |
for subdir in tvobjpath: |
|
656 |
path = join(directory, subdir) |
|
657 |
if exists(path): |
|
658 |
vregpath.append(path) |
|
659 |
elif exists(path + '.py'): |
|
660 |
vregpath.append(path + '.py') |
|
661 |
return vregpath |
|
1446 | 662 |
|
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
|
663 |
def __init__(self, debugmode=False): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
664 |
register_stored_procedures() |
0 | 665 |
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
|
666 |
self.debugmode = debugmode |
0 | 667 |
self.adjust_sys_path() |
668 |
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
|
669 |
# 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
|
670 |
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
|
671 |
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
|
672 |
# 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
|
673 |
# 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
|
674 |
# 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
|
675 |
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
|
676 |
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
|
677 |
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
|
678 |
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
|
679 |
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
|
680 |
cw_rest_init() |
0 | 681 |
|
682 |
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
|
683 |
# overriden in CubicWebConfiguration |
0 | 684 |
self.cls_adjust_sys_path() |
1446 | 685 |
|
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
|
686 |
def init_log(self, logthreshold=None, logfile=None, syslog=False): |
0 | 687 |
"""init the log service""" |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
688 |
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
|
689 |
if self.debugmode: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
690 |
logthreshold = 'DEBUG' |
0 | 691 |
else: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
692 |
logthreshold = self['log-threshold'] |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
693 |
if sys.platform == 'win32': |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
694 |
# no logrotate on win32, so use logging rotation facilities |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
695 |
# 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
|
696 |
# idea: make this configurable? |
5655 | 697 |
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
|
698 |
rotation_parameters={'when': 'W6', # every sunday |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
699 |
'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
|
700 |
'backupCount': 52}) |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
701 |
else: |
5655 | 702 |
init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format) |
0 | 703 |
# configure simpleTal logger |
704 |
logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
|
705 |
||
706 |
def vregistry_path(self): |
|
707 |
"""return a list of files or directories where the registry will look |
|
708 |
for application objects. By default return nothing in NoApp config. |
|
709 |
""" |
|
710 |
return [] |
|
1446 | 711 |
|
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
|
712 |
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
|
713 |
|
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
|
714 |
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
|
715 |
"""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
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
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
|
722 |
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
|
723 |
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
|
724 |
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
|
725 |
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
|
726 |
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
|
727 |
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
|
728 |
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
|
729 |
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
|
730 |
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
|
731 |
'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
|
732 |
|
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 |
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
|
734 |
# 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
|
735 |
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
|
736 |
module = load_module_from_modpath(modpath_from_file(sitefile, self.extrapath)) |
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.info('%s loaded', 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
|
738 |
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
|
739 |
|
0 | 740 |
def eproperty_definitions(self): |
741 |
cfg = self.persistent_options_configuration() |
|
742 |
for section, options in cfg.options_by_section(): |
|
743 |
section = section.lower() |
|
744 |
for optname, optdict, value in options: |
|
745 |
key = '%s.%s' % (section, optname) |
|
746 |
type, vocab = self.map_option(optdict) |
|
747 |
default = cfg.option_default(optname, optdict) |
|
748 |
pdef = {'type': type, 'vocabulary': vocab, 'default': default, |
|
749 |
'help': optdict['help'], |
|
750 |
'sitewide': optdict.get('sitewide', False)} |
|
751 |
yield key, pdef |
|
1446 | 752 |
|
0 | 753 |
def map_option(self, optdict): |
754 |
try: |
|
755 |
vocab = optdict['choices'] |
|
756 |
except KeyError: |
|
757 |
vocab = optdict.get('vocabulary') |
|
758 |
if isinstance(vocab, Method): |
|
759 |
vocab = getattr(self, vocab.method, ()) |
|
760 |
return CFGTYPE2ETYPE_MAP[optdict['type']], vocab |
|
761 |
||
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
|
762 |
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
|
763 |
"""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
|
764 |
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
|
765 |
""" |
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
|
766 |
return None |
1446 | 767 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
768 |
|
0 | 769 |
class CubicWebConfiguration(CubicWebNoAppConfiguration): |
770 |
"""base class for cubicweb server and web configurations""" |
|
1446 | 771 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
772 |
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
|
773 |
_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
|
774 |
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
|
775 |
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
|
776 |
_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
|
777 |
else: |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
778 |
_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
|
779 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
780 |
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
|
781 |
_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
|
782 |
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
|
783 |
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
|
784 |
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
|
785 |
os.makedirs(_INSTANCES_DIR) |
0 | 786 |
|
787 |
# for some commands (creation...) we don't want to initialize gettext |
|
788 |
set_language = True |
|
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2449
diff
changeset
|
789 |
# 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
|
790 |
repairing = False |
1446 | 791 |
|
0 | 792 |
options = CubicWebNoAppConfiguration.options + ( |
793 |
('log-file', |
|
794 |
{'type' : 'string', |
|
795 |
'default': Method('default_log_file'), |
|
796 |
'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
|
797 |
'group': 'main', 'level': 2, |
0 | 798 |
}), |
799 |
# email configuration |
|
800 |
('smtp-host', |
|
801 |
{'type' : 'string', |
|
802 |
'default': 'mail', |
|
803 |
'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
|
804 |
'group': 'email', 'level': 1, |
0 | 805 |
}), |
806 |
('smtp-port', |
|
807 |
{'type' : 'int', |
|
808 |
'default': 25, |
|
809 |
'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
|
810 |
'group': 'email', 'level': 1, |
0 | 811 |
}), |
812 |
('sender-name', |
|
813 |
{'type' : 'string', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
814 |
'default': Method('default_instance_id'), |
0 | 815 |
'help': 'name used as HELO name for outgoing emails from the \ |
816 |
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
|
817 |
'group': 'email', 'level': 2, |
0 | 818 |
}), |
819 |
('sender-addr', |
|
820 |
{'type' : 'string', |
|
2351
dddee537e4d5
don't use internal address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
821 |
'default': 'cubicweb@mydomain.com', |
0 | 822 |
'help': 'email address used as HELO address for outgoing emails from \ |
823 |
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
|
824 |
'group': 'email', 'level': 1, |
0 | 825 |
}), |
826 |
) |
|
827 |
||
828 |
@classmethod |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
829 |
def instances_dir(cls): |
0 | 830 |
"""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
|
831 |
return env_path('CW_INSTANCES_DIR', cls._INSTANCES_DIR, 'registry') |
1446 | 832 |
|
0 | 833 |
@classmethod |
834 |
def migration_scripts_dir(cls): |
|
835 |
"""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
|
836 |
if CWDEV: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
837 |
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
|
838 |
mdir = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'migration') |
5028 | 839 |
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
|
840 |
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
|
841 |
return mdir |
0 | 842 |
|
843 |
@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
|
844 |
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
|
845 |
"""return a configuration instance for the given instance identifier |
0 | 846 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
847 |
config = config or guess_configuration(cls.instance_home(appid)) |
0 | 848 |
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
|
849 |
return configcls(appid, debugmode) |
1446 | 850 |
|
0 | 851 |
@classmethod |
852 |
def possible_configurations(cls, appid): |
|
853 |
"""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
|
854 |
instance id |
0 | 855 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
856 |
home = cls.instance_home(appid) |
0 | 857 |
return possible_configurations(home) |
1446 | 858 |
|
0 | 859 |
@classmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
860 |
def instance_home(cls, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
861 |
"""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
|
862 |
instance id |
0 | 863 |
""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
864 |
home = join(cls.instances_dir(), appid) |
0 | 865 |
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
|
866 |
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
|
867 |
' "cubicweb-ctl list")' % appid) |
0 | 868 |
return home |
869 |
||
870 |
MODES = ('common', 'repository', 'Any', 'web') |
|
871 |
MCOMPAT = {'all-in-one': MODES, |
|
872 |
'repository': ('common', 'repository', 'Any'), |
|
873 |
'twisted' : ('common', 'web'),} |
|
874 |
@classmethod |
|
875 |
def accept_mode(cls, mode): |
|
876 |
#assert mode in cls.MODES, mode |
|
877 |
return mode in cls.MCOMPAT[cls.name] |
|
1446 | 878 |
|
0 | 879 |
# default configuration methods ########################################### |
1446 | 880 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
881 |
def default_instance_id(self): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
882 |
"""return the instance identifier, useful for option which need this |
0 | 883 |
as default value |
884 |
""" |
|
885 |
return self.appid |
|
886 |
||
887 |
def default_log_file(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
888 |
"""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
|
889 |
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
|
890 |
import tempfile |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
891 |
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
|
892 |
basename(self.appid), self.name)) |
0 | 893 |
path = basepath + '.log' |
894 |
i = 1 |
|
895 |
while exists(path) and i < 100: # arbitrary limit to avoid infinite loop |
|
896 |
try: |
|
897 |
file(path, 'a') |
|
898 |
break |
|
899 |
except IOError: |
|
900 |
path = '%s-%s.log' % (basepath, i) |
|
901 |
i += 1 |
|
902 |
return path |
|
903 |
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
|
1446 | 904 |
|
0 | 905 |
def default_pid_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
906 |
"""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
|
907 |
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
|
908 |
# 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
|
909 |
rtdir = env_path('CW_RUNTIME_DIR', '/var/run/cubicweb/', 'run time') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
910 |
else: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
911 |
import tempfile |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
912 |
rtdir = env_path('CW_RUNTIME_DIR', tempfile.gettempdir(), 'run time') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
913 |
return join(rtdir, '%s-%s.pid' % (self.appid, self.name)) |
1446 | 914 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
915 |
# instance methods used to get instance specific resources ############# |
1446 | 916 |
|
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
|
917 |
def __init__(self, appid, debugmode=False): |
0 | 918 |
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
|
919 |
CubicWebNoAppConfiguration.__init__(self, debugmode) |
0 | 920 |
self._cubes = None |
921 |
self.load_file_configuration(self.main_config_file()) |
|
922 |
||
923 |
def adjust_sys_path(self): |
|
924 |
CubicWebNoAppConfiguration.adjust_sys_path(self) |
|
925 |
# adding apphome to python path is not usually necessary in production |
|
926 |
# environments, but necessary for tests |
|
927 |
if self.apphome and not self.apphome in sys.path: |
|
928 |
sys.path.insert(0, self.apphome) |
|
929 |
||
930 |
@property |
|
931 |
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
|
932 |
return join(self.instances_dir(), self.appid) |
1446 | 933 |
|
0 | 934 |
@property |
935 |
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
|
936 |
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
|
937 |
# 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
|
938 |
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
|
939 |
else: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
940 |
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
|
941 |
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
|
942 |
return join(iddir, self.appid) |
1446 | 943 |
|
0 | 944 |
def init_cubes(self, cubes): |
1681
1586c0ed9a92
nicer assertion message
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1521
diff
changeset
|
945 |
assert self._cubes is None, self._cubes |
0 | 946 |
self._cubes = self.reorder_cubes(cubes) |
947 |
# load cubes'__init__.py file first |
|
948 |
for cube in cubes: |
|
949 |
__import__('cubes.%s' % cube) |
|
950 |
self.load_site_cubicweb() |
|
951 |
# reload config file in cases options are defined in cubes __init__ |
|
952 |
# or site_cubicweb files |
|
953 |
self.load_file_configuration(self.main_config_file()) |
|
954 |
# configuration initialization hook |
|
955 |
self.load_configuration() |
|
1446 | 956 |
|
0 | 957 |
def cubes(self): |
958 |
"""return the list of cubes used by this instance |
|
959 |
||
960 |
result is ordered from the top level cubes to inner dependencies |
|
961 |
cubes |
|
962 |
""" |
|
963 |
assert self._cubes is not None |
|
964 |
return self._cubes |
|
1446 | 965 |
|
0 | 966 |
def cubes_path(self): |
967 |
"""return the list of path to cubes used by this instance, from outer |
|
968 |
most to inner most cubes |
|
969 |
""" |
|
970 |
return [self.cube_dir(p) for p in self.cubes()] |
|
971 |
||
972 |
def add_cubes(self, cubes): |
|
973 |
"""add given cubes to the list of used cubes""" |
|
974 |
if not isinstance(cubes, list): |
|
975 |
cubes = list(cubes) |
|
976 |
self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
|
1446 | 977 |
|
0 | 978 |
def main_config_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
979 |
"""return instance's control configuration file""" |
0 | 980 |
return join(self.apphome, '%s.conf' % self.name) |
1446 | 981 |
|
0 | 982 |
def save(self): |
983 |
"""write down current configuration""" |
|
984 |
self.generate_config(open(self.main_config_file(), 'w')) |
|
985 |
||
986 |
@cached |
|
987 |
def instance_md5_version(self): |
|
988 |
import md5 |
|
989 |
infos = [] |
|
990 |
for pkg in self.cubes(): |
|
991 |
version = self.cube_version(pkg) |
|
992 |
infos.append('%s-%s' % (pkg, version)) |
|
993 |
return md5.new(';'.join(infos)).hexdigest() |
|
1446 | 994 |
|
0 | 995 |
def load_configuration(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
996 |
"""load instance's configuration files""" |
0 | 997 |
super(CubicWebConfiguration, self).load_configuration() |
998 |
if self.apphome and self.set_language: |
|
999 |
# 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
|
1000 |
self._gettext_init() |
1446 | 1001 |
|
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
|
1002 |
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
|
1003 |
# 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
|
1004 |
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
|
1005 |
if getattr(mod, 'options', None): |
5817
e4207221f3f5
[config] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5812
diff
changeset
|
1006 |
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
|
1007 |
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
|
1008 |
|
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
|
1009 |
def init_log(self, logthreshold=None, force=False): |
0 | 1010 |
"""init the log service""" |
1011 |
if not force and hasattr(self, '_logging_initialized'): |
|
1012 |
return |
|
1013 |
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
|
1014 |
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
|
1015 |
logfile=self.get('log-file')) |
0 | 1016 |
# read a config file if it exists |
1017 |
logconfig = join(self.apphome, 'logging.conf') |
|
1018 |
if exists(logconfig): |
|
1019 |
logging.fileConfig(logconfig) |
|
1020 |
||
1021 |
def available_languages(self, *args): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1022 |
"""return available translation for an instance, by looking for |
0 | 1023 |
compiled catalog |
1024 |
||
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4889
diff
changeset
|
1025 |
take \*args to be usable as a vocabulary method |
0 | 1026 |
""" |
1027 |
from glob import glob |
|
1028 |
yield 'en' # ensure 'en' is yielded even if no .mo found |
|
1029 |
for path in glob(join(self.apphome, 'i18n', |
|
3118 | 1030 |
'*', 'LC_MESSAGES')): |
1031 |
lang = path.split(os.sep)[-2] |
|
0 | 1032 |
if lang != 'en': |
1033 |
yield lang |
|
1446 | 1034 |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
1035 |
def _gettext_init(self): |
0 | 1036 |
"""set language for gettext""" |
1037 |
from gettext import translation |
|
1038 |
path = join(self.apphome, 'i18n') |
|
1039 |
for language in self.available_languages(): |
|
1040 |
self.info("loading language %s", language) |
|
1041 |
try: |
|
1042 |
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
|
1043 |
self.translations[language] = (tr.ugettext, tr.upgettext) |
0 | 1044 |
except (ImportError, AttributeError, IOError): |
1045 |
self.exception('localisation support error for language %s', |
|
1446 | 1046 |
language) |
1047 |
||
0 | 1048 |
def vregistry_path(self): |
1049 |
"""return a list of files or directories where the registry will look |
|
1050 |
for application objects |
|
1051 |
""" |
|
1052 |
templpath = list(reversed(self.cubes_path())) |
|
1053 |
if self.apphome: # may be unset in tests |
|
1054 |
templpath.append(self.apphome) |
|
1055 |
return self.build_vregistry_path(templpath) |
|
1056 |
||
1057 |
def set_sources_mode(self, sources): |
|
1058 |
if not 'all' in sources: |
|
1059 |
print 'warning: ignoring specified sources, requires a repository '\ |
|
1060 |
'configuration' |
|
1446 | 1061 |
|
0 | 1062 |
def migration_handler(self): |
1063 |
"""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
|
1064 |
from cubicweb.migration import MigrationHelper |
0 | 1065 |
return MigrationHelper(self, verbosity=self.verbosity) |
1066 |
||
1067 |
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
|
1068 |
from cubicweb import i18n |
0 | 1069 |
if langs is None: |
1070 |
langs = self.available_languages() |
|
1071 |
i18ndir = join(self.apphome, 'i18n') |
|
1072 |
if not exists(i18ndir): |
|
1073 |
create_dir(i18ndir) |
|
1074 |
sourcedirs = [join(path, 'i18n') for path in self.cubes_path()] |
|
1075 |
sourcedirs.append(self.i18n_lib_dir()) |
|
1076 |
return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs) |
|
1077 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1078 |
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
|
1079 |
"""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
|
1080 |
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
|
1081 |
""" |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1082 |
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
|
1083 |
SMTP_LOCK.acquire() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1084 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1085 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1086 |
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
|
1087 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1088 |
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
|
1089 |
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
|
1090 |
return False |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1091 |
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
|
1092 |
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
|
1093 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1094 |
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
|
1095 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1096 |
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
|
1097 |
recipients, ex) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1098 |
smtp.close() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1099 |
finally: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1100 |
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
|
1101 |
return True |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1102 |
|
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
|
1103 |
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
|
1104 |
logging.getLogger('cubicweb.configuration')) |
1446 | 1105 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1106 |
# 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
|
1107 |
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
|
1108 |
application_configuration = deprecated('use instance_configuration')(instance_configuration) |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1109 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1110 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1111 |
_EXT_REGISTERED = False |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1112 |
def register_stored_procedures(): |
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
1113 |
from logilab.database import FunctionDescr |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1114 |
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
|
1115 |
from rql.nodes import SortTerm, Constant, VariableRef |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1116 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1117 |
global _EXT_REGISTERED |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1118 |
if _EXT_REGISTERED: |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1119 |
return |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1120 |
_EXT_REGISTERED = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1121 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1122 |
class COMMA_JOIN(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1123 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1124 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1125 |
|
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
|
1126 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1127 |
return ', '.join(sorted(term.get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1128 |
for term in iter_funcnode_variables(funcnode))) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1129 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1130 |
register_function(COMMA_JOIN) # XXX do not expose? |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1131 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1132 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1133 |
class CONCAT_STRINGS(COMMA_JOIN): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1134 |
aggregat = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1135 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1136 |
register_function(CONCAT_STRINGS) # XXX bw compat |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1137 |
|
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
|
1138 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1139 |
class GROUP_CONCAT(CONCAT_STRINGS): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1140 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1141 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1142 |
register_function(GROUP_CONCAT) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1143 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1144 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1145 |
class LIMIT_SIZE(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1146 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1147 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1148 |
|
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
|
1149 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1150 |
return funcnode.children[0].get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1151 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1152 |
register_function(LIMIT_SIZE) |
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 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1155 |
class TEXT_LIMIT_SIZE(LIMIT_SIZE): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1156 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1157 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1158 |
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
|
1159 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1160 |
|
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
|
1161 |
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
|
1162 |
"""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
|
1163 |
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
|
1164 |
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
|
1165 |
""" |
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
|
1166 |
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
|
1167 |
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
|
1168 |
|
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
|
1169 |
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
|
1170 |
"""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
|
1171 |
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
|
1172 |
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
|
1173 |
""" |
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
|
1174 |
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
|
1175 |
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
|
1176 |
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
|
1177 |
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
|
1178 |
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
|
1179 |
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
|
1180 |
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
|
1181 |
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
|
1182 |
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
|
1183 |
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
|
1184 |
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
|
1185 |
|
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
|
1186 |
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
|
1187 |
|
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
|
1188 |
|
4322
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1189 |
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
|
1190 |
"""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
|
1191 |
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
|
1192 |
""" |
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
|
1193 |
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
|
1194 |
|
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
|
1195 |
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
|
1196 |
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
|
1197 |
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
|
1198 |
|
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
|
1199 |
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
|
1200 |
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
|
1201 |
|
5630
40d7c7e180f1
[storage] source's callback has a new prototype, update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
1202 |
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
|
1203 |
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
|
1204 |
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
|
1205 |
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
|
1206 |
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
|
1207 |
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
|
1208 |
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
|
1209 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1210 |
register_function(FSPATH) |