author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 10 May 2011 18:53:18 +0200 | |
changeset 7358 | 5a56890b33df |
parent 7264 | 9ed9e1d77ef3 |
child 7691 | c47dcd37d4e3 |
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 -*- |
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
2 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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 |
|
6846
4dd1df437e15
[doc] fix typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6844
diff
changeset
|
25 |
A resource *mode* is a predefined set of settings for various resources |
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
|
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 |
|
6397
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
29 |
* **system**: resources are searched / created in the system directories (eg |
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
|
30 |
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
|
31 |
|
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 |
- 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
|
33 |
- 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
|
34 |
|
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 |
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
|
36 |
instance). |
1493 | 37 |
|
6397
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
38 |
* **user**: resources are searched / created in the user home directory: |
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
39 |
|
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
40 |
- instances are stored in :file:`~/etc/cubicweb.d` |
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
41 |
- temporary files (such as pid file) in :file:`/tmp` |
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
42 |
|
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
43 |
|
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
|
44 |
|
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
|
6397
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
49 |
* **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
|
50 |
|
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
|
6397
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
55 |
* **user**: :: |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3564
diff
changeset
|
56 |
|
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_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_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
|
59 |
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
|
60 |
|
6397
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
61 |
Cubes search path is also affected, see the :ref:`Cube` section. |
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
|
62 |
|
6397
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
63 |
By default, the mode automatically set to `user` if a :file:`.hg` directory is found |
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
64 |
in the cubicweb package, else it's set to `system`. You can force this by setting |
66401ba9332a
[book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6192
diff
changeset
|
65 |
the :envvar:`CW_MODE` environment variable to either `user` or `system` so you can |
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
|
66 |
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
|
67 |
|
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 |
* 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
|
69 |
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
|
70 |
|
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 |
* 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
|
72 |
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
|
73 |
|
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 |
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
|
75 |
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
|
76 |
|
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 |
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
|
78 |
|
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 |
* 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
|
80 |
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
|
81 |
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
|
82 |
|
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 |
* 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
|
84 |
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
|
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 |
|
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 |
.. _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
|
88 |
|
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 |
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
|
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 |
|
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 |
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
|
93 |
`````` |
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
|
94 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
|
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 |
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
|
100 |
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
|
101 |
|
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 |
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
|
103 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
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
|
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 |
|
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 |
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
|
110 |
```````` |
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
|
111 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
112 |
Here are all environment variables that may be used to configure *CubicWeb*: |
3639 | 113 |
|
114 |
.. 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
|
115 |
|
5264
57ac406d1d82
fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5198
diff
changeset
|
116 |
Resource mode: user or system, as explained in :ref:`ResourceMode`. |
3639 | 117 |
|
1493 | 118 |
.. 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
|
119 |
|
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 |
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
|
121 |
directories using ':' as separator (';' under windows environment). |
3639 | 122 |
|
123 |
.. 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
|
124 |
|
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
|
125 |
Directory where cubicweb instances will be found. |
1493 | 126 |
|
3639 | 127 |
.. 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
|
128 |
|
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
|
129 |
Directory where cubicweb instances data will be written (backup file...) |
3639 | 130 |
|
131 |
.. 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
|
132 |
|
3639 | 133 |
Directory where pid files will be written |
0 | 134 |
""" |
5885
5d908f1a7659
[config] use hashlib to avoid warning w/ py2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5817
diff
changeset
|
135 |
|
0 | 136 |
__docformat__ = "restructuredtext en" |
1948 | 137 |
_ = unicode |
0 | 138 |
|
139 |
import sys |
|
140 |
import os |
|
141 |
import logging |
|
7178
a62f24e1497e
fileConfig is in logging.config
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7086
diff
changeset
|
142 |
import logging.config |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
143 |
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
|
144 |
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
|
145 |
from os.path import (exists, join, expanduser, abspath, normpath, |
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
146 |
basename, isdir, dirname, splitext) |
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
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
from logilab.common.logging_ext import set_log_methods, init_log |
0 | 151 |
from logilab.common.configuration import (Configuration, Method, |
152 |
ConfigurationMixIn, merge_options) |
|
153 |
||
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
|
154 |
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
|
155 |
ConfigurationError, Binary) |
6495
3187112bc7cc
#1251878: Cubicweb no longer crash for missing instance and data dir at create.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6192
diff
changeset
|
156 |
from cubicweb.toolsutils import create_dir |
0 | 157 |
|
158 |
CONFIGURATIONS = [] |
|
159 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
160 |
SMTP_LOCK = Lock() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
161 |
|
0 | 162 |
|
163 |
def configuration_cls(name): |
|
164 |
"""return the configuration class registered with the given name""" |
|
165 |
try: |
|
166 |
return [c for c in CONFIGURATIONS if c.name == name][0] |
|
167 |
except IndexError: |
|
168 |
raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
|
169 |
||
170 |
def possible_configurations(directory): |
|
171 |
"""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
|
172 |
according to \*-ctl files |
0 | 173 |
""" |
174 |
return [name for name in ('repository', 'twisted', 'all-in-one') |
|
175 |
if exists(join(directory, '%s.conf' % name))] |
|
176 |
||
177 |
def guess_configuration(directory): |
|
178 |
"""try to guess the configuration to use for a directory. If multiple |
|
179 |
configurations are found, ConfigurationError is raised |
|
180 |
""" |
|
181 |
modes = possible_configurations(directory) |
|
182 |
if len(modes) != 1: |
|
183 |
raise ConfigurationError('unable to guess configuration from %r %s' |
|
184 |
% (directory, modes)) |
|
185 |
return modes[0] |
|
186 |
||
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
187 |
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
|
188 |
"""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
|
189 |
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
|
190 |
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
|
191 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
192 |
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
|
193 |
""" |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
prefix = dirname(start_path) |
6503
0fd079726606
[packaging] Egg are not valid cubicweb prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6502
diff
changeset
|
198 |
while (not isdir(join(prefix, 'share', 'cubicweb')) |
0fd079726606
[packaging] Egg are not valid cubicweb prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6502
diff
changeset
|
199 |
or prefix.endswith('.egg')) and prefix != old_prefix: |
5021
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 = prefix |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
201 |
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
|
202 |
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
|
203 |
return prefix |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
204 |
return sys.prefix |
0 | 205 |
|
206 |
# persistent options definition |
|
207 |
PERSISTENT_OPTIONS = ( |
|
208 |
('encoding', |
|
209 |
{'type' : 'string', |
|
210 |
'default': 'UTF-8', |
|
211 |
'help': _('user interface encoding'), |
|
212 |
'group': 'ui', 'sitewide': True, |
|
1446 | 213 |
}), |
0 | 214 |
('language', |
215 |
{'type' : 'string', |
|
216 |
'default': 'en', |
|
217 |
'vocabulary': Method('available_languages'), |
|
218 |
'help': _('language of the user interface'), |
|
1446 | 219 |
'group': 'ui', |
0 | 220 |
}), |
221 |
('date-format', |
|
222 |
{'type' : 'string', |
|
223 |
'default': '%Y/%m/%d', |
|
224 |
'help': _('how to format date in the ui ("man strftime" for format description)'), |
|
1446 | 225 |
'group': 'ui', |
0 | 226 |
}), |
227 |
('datetime-format', |
|
228 |
{'type' : 'string', |
|
229 |
'default': '%Y/%m/%d %H:%M', |
|
230 |
'help': _('how to format date and time in the ui ("man strftime" for format description)'), |
|
1446 | 231 |
'group': 'ui', |
0 | 232 |
}), |
233 |
('time-format', |
|
234 |
{'type' : 'string', |
|
235 |
'default': '%H:%M', |
|
236 |
'help': _('how to format time in the ui ("man strftime" for format description)'), |
|
1446 | 237 |
'group': 'ui', |
0 | 238 |
}), |
239 |
('float-format', |
|
240 |
{'type' : 'string', |
|
241 |
'default': '%.3f', |
|
242 |
'help': _('how to format float numbers in the ui'), |
|
1446 | 243 |
'group': 'ui', |
0 | 244 |
}), |
245 |
('default-text-format', |
|
246 |
{'type' : 'choice', |
|
247 |
'choices': ('text/plain', 'text/rest', 'text/html'), |
|
248 |
'default': 'text/html', # use fckeditor in the web ui |
|
249 |
'help': _('default text format for rich text fields.'), |
|
1446 | 250 |
'group': 'ui', |
0 | 251 |
}), |
252 |
('short-line-size', |
|
253 |
{'type' : 'int', |
|
5391
fe3fe2b2b60a
[config] augment default value for short-line-size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5264
diff
changeset
|
254 |
'default': 80, |
0 | 255 |
'help': _('maximum number of characters in short description'), |
256 |
'group': 'navigation', |
|
257 |
}), |
|
258 |
) |
|
259 |
||
260 |
def register_persistent_options(options): |
|
261 |
global PERSISTENT_OPTIONS |
|
262 |
PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options) |
|
1446 | 263 |
|
0 | 264 |
CFGTYPE2ETYPE_MAP = { |
265 |
'string': 'String', |
|
266 |
'choice': 'String', |
|
267 |
'yn': 'Boolean', |
|
268 |
'int': 'Int', |
|
269 |
'float' : 'Float', |
|
270 |
} |
|
1446 | 271 |
|
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
|
272 |
_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
|
273 |
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
|
274 |
|
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
|
275 |
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
|
276 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
277 |
try: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
278 |
_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
|
279 |
except KeyError: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
280 |
_INSTALL_PREFIX = _find_prefix() |
6502
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
281 |
_USR_INSTALL = _INSTALL_PREFIX == '/usr' |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
282 |
|
0 | 283 |
class CubicWebNoAppConfiguration(ConfigurationMixIn): |
284 |
"""base class for cubicweb configuration without a specific instance directory |
|
285 |
""" |
|
286 |
# to set in concrete configuration |
|
287 |
name = None |
|
288 |
# log messages format (see logging module documentation for available keys) |
|
289 |
log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s' |
|
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
290 |
# the format below can be useful to debug multi thread issues: |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
291 |
# 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
|
292 |
# nor remove appobjects based on unused interface [???] |
0 | 293 |
cleanup_interface_sobjects = True |
294 |
||
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
295 |
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
|
296 |
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
|
297 |
_CUBES_DIR = join(CW_SOFTWARE_ROOT, '../cubes') |
0 | 298 |
else: |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
299 |
mode = _forced_mode or 'system' |
5022
7e09702aa766
fix _cubes dir
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
300 |
_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
|
301 |
|
6495
3187112bc7cc
#1251878: Cubicweb no longer crash for missing instance and data dir at create.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6192
diff
changeset
|
302 |
CUBES_DIR = abspath(os.environ.get('CW_CUBES_DIR', _CUBES_DIR)) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
303 |
CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep) |
0 | 304 |
|
1046
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
305 |
options = ( |
0 | 306 |
('log-threshold', |
307 |
{'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
|
308 |
'default': 'WARNING', |
0 | 309 |
'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
|
310 |
'group': 'main', 'level': 1, |
0 | 311 |
}), |
6779
accf5978a440
[daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
312 |
('umask', |
accf5978a440
[daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
313 |
{'type' : 'int', |
accf5978a440
[daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
314 |
'default': 077, |
accf5978a440
[daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
315 |
'help': 'permission umask for files created by the server', |
accf5978a440
[daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
316 |
'group': 'main', 'level': 2, |
accf5978a440
[daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
317 |
}), |
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
|
318 |
# 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
|
319 |
('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
|
320 |
{'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
|
321 |
'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
|
322 |
'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
|
323 |
'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
|
324 |
}), |
0 | 325 |
('pyro-ns-host', |
326 |
{'type' : 'string', |
|
378
c0cd7398edff
revert local debug checkin
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
369
diff
changeset
|
327 |
'default': '', |
0 | 328 |
'help': 'Pyro name server\'s host. If not set, will be detected by a \ |
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7129
diff
changeset
|
329 |
broadcast query. It may contains port information using <host>:<port> notation. \ |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7129
diff
changeset
|
330 |
Use "NO_PYRONS" to create a Pyro server but not register to a pyro nameserver', |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5322
diff
changeset
|
331 |
'group': 'pyro', 'level': 1, |
0 | 332 |
}), |
333 |
('pyro-ns-group', |
|
334 |
{'type' : 'string', |
|
335 |
'default': 'cubicweb', |
|
336 |
'help': 'Pyro name server\'s group where the repository will be \ |
|
337 |
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
|
338 |
'group': 'pyro', 'level': 1, |
0 | 339 |
}), |
340 |
# common configuration options which are potentially required as soon as |
|
341 |
# you're using "base" application objects (ie to really server/web |
|
342 |
# specific) |
|
343 |
('base-url', |
|
344 |
{'type' : 'string', |
|
345 |
'default': None, |
|
346 |
'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
|
347 |
'group': 'main', 'level': 1, |
0 | 348 |
}), |
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
|
349 |
('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
|
350 |
{'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
|
351 |
'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
|
352 |
'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
|
353 |
'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
|
354 |
}), |
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
|
355 |
('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
|
356 |
{'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
|
357 |
'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
|
358 |
'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
|
359 |
'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
|
360 |
'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
|
361 |
'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
|
362 |
}), |
0 | 363 |
('mangle-emails', |
364 |
{'type' : 'yn', |
|
365 |
'default': False, |
|
366 |
'help': "don't display actual email addresses but mangle them if \ |
|
367 |
this option is set to yes", |
|
5456
d040889fac4e
merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
diff
changeset
|
368 |
'group': 'email', 'level': 3, |
0 | 369 |
}), |
370 |
) |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
371 |
# static and class methods used to get instance independant resources ## |
0 | 372 |
@staticmethod |
373 |
def cubicweb_version(): |
|
374 |
"""return installed cubicweb version""" |
|
375 |
from logilab.common.changelog import Version |
|
376 |
from cubicweb import __pkginfo__ |
|
377 |
version = __pkginfo__.numversion |
|
378 |
assert len(version) == 3, version |
|
379 |
return Version(version) |
|
1446 | 380 |
|
0 | 381 |
@staticmethod |
382 |
def persistent_options_configuration(): |
|
383 |
return Configuration(options=PERSISTENT_OPTIONS) |
|
384 |
||
385 |
@classmethod |
|
386 |
def shared_dir(cls): |
|
387 |
"""return the shared data directory (i.e. directory where standard |
|
388 |
library views and data may be found) |
|
389 |
""" |
|
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
|
390 |
if CWDEV: |
0 | 391 |
return join(CW_SOFTWARE_ROOT, 'web') |
1039 | 392 |
return cls.cube_dir('shared') |
1446 | 393 |
|
0 | 394 |
@classmethod |
395 |
def i18n_lib_dir(cls): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
396 |
"""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
|
397 |
if CWDEV: |
0 | 398 |
return join(CW_SOFTWARE_ROOT, 'i18n') |
399 |
return join(cls.shared_dir(), 'i18n') |
|
400 |
||
401 |
@classmethod |
|
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
402 |
def cw_languages(cls): |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
403 |
for fname in os.listdir(join(cls.i18n_lib_dir())): |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
404 |
if fname.endswith('.po'): |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
405 |
yield splitext(fname)[0] |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
406 |
|
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
407 |
|
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
408 |
@classmethod |
0 | 409 |
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
|
410 |
import re |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
411 |
cubes = set() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
412 |
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
|
413 |
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
|
414 |
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
|
415 |
% directory) |
4001
bc31ede2085d
dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3915
diff
changeset
|
416 |
continue |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
417 |
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
|
418 |
if cube == 'shared': |
5026
1f8238eaec9b
[config] more cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5025
diff
changeset
|
419 |
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
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
cubes.add(cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
425 |
return sorted(cubes) |
1446 | 426 |
|
0 | 427 |
@classmethod |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
428 |
def cubes_search_path(cls): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
429 |
"""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
|
430 |
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
|
431 |
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
|
432 |
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
|
433 |
path.append(cls.CUBES_DIR) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
434 |
return path |
1446 | 435 |
|
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
|
436 |
@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
|
437 |
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
|
438 |
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
|
439 |
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
|
440 |
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
|
441 |
extrapath[cubesdir] = 'cubes' |
4325 | 442 |
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
|
443 |
|
0 | 444 |
@classmethod |
445 |
def cube_dir(cls, cube): |
|
6799
30faf6021278
[config] use %r instead of %s for cube name makes things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6788
diff
changeset
|
446 |
"""return the cube directory for the given cube id, raise |
30faf6021278
[config] use %r instead of %s for cube name makes things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6788
diff
changeset
|
447 |
`ConfigurationError` if it doesn't exist |
0 | 448 |
""" |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
449 |
for directory in cls.cubes_search_path(): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
450 |
cubedir = join(directory, cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
451 |
if exists(cubedir): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
452 |
return cubedir |
6799
30faf6021278
[config] use %r instead of %s for cube name makes things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6788
diff
changeset
|
453 |
raise ConfigurationError('no cube %r in %s' % ( |
30faf6021278
[config] use %r instead of %s for cube name makes things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6788
diff
changeset
|
454 |
cube, cls.cubes_search_path())) |
0 | 455 |
|
456 |
@classmethod |
|
457 |
def cube_migration_scripts_dir(cls, cube): |
|
458 |
"""cube migration scripts directory""" |
|
459 |
return join(cls.cube_dir(cube), 'migration') |
|
1446 | 460 |
|
0 | 461 |
@classmethod |
462 |
def cube_pkginfo(cls, cube): |
|
463 |
"""return the information module for the given cube""" |
|
464 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
465 |
try: |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
466 |
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
|
467 |
return getattr(parent, cube).__pkginfo__ |
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
468 |
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
|
469 |
raise ConfigurationError( |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
470 |
'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
|
471 |
% (cube, ex.__class__.__name__, ex)) |
0 | 472 |
|
473 |
@classmethod |
|
474 |
def cube_version(cls, cube): |
|
1446 | 475 |
"""return the version of the cube located in the given directory |
0 | 476 |
""" |
477 |
from logilab.common.changelog import Version |
|
478 |
version = cls.cube_pkginfo(cube).numversion |
|
479 |
assert len(version) == 3, version |
|
480 |
return Version(version) |
|
481 |
||
482 |
@classmethod |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
483 |
def _cube_deps(cls, cube, key, oldkey): |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
484 |
"""return cubicweb cubes used by the given cube""" |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
485 |
pkginfo = cls.cube_pkginfo(cube) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
486 |
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
|
487 |
# explicit __xxx_cubes__ attribute |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
488 |
deps = getattr(pkginfo, key) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
489 |
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
|
490 |
# 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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
# 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
|
495 |
if hasattr(pkginfo, oldkey): |
5381
1e6f23066067
[config] include cube name in warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
496 |
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
|
497 |
% (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
|
498 |
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
|
499 |
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
|
500 |
deps = {} |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
501 |
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
|
502 |
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
|
503 |
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
|
504 |
if x.startswith('cubicweb-')) |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
505 |
if not isinstance(deps, dict): |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
506 |
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
|
507 |
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
|
508 |
DeprecationWarning) |
5917
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
509 |
for depcube in deps: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
510 |
try: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
511 |
newname = CW_MIGRATION_MAP[depcube] |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
512 |
except KeyError: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
513 |
pass |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
514 |
else: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
515 |
deps[newname] = deps.pop(depcube) |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
516 |
return deps |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
517 |
|
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
518 |
@classmethod |
6659
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
519 |
def cube_depends_cubicweb_version(cls, cube): |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
520 |
# XXX no backward compat (see _cube_deps above) |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
521 |
try: |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
522 |
pkginfo = cls.cube_pkginfo(cube) |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
523 |
deps = getattr(pkginfo, '__depends__') |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
524 |
return deps.get('cubicweb') |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
525 |
except AttributeError: |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
526 |
return None |
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
527 |
|
6205927e927a
fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6657
diff
changeset
|
528 |
@classmethod |
0 | 529 |
def cube_dependencies(cls, cube): |
530 |
"""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
|
531 |
return cls._cube_deps(cube, '__depends_cubes__', '__use__') |
0 | 532 |
|
533 |
@classmethod |
|
534 |
def cube_recommends(cls, cube): |
|
535 |
"""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
|
536 |
return cls._cube_deps(cube, '__recommends_cubes__', '__recommend__') |
0 | 537 |
|
538 |
@classmethod |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
539 |
def expand_cubes(cls, cubes, with_recommends=False): |
0 | 540 |
"""expand the given list of top level cubes used by adding recursivly |
541 |
each cube dependencies |
|
542 |
""" |
|
543 |
cubes = list(cubes) |
|
544 |
todo = cubes[:] |
|
5917
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
545 |
if with_recommends: |
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
546 |
available = set(cls.available_cubes()) |
0 | 547 |
while todo: |
548 |
cube = todo.pop(0) |
|
549 |
for depcube in cls.cube_dependencies(cube): |
|
550 |
if depcube not in cubes: |
|
551 |
cubes.append(depcube) |
|
552 |
todo.append(depcube) |
|
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
553 |
if with_recommends: |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
554 |
for depcube in cls.cube_recommends(cube): |
5917
64198285352e
[config] expand_cubes(with_recommends=True) shouldn't return recommened-but-not-installed cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
555 |
if depcube not in cubes and depcube in available: |
2762
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
556 |
cubes.append(depcube) |
b1bb33b37992
[config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2665
diff
changeset
|
557 |
todo.append(depcube) |
0 | 558 |
return cubes |
559 |
||
560 |
@classmethod |
|
561 |
def reorder_cubes(cls, cubes): |
|
562 |
"""reorder cubes from the top level cubes to inner dependencies |
|
563 |
cubes |
|
564 |
""" |
|
5322
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
565 |
from logilab.common.graph import ordered_nodes, UnorderableGraph |
0 | 566 |
graph = {} |
567 |
for cube in cubes: |
|
568 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
569 |
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
|
570 |
if dep in cubes) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5023
diff
changeset
|
571 |
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
|
572 |
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
|
573 |
try: |
c0b7687bce3d
[config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5298
diff
changeset
|
574 |
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
|
575 |
except UnorderableGraph, ex: |
0 | 576 |
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
|
577 |
% ex.cycles) |
1446 | 578 |
|
0 | 579 |
@classmethod |
580 |
def cls_adjust_sys_path(cls): |
|
581 |
"""update python path if necessary""" |
|
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
582 |
cubes_parent_dir = normpath(join(cls.CUBES_DIR, '..')) |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
583 |
if not cubes_parent_dir in sys.path: |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
584 |
sys.path.insert(0, cubes_parent_dir) |
0 | 585 |
try: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
586 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
587 |
cubes.__path__ = cls.cubes_search_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
588 |
except ImportError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
589 |
return # cubes dir doesn't exists |
0 | 590 |
|
591 |
@classmethod |
|
7005
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
592 |
def load_available_configs(cls): |
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
593 |
from logilab.common.modutils import load_module_from_file |
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
594 |
for conffile in ('web/webconfig.py', 'etwist/twconfig.py', |
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
595 |
'server/serverconfig.py',): |
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
596 |
if exists(join(CW_SOFTWARE_ROOT, conffile)): |
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
597 |
load_module_from_file(join(CW_SOFTWARE_ROOT, conffile)) |
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
598 |
|
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
599 |
@classmethod |
0 | 600 |
def load_cwctl_plugins(cls): |
601 |
from logilab.common.modutils import load_module_from_file |
|
602 |
cls.cls_adjust_sys_path() |
|
603 |
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
|
604 |
'server/serverctl.py', |
0 | 605 |
'devtools/devctl.py', 'goa/goactl.py'): |
606 |
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
|
607 |
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
|
608 |
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
|
609 |
except ImportError, err: |
7005
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
610 |
cls.error('could not import the command provider %s: %s', |
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
611 |
ctlfile, err) |
0 | 612 |
cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
613 |
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
|
614 |
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
|
615 |
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
|
616 |
initfile = join(cls.cube_dir(cube), '__init__.py') |
0 | 617 |
if exists(pluginfile): |
618 |
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
|
619 |
__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
|
620 |
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
|
621 |
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
|
622 |
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
|
623 |
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
|
624 |
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
|
625 |
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
|
626 |
try: |
0 | 627 |
__import__('cubes.%s.ecplugin' % cube) |
628 |
cls.info('loaded cubicweb-ctl plugin from %s', cube) |
|
629 |
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
|
630 |
cls.exception('while loading plugin %s', oldpluginfile) |
0 | 631 |
elif exists(initfile): |
632 |
try: |
|
633 |
__import__('cubes.%s' % cube) |
|
634 |
except: |
|
635 |
cls.exception('while loading cube %s', cube) |
|
636 |
else: |
|
1446 | 637 |
cls.warning('no __init__ file in cube %s', cube) |
0 | 638 |
|
639 |
@classmethod |
|
640 |
def init_available_cubes(cls): |
|
641 |
"""cubes may register some sources (svnfile for instance) in their |
|
642 |
__init__ file, so they should be loaded early in the startup process |
|
643 |
""" |
|
644 |
for cube in cls.available_cubes(): |
|
645 |
try: |
|
646 |
__import__('cubes.%s' % cube) |
|
647 |
except Exception, ex: |
|
648 |
cls.warning("can't init cube %s: %s", cube, ex) |
|
1446 | 649 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
650 |
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
|
651 |
cube_appobject_path = set(['entities']) |
0 | 652 |
|
653 |
@classmethod |
|
654 |
def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None): |
|
655 |
"""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
|
656 |
directories that should be loaded by the instance objects registry. |
0 | 657 |
|
658 |
:param evobjpath: |
|
659 |
optional list of sub-directories (or files without the .py ext) of |
|
660 |
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
|
661 |
if they exists. If not give, default to `cubicweb_appobject_path` class |
0 | 662 |
attribute. |
663 |
:param tvobjpath: |
|
664 |
optional list of sub-directories (or files without the .py ext) of |
|
665 |
directories given in `templpath` that should be tested and added to |
|
666 |
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
|
667 |
`cube_appobject_path` class attribute. |
0 | 668 |
""" |
669 |
vregpath = cls.build_vregistry_cubicweb_path(evobjpath) |
|
670 |
vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath) |
|
671 |
return vregpath |
|
672 |
||
673 |
@classmethod |
|
674 |
def build_vregistry_cubicweb_path(cls, evobjpath=None): |
|
675 |
vregpath = [] |
|
676 |
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
|
677 |
evobjpath = cls.cubicweb_appobject_path |
0 | 678 |
for subdir in evobjpath: |
679 |
path = join(CW_SOFTWARE_ROOT, subdir) |
|
680 |
if exists(path): |
|
681 |
vregpath.append(path) |
|
682 |
return vregpath |
|
683 |
||
684 |
@classmethod |
|
685 |
def build_vregistry_cube_path(cls, templpath, tvobjpath=None): |
|
686 |
vregpath = [] |
|
687 |
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
|
688 |
tvobjpath = cls.cube_appobject_path |
0 | 689 |
for directory in templpath: |
690 |
for subdir in tvobjpath: |
|
691 |
path = join(directory, subdir) |
|
692 |
if exists(path): |
|
693 |
vregpath.append(path) |
|
694 |
elif exists(path + '.py'): |
|
695 |
vregpath.append(path + '.py') |
|
696 |
return vregpath |
|
1446 | 697 |
|
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
|
698 |
def __init__(self, debugmode=False): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
699 |
register_stored_procedures() |
6494
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
700 |
self._cubes = None |
6748
52226299c352
[config] Use newstyle call to parent classe method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6741
diff
changeset
|
701 |
super(CubicWebNoAppConfiguration, self).__init__() |
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
|
702 |
self.debugmode = debugmode |
0 | 703 |
self.adjust_sys_path() |
704 |
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
|
705 |
# 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
|
706 |
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
|
707 |
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
|
708 |
# 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
|
709 |
# 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
|
710 |
# 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
|
711 |
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
|
712 |
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
|
713 |
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
|
714 |
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
|
715 |
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
|
716 |
cw_rest_init() |
0 | 717 |
|
718 |
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
|
719 |
# overriden in CubicWebConfiguration |
0 | 720 |
self.cls_adjust_sys_path() |
1446 | 721 |
|
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
|
722 |
def init_log(self, logthreshold=None, logfile=None, syslog=False): |
0 | 723 |
"""init the log service""" |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
724 |
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
|
725 |
if self.debugmode: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
726 |
logthreshold = 'DEBUG' |
0 | 727 |
else: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
728 |
logthreshold = self['log-threshold'] |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
729 |
if sys.platform == 'win32': |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
730 |
# no logrotate on win32, so use logging rotation facilities |
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
731 |
# 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
|
732 |
# idea: make this configurable? |
5655 | 733 |
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
|
734 |
rotation_parameters={'when': 'W6', # every sunday |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
735 |
'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
|
736 |
'backupCount': 52}) |
5640
8a6d14f4fb9d
logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5456
diff
changeset
|
737 |
else: |
5655 | 738 |
init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format) |
0 | 739 |
# configure simpleTal logger |
740 |
logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
|
741 |
||
742 |
def vregistry_path(self): |
|
743 |
"""return a list of files or directories where the registry will look |
|
744 |
for application objects. By default return nothing in NoApp config. |
|
745 |
""" |
|
746 |
return [] |
|
1446 | 747 |
|
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
|
748 |
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
|
749 |
|
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
|
750 |
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
|
751 |
"""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
|
752 |
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
|
753 |
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
|
754 |
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
|
755 |
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
|
756 |
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
|
757 |
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
|
758 |
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
|
759 |
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
|
760 |
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
|
761 |
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
|
762 |
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
|
763 |
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
|
764 |
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
|
765 |
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
|
766 |
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
|
767 |
'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
|
768 |
|
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
|
769 |
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
|
770 |
# 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
|
771 |
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
|
772 |
module = load_module_from_modpath(modpath_from_file(sitefile, self.extrapath)) |
6087
bdfbd6aa5758
[debug] change severity of 'site_cubicweb loaded' message to debug
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5960
diff
changeset
|
773 |
self.debug('%s loaded', sitefile) |
5812
d970049d7cfd
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5647
diff
changeset
|
774 |
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
|
775 |
|
7031
a04621040cad
[config refactoring] rename eproperty_definition method to cwproperty_definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7005
diff
changeset
|
776 |
def cwproperty_definitions(self): |
0 | 777 |
cfg = self.persistent_options_configuration() |
778 |
for section, options in cfg.options_by_section(): |
|
779 |
section = section.lower() |
|
780 |
for optname, optdict, value in options: |
|
781 |
key = '%s.%s' % (section, optname) |
|
782 |
type, vocab = self.map_option(optdict) |
|
783 |
default = cfg.option_default(optname, optdict) |
|
784 |
pdef = {'type': type, 'vocabulary': vocab, 'default': default, |
|
785 |
'help': optdict['help'], |
|
786 |
'sitewide': optdict.get('sitewide', False)} |
|
787 |
yield key, pdef |
|
1446 | 788 |
|
0 | 789 |
def map_option(self, optdict): |
790 |
try: |
|
791 |
vocab = optdict['choices'] |
|
792 |
except KeyError: |
|
793 |
vocab = optdict.get('vocabulary') |
|
794 |
if isinstance(vocab, Method): |
|
795 |
vocab = getattr(self, vocab.method, ()) |
|
796 |
return CFGTYPE2ETYPE_MAP[optdict['type']], vocab |
|
797 |
||
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
|
798 |
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
|
799 |
"""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
|
800 |
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
|
801 |
""" |
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
|
802 |
return None |
1446 | 803 |
|
6494
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
804 |
_cubes = None |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
805 |
|
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
806 |
def init_cubes(self, cubes): |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
807 |
assert self._cubes is None, self._cubes |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
808 |
self._cubes = self.reorder_cubes(cubes) |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
809 |
# load cubes'__init__.py file first |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
810 |
for cube in cubes: |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
811 |
__import__('cubes.%s' % cube) |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
812 |
self.load_site_cubicweb() |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
813 |
|
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
814 |
def cubes(self): |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
815 |
"""return the list of cubes used by this instance |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
816 |
|
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
817 |
result is ordered from the top level cubes to inner dependencies |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
818 |
cubes |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
819 |
""" |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
820 |
assert self._cubes is not None, 'cubes not initialized' |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
821 |
return self._cubes |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
822 |
|
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
823 |
def cubes_path(self): |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
824 |
"""return the list of path to cubes used by this instance, from outer |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
825 |
most to inner most cubes |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
826 |
""" |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
827 |
return [self.cube_dir(p) for p in self.cubes()] |
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
828 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
829 |
|
0 | 830 |
class CubicWebConfiguration(CubicWebNoAppConfiguration): |
831 |
"""base class for cubicweb server and web configurations""" |
|
1446 | 832 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
833 |
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
|
834 |
_INSTANCES_DIR = expanduser('~/etc/cubicweb.d/') |
6502
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
835 |
#mode == system' |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
836 |
elif _USR_INSTALL: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
837 |
_INSTANCES_DIR = '/etc/cubicweb.d/' |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
838 |
else: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
839 |
_INSTANCES_DIR = join(_INSTALL_PREFIX, 'etc', 'cubicweb.d') |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
840 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
841 |
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
|
842 |
_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
|
843 |
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
|
844 |
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
|
845 |
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
|
846 |
os.makedirs(_INSTANCES_DIR) |
0 | 847 |
|
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
848 |
# set to true during repair (shell, migration) to allow some things which |
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
849 |
# wouldn't be possible otherwise |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2449
diff
changeset
|
850 |
repairing = False |
1446 | 851 |
|
0 | 852 |
options = CubicWebNoAppConfiguration.options + ( |
853 |
('log-file', |
|
854 |
{'type' : 'string', |
|
855 |
'default': Method('default_log_file'), |
|
856 |
'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
|
857 |
'group': 'main', 'level': 2, |
0 | 858 |
}), |
859 |
# email configuration |
|
860 |
('smtp-host', |
|
861 |
{'type' : 'string', |
|
862 |
'default': 'mail', |
|
863 |
'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
|
864 |
'group': 'email', 'level': 1, |
0 | 865 |
}), |
866 |
('smtp-port', |
|
867 |
{'type' : 'int', |
|
868 |
'default': 25, |
|
869 |
'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
|
870 |
'group': 'email', 'level': 1, |
0 | 871 |
}), |
872 |
('sender-name', |
|
873 |
{'type' : 'string', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
874 |
'default': Method('default_instance_id'), |
0 | 875 |
'help': 'name used as HELO name for outgoing emails from the \ |
876 |
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
|
877 |
'group': 'email', 'level': 2, |
0 | 878 |
}), |
879 |
('sender-addr', |
|
880 |
{'type' : 'string', |
|
2351
dddee537e4d5
don't use internal address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
881 |
'default': 'cubicweb@mydomain.com', |
0 | 882 |
'help': 'email address used as HELO address for outgoing emails from \ |
883 |
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
|
884 |
'group': 'email', 'level': 1, |
0 | 885 |
}), |
886 |
) |
|
887 |
||
888 |
@classmethod |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
889 |
def instances_dir(cls): |
0 | 890 |
"""return the control directory""" |
6495
3187112bc7cc
#1251878: Cubicweb no longer crash for missing instance and data dir at create.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6192
diff
changeset
|
891 |
return abspath(os.environ.get('CW_INSTANCES_DIR', cls._INSTANCES_DIR)) |
1446 | 892 |
|
0 | 893 |
@classmethod |
894 |
def migration_scripts_dir(cls): |
|
895 |
"""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
|
896 |
if CWDEV: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
897 |
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
|
898 |
mdir = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'migration') |
5028 | 899 |
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
|
900 |
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
|
901 |
return mdir |
0 | 902 |
|
903 |
@classmethod |
|
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
904 |
def config_for(cls, appid, config=None, debugmode=False, creating=False): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
905 |
"""return a configuration instance for the given instance identifier |
0 | 906 |
""" |
7005
f45f42256905
[config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6846
diff
changeset
|
907 |
cls.load_available_configs() |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
908 |
config = config or guess_configuration(cls.instance_home(appid)) |
0 | 909 |
configcls = configuration_cls(config) |
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
910 |
return configcls(appid, debugmode, creating) |
1446 | 911 |
|
0 | 912 |
@classmethod |
913 |
def possible_configurations(cls, appid): |
|
914 |
"""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
|
915 |
instance id |
0 | 916 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
917 |
home = cls.instance_home(appid) |
0 | 918 |
return possible_configurations(home) |
1446 | 919 |
|
0 | 920 |
@classmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
921 |
def instance_home(cls, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
922 |
"""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
|
923 |
instance id |
0 | 924 |
""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
925 |
home = join(cls.instances_dir(), appid) |
0 | 926 |
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
|
927 |
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
|
928 |
' "cubicweb-ctl list")' % appid) |
0 | 929 |
return home |
930 |
||
931 |
MODES = ('common', 'repository', 'Any', 'web') |
|
932 |
MCOMPAT = {'all-in-one': MODES, |
|
933 |
'repository': ('common', 'repository', 'Any'), |
|
934 |
'twisted' : ('common', 'web'),} |
|
935 |
@classmethod |
|
936 |
def accept_mode(cls, mode): |
|
937 |
#assert mode in cls.MODES, mode |
|
938 |
return mode in cls.MCOMPAT[cls.name] |
|
1446 | 939 |
|
0 | 940 |
# default configuration methods ########################################### |
1446 | 941 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
942 |
def default_instance_id(self): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
943 |
"""return the instance identifier, useful for option which need this |
0 | 944 |
as default value |
945 |
""" |
|
946 |
return self.appid |
|
947 |
||
948 |
def default_log_file(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
949 |
"""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
|
950 |
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
|
951 |
import tempfile |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
952 |
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
|
953 |
basename(self.appid), self.name)) |
0 | 954 |
path = basepath + '.log' |
955 |
i = 1 |
|
956 |
while exists(path) and i < 100: # arbitrary limit to avoid infinite loop |
|
957 |
try: |
|
958 |
file(path, 'a') |
|
959 |
break |
|
960 |
except IOError: |
|
961 |
path = '%s-%s.log' % (basepath, i) |
|
962 |
i += 1 |
|
963 |
return path |
|
6502
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
964 |
if _USR_INSTALL: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
965 |
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
966 |
else: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
967 |
log_path = os.path.join(_INSTALL_PREFIX, 'var', 'log', 'cubicweb', '%s-%s.log') |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
968 |
return log_path % (self.appid, self.name) |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
969 |
|
0 | 970 |
def default_pid_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
971 |
"""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
|
972 |
if self.mode == 'system': |
6502
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
973 |
if _USR_INSTALL: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
974 |
default = '/var/run/cubicweb/' |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
975 |
else: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
976 |
default = os.path.join(_INSTALL_PREFIX, 'var', 'run', 'cubicweb') |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
977 |
else: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
978 |
import tempfile |
5960
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
979 |
default = tempfile.gettempdir() |
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
980 |
# runtime directory created on startup if necessary, don't check it |
ffa38c4ec592
[config] run time directory created when necessary on startup, don't check it exists while creating the instance (closes #1177687)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5933
diff
changeset
|
981 |
# exists |
6495
3187112bc7cc
#1251878: Cubicweb no longer crash for missing instance and data dir at create.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6192
diff
changeset
|
982 |
rtdir = abspath(os.environ.get('CW_RUNTIME_DIR', default)) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
983 |
return join(rtdir, '%s-%s.pid' % (self.appid, self.name)) |
1446 | 984 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
985 |
# instance methods used to get instance specific resources ############# |
1446 | 986 |
|
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
987 |
def __init__(self, appid, debugmode=False, creating=False): |
0 | 988 |
self.appid = appid |
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
989 |
# set to true while creating an instance |
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
990 |
self.creating = creating |
6748
52226299c352
[config] Use newstyle call to parent classe method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6741
diff
changeset
|
991 |
super(CubicWebConfiguration, self).__init__(debugmode) |
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
992 |
fake_gettext = (unicode, lambda ctx, msgid: unicode(msgid)) |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
993 |
for lang in self.available_languages(): |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6748
diff
changeset
|
994 |
self.translations[lang] = fake_gettext |
0 | 995 |
self._cubes = None |
996 |
self.load_file_configuration(self.main_config_file()) |
|
997 |
||
998 |
def adjust_sys_path(self): |
|
6748
52226299c352
[config] Use newstyle call to parent classe method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6741
diff
changeset
|
999 |
super(CubicWebConfiguration, self).adjust_sys_path() |
0 | 1000 |
# adding apphome to python path is not usually necessary in production |
1001 |
# environments, but necessary for tests |
|
1002 |
if self.apphome and not self.apphome in sys.path: |
|
1003 |
sys.path.insert(0, self.apphome) |
|
1004 |
||
1005 |
@property |
|
1006 |
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
|
1007 |
return join(self.instances_dir(), self.appid) |
1446 | 1008 |
|
0 | 1009 |
@property |
1010 |
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
|
1011 |
if self.mode == 'system': |
6502
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
1012 |
if _USR_INSTALL: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
1013 |
iddir = os.path.join('/var','lib', 'cubicweb', 'instances') |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
1014 |
else: |
1e1de0339a95
[config] Put "Instance" and "Instance data" directory within cubiweb install prefix.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6495
diff
changeset
|
1015 |
iddir = os.path.join(_INSTALL_PREFIX, 'var', 'lib', 'cubicweb', 'instances') |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
1016 |
else: |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
1017 |
iddir = self.instances_dir() |
6495
3187112bc7cc
#1251878: Cubicweb no longer crash for missing instance and data dir at create.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6192
diff
changeset
|
1018 |
iddir = abspath(os.environ.get('CW_INSTANCES_DATA_DIR', iddir)) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5013
diff
changeset
|
1019 |
return join(iddir, self.appid) |
1446 | 1020 |
|
0 | 1021 |
def init_cubes(self, cubes): |
6494
70c87c717e4a
[config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6397
diff
changeset
|
1022 |
super(CubicWebConfiguration, self).init_cubes(cubes) |
0 | 1023 |
# reload config file in cases options are defined in cubes __init__ |
1024 |
# or site_cubicweb files |
|
1025 |
self.load_file_configuration(self.main_config_file()) |
|
1026 |
# configuration initialization hook |
|
1027 |
self.load_configuration() |
|
1446 | 1028 |
|
0 | 1029 |
def add_cubes(self, cubes): |
1030 |
"""add given cubes to the list of used cubes""" |
|
1031 |
if not isinstance(cubes, list): |
|
1032 |
cubes = list(cubes) |
|
1033 |
self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
|
1446 | 1034 |
|
0 | 1035 |
def main_config_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1036 |
"""return instance's control configuration file""" |
0 | 1037 |
return join(self.apphome, '%s.conf' % self.name) |
1446 | 1038 |
|
0 | 1039 |
def save(self): |
1040 |
"""write down current configuration""" |
|
1041 |
self.generate_config(open(self.main_config_file(), 'w')) |
|
1042 |
||
5933
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1043 |
def check_writeable_uid_directory(self, path): |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1044 |
"""check given directory path exists, belongs to the user running the |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1045 |
server process and is writeable. |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1046 |
|
6135
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1047 |
If not, try to fix this, letting exception propagate when not possible. |
5933
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1048 |
""" |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1049 |
if not exists(path): |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1050 |
os.makedirs(path) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1051 |
if self['uid']: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1052 |
try: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1053 |
uid = int(self['uid']) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1054 |
except ValueError: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1055 |
from pwd import getpwnam |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1056 |
uid = getpwnam(self['uid']).pw_uid |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1057 |
else: |
6135
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1058 |
try: |
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1059 |
uid = os.getuid() |
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1060 |
except AttributeError: # we are on windows |
e4b37742f75a
[win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6087
diff
changeset
|
1061 |
return |
5933
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1062 |
fstat = os.stat(path) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1063 |
if fstat.st_uid != uid: |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1064 |
os.chown(path, uid, os.getgid()) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1065 |
import stat |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1066 |
if not (fstat.st_mode & stat.S_IWUSR): |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1067 |
os.chmod(path, fstat.st_mode | stat.S_IWUSR) |
3d707b8f8a4d
[web configuration] ensure data home directory / uicache file belong to daemon user and are writeable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5917
diff
changeset
|
1068 |
|
0 | 1069 |
@cached |
1070 |
def instance_md5_version(self): |
|
5885
5d908f1a7659
[config] use hashlib to avoid warning w/ py2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5817
diff
changeset
|
1071 |
import hashlib |
0 | 1072 |
infos = [] |
7264
9ed9e1d77ef3
[web config] fix md5 version to ensure cubes order and to include cubicweb version
Florent Cayré
parents:
7179
diff
changeset
|
1073 |
for pkg in sorted(self.cubes()): |
0 | 1074 |
version = self.cube_version(pkg) |
1075 |
infos.append('%s-%s' % (pkg, version)) |
|
7264
9ed9e1d77ef3
[web config] fix md5 version to ensure cubes order and to include cubicweb version
Florent Cayré
parents:
7179
diff
changeset
|
1076 |
infos.append('cubicweb-%s' % str(self.cubicweb_version())) |
5885
5d908f1a7659
[config] use hashlib to avoid warning w/ py2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5817
diff
changeset
|
1077 |
return hashlib.md5(';'.join(infos)).hexdigest() |
1446 | 1078 |
|
0 | 1079 |
def load_configuration(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1080 |
"""load instance's configuration files""" |
0 | 1081 |
super(CubicWebConfiguration, self).load_configuration() |
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7086
diff
changeset
|
1082 |
if self.apphome and not self.creating: |
0 | 1083 |
# 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
|
1084 |
self._gettext_init() |
1446 | 1085 |
|
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
|
1086 |
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
|
1087 |
# 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
|
1088 |
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
|
1089 |
if getattr(mod, 'options', None): |
5817
e4207221f3f5
[config] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5812
diff
changeset
|
1090 |
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
|
1091 |
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
|
1092 |
|
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
|
1093 |
def init_log(self, logthreshold=None, force=False): |
0 | 1094 |
"""init the log service""" |
1095 |
if not force and hasattr(self, '_logging_initialized'): |
|
1096 |
return |
|
1097 |
self._logging_initialized = True |
|
6748
52226299c352
[config] Use newstyle call to parent classe method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6741
diff
changeset
|
1098 |
super_self = super(CubicWebConfiguration, self) |
52226299c352
[config] Use newstyle call to parent classe method.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6741
diff
changeset
|
1099 |
super_self.init_log(logthreshold, logfile=self.get('log-file')) |
0 | 1100 |
# read a config file if it exists |
1101 |
logconfig = join(self.apphome, 'logging.conf') |
|
1102 |
if exists(logconfig): |
|
7178
a62f24e1497e
fileConfig is in logging.config
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7086
diff
changeset
|
1103 |
logging.config.fileConfig(logconfig) |
0 | 1104 |
|
1105 |
def available_languages(self, *args): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1106 |
"""return available translation for an instance, by looking for |
0 | 1107 |
compiled catalog |
1108 |
||
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4889
diff
changeset
|
1109 |
take \*args to be usable as a vocabulary method |
0 | 1110 |
""" |
1111 |
from glob import glob |
|
1112 |
yield 'en' # ensure 'en' is yielded even if no .mo found |
|
1113 |
for path in glob(join(self.apphome, 'i18n', |
|
3118 | 1114 |
'*', 'LC_MESSAGES')): |
1115 |
lang = path.split(os.sep)[-2] |
|
0 | 1116 |
if lang != 'en': |
1117 |
yield lang |
|
1446 | 1118 |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
1119 |
def _gettext_init(self): |
0 | 1120 |
"""set language for gettext""" |
1121 |
from gettext import translation |
|
1122 |
path = join(self.apphome, 'i18n') |
|
1123 |
for language in self.available_languages(): |
|
1124 |
self.info("loading language %s", language) |
|
1125 |
try: |
|
1126 |
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
|
1127 |
self.translations[language] = (tr.ugettext, tr.upgettext) |
0 | 1128 |
except (ImportError, AttributeError, IOError): |
1129 |
self.exception('localisation support error for language %s', |
|
1446 | 1130 |
language) |
1131 |
||
0 | 1132 |
def vregistry_path(self): |
1133 |
"""return a list of files or directories where the registry will look |
|
1134 |
for application objects |
|
1135 |
""" |
|
1136 |
templpath = list(reversed(self.cubes_path())) |
|
1137 |
if self.apphome: # may be unset in tests |
|
1138 |
templpath.append(self.apphome) |
|
1139 |
return self.build_vregistry_path(templpath) |
|
1140 |
||
1141 |
def set_sources_mode(self, sources): |
|
1142 |
if not 'all' in sources: |
|
1143 |
print 'warning: ignoring specified sources, requires a repository '\ |
|
1144 |
'configuration' |
|
1446 | 1145 |
|
0 | 1146 |
def migration_handler(self): |
1147 |
"""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
|
1148 |
from cubicweb.migration import MigrationHelper |
0 | 1149 |
return MigrationHelper(self, verbosity=self.verbosity) |
1150 |
||
1151 |
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
|
1152 |
from cubicweb import i18n |
0 | 1153 |
if langs is None: |
1154 |
langs = self.available_languages() |
|
1155 |
i18ndir = join(self.apphome, 'i18n') |
|
1156 |
if not exists(i18ndir): |
|
1157 |
create_dir(i18ndir) |
|
1158 |
sourcedirs = [join(path, 'i18n') for path in self.cubes_path()] |
|
1159 |
sourcedirs.append(self.i18n_lib_dir()) |
|
1160 |
return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs) |
|
1161 |
||
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1162 |
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
|
1163 |
"""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
|
1164 |
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
|
1165 |
""" |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1166 |
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
|
1167 |
SMTP_LOCK.acquire() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1168 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1169 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1170 |
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
|
1171 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1172 |
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
|
1173 |
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
|
1174 |
return False |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1175 |
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
|
1176 |
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
|
1177 |
try: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1178 |
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
|
1179 |
except Exception, ex: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1180 |
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
|
1181 |
recipients, ex) |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1182 |
smtp.close() |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1183 |
finally: |
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1184 |
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
|
1185 |
return True |
2221
d9b85a7b0bdd
create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2220
diff
changeset
|
1186 |
|
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7031
diff
changeset
|
1187 |
# these are overridden by set_log_methods below |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7031
diff
changeset
|
1188 |
# only defining here to prevent pylint from complaining |
7086
0d63937991a5
fix pylint helper methods: need a classmathod in cwconfig.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7083
diff
changeset
|
1189 |
@classmethod |
0d63937991a5
fix pylint helper methods: need a classmathod in cwconfig.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7083
diff
changeset
|
1190 |
def debug(cls, msg, *a, **kw): |
0d63937991a5
fix pylint helper methods: need a classmathod in cwconfig.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7083
diff
changeset
|
1191 |
pass |
0d63937991a5
fix pylint helper methods: need a classmathod in cwconfig.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7083
diff
changeset
|
1192 |
info = warning = error = critical = exception = debug |
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7031
diff
changeset
|
1193 |
|
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
|
1194 |
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
|
1195 |
logging.getLogger('cubicweb.configuration')) |
1446 | 1196 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
1197 |
# 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
|
1198 |
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
|
1199 |
application_configuration = deprecated('use instance_configuration')(instance_configuration) |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1200 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1201 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1202 |
_EXT_REGISTERED = False |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1203 |
def register_stored_procedures(): |
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
1204 |
from logilab.database import FunctionDescr |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1205 |
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
|
1206 |
from rql.nodes import SortTerm, Constant, VariableRef |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1207 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1208 |
global _EXT_REGISTERED |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1209 |
if _EXT_REGISTERED: |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1210 |
return |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1211 |
_EXT_REGISTERED = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1212 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1213 |
class COMMA_JOIN(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1214 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1215 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1216 |
|
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
|
1217 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1218 |
return ', '.join(sorted(term.get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1219 |
for term in iter_funcnode_variables(funcnode))) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1220 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1221 |
register_function(COMMA_JOIN) # XXX do not expose? |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1222 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1223 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1224 |
class CONCAT_STRINGS(COMMA_JOIN): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1225 |
aggregat = True |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1226 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1227 |
register_function(CONCAT_STRINGS) # XXX bw compat |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1228 |
|
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
|
1229 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1230 |
class GROUP_CONCAT(CONCAT_STRINGS): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1231 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1232 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1233 |
register_function(GROUP_CONCAT) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1234 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1235 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1236 |
class LIMIT_SIZE(FunctionDescr): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1237 |
supported_backends = ('postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1238 |
rtype = 'String' |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1239 |
|
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
|
1240 |
def st_description(self, funcnode, mainindex, tr): |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1241 |
return funcnode.children[0].get_description(mainindex, tr) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1242 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1243 |
register_function(LIMIT_SIZE) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1244 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1245 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1246 |
class TEXT_LIMIT_SIZE(LIMIT_SIZE): |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1247 |
supported_backends = ('mysql', 'postgres', 'sqlite',) |
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1248 |
|
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
1249 |
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
|
1250 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1251 |
|
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
|
1252 |
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
|
1253 |
"""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
|
1254 |
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
|
1255 |
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
|
1256 |
""" |
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
|
1257 |
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
|
1258 |
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
|
1259 |
|
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
|
1260 |
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
|
1261 |
"""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
|
1262 |
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
|
1263 |
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
|
1264 |
""" |
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
|
1265 |
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
|
1266 |
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
|
1267 |
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
|
1268 |
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
|
1269 |
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
|
1270 |
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
|
1271 |
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
|
1272 |
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
|
1273 |
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
|
1274 |
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
|
1275 |
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
|
1276 |
|
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
|
1277 |
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
|
1278 |
|
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
|
1279 |
|
4322
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1280 |
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
|
1281 |
"""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
|
1282 |
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
|
1283 |
""" |
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
|
1284 |
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
|
1285 |
|
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
|
1286 |
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
|
1287 |
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
|
1288 |
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
|
1289 |
|
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
|
1290 |
def as_sql(self, backend, args): |
6788
0f31ed3fff79
[bfss storage] Improve fspath() error message.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6779
diff
changeset
|
1291 |
raise NotImplementedError( |
0f31ed3fff79
[bfss storage] Improve fspath() error message.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6779
diff
changeset
|
1292 |
'This callback is only available for BytesFileSystemStorage ' |
0f31ed3fff79
[bfss storage] Improve fspath() error message.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6779
diff
changeset
|
1293 |
'managed attribute. Is FSPATH() argument BFSS managed?') |
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
|
1294 |
|
5630
40d7c7e180f1
[storage] source's callback has a new prototype, update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
1295 |
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
|
1296 |
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
|
1297 |
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
|
1298 |
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
|
1299 |
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
|
1300 |
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
|
1301 |
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
|
1302 |
|
f65743cc53e4
first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1303 |
register_function(FSPATH) |