cubicweb/cwconfig.py
author Guillaume Vandevelde <gvandevelde@logilab.fr>
Thu, 13 Feb 2020 13:56:12 +0100
branch3.26
changeset 12876 fe9bd0e937e4
parent 12719 9fb4a71f119d
child 12722 1a5eb9a9f5b4
permissions -rw-r--r--
[pkg] version 3.26.15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 -*-
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
     2
# copyright 2003-2016 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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    25
Standard resource mode
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    26
``````````````````````
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    27
6846
4dd1df437e15 [doc] fix typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6844
diff changeset
    28
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
    29
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
    30
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
    31
6397
66401ba9332a [book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6192
diff changeset
    32
* **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
    33
  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
    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
  - instances are stored in :file:`<INSTALL_PREFIX>/etc/cubicweb.d`
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    36
  - temporary files (such as pid file) in :file:`<INSTALL_PREFIX>/var/run/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
    37
f15286235aef [doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5086
diff changeset
    38
  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
    39
  instance).
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1446
diff changeset
    40
6397
66401ba9332a [book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6192
diff changeset
    41
* **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
    42
66401ba9332a [book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6192
diff changeset
    43
  - 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
    44
  - 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
    45
66401ba9332a [book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6192
diff changeset
    46
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    47
.. _CubicwebWithinVirtualEnv:
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    48
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    49
Within virtual environment
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    50
``````````````````````````
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    51
12435
af93bf9723b4 [doc] new behavior in virtualenv since 3.26
Laurent Peuch <cortex@worlddomination.be>
parents: 12273
diff changeset
    52
When installed within a virtualenv, CubicWeb will look for instances data as in
af93bf9723b4 [doc] new behavior in virtualenv since 3.26
Laurent Peuch <cortex@worlddomination.be>
parents: 12273
diff changeset
    53
user mode by default, that is in $HOME/etc/cubicweb.d. However the
af93bf9723b4 [doc] new behavior in virtualenv since 3.26
Laurent Peuch <cortex@worlddomination.be>
parents: 12273
diff changeset
    54
CW_INSTANCES_DIR environment variable should be preferably used.
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    55
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    56
.. _virtualenv: http://pypi.python.org/pypi/virtualenv
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    57
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    58
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    59
Custom resource location
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    60
````````````````````````
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    61
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
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
    63
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
    64
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
    65
6397
66401ba9332a [book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6192
diff changeset
    66
* **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
    67
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
    68
        CW_INSTANCES_DIR = <INSTALL_PREFIX>/etc/cubicweb.d/
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    69
        CW_INSTANCES_DATA_DIR = <INSTALL_PREFIX>/var/lib/cubicweb/instances/
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    70
        CW_RUNTIME_DIR = <INSTALL_PREFIX>/var/run/cubicweb/
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
    71
6397
66401ba9332a [book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6192
diff changeset
    72
* **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
    73
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
    74
        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
    75
        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
    76
        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
    77
6397
66401ba9332a [book] improve documentation lisibility for cwconfig chapter and fix some references
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6192
diff changeset
    78
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
    79
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    80
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    81
Setting Cubicweb Mode
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    82
`````````````````````
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    83
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    84
By default, the mode is set to 'system' for standard installation. The mode is
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    85
set to 'user' if `cubicweb is used from a mercurial repository`_. You can force
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    86
this by setting the :envvar:`CW_MODE` environment variable to either 'user' or
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    87
'system' so you can easily:
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
    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
* 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
    90
  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
    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
* 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
    93
  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
    94
f15286235aef [doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5086
diff changeset
    95
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
    96
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
    97
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    98
.. _`cubicweb is used from a mercurial repository`: CubicwebDevelopmentMod_
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
    99
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   100
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
   101
.. _CubicwebDevelopmentMod:
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
   102
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   103
Development Mode (source)
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   104
`````````````````````````
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   105
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   106
If :file:`.hg` directory is found into the cubicweb package, there are
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   107
specific resource rules.
8031
dcc2b6a517a0 Update documentation about resource mode.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7879
diff changeset
   108
11057
0b59724cb3f2 Reorganize source tree to have a "cubicweb" top-level package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11000
diff changeset
   109
`<CW_SOFTWARE_ROOT>` is the source checkout's ``cubicweb`` directory:
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
   110
11057
0b59724cb3f2 Reorganize source tree to have a "cubicweb" top-level package
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11000
diff changeset
   111
* main cubes directory is `<CW_SOFTWARE_ROOT>/../../cubes`. You can specify
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
   112
  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
   113
  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
   114
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
* 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
   116
  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
   117
f15286235aef [doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5086
diff changeset
   118
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   119
Development Mode (virtualenv)
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   120
`````````````````````````````
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   121
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   122
If a virtualenv is found to be activated (i.e. a VIRTUAL_ENV variable is found
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   123
in environment), the virtualenv root is used as `<INSTALL_PREFIX>`. This, in
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   124
particular, makes it possible to work in `setuptools development mode`_
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   125
(``python setup.py develop``) without any further configuration.
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   126
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   127
.. _`setuptools development mode`: https://pythonhosted.org/setuptools/setuptools.html#development-mode
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   128
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
   129
.. _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
   130
f15286235aef [doc] enhanced setup section: fix sections'level, more postgres tips, merge environment doc with cwconfig.py module docstring using custom autodocstring directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5086
diff changeset
   131
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
   132
-------------------------
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
   133
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
   134
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
   135
``````
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
   136
9917
a98e60464c26 [book] stop talking about the hg `forest` extension
Julien Cristau <julien.cristau@logilab.fr>
parents: 9792
diff changeset
   137
If you installed *CubicWeb* by cloning the Mercurial shell repository 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
   138
distribution, then you will need to update the environment variable PYTHONPATH by
9917
a98e60464c26 [book] stop talking about the hg `forest` extension
Julien Cristau <julien.cristau@logilab.fr>
parents: 9792
diff changeset
   139
adding the path to `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
   140
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
   141
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
   142
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
   143
9917
a98e60464c26 [book] stop talking about the hg `forest` extension
Julien Cristau <julien.cristau@logilab.fr>
parents: 9792
diff changeset
   144
    export PYTHONPATH=/full/path/to/grshell-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
   145
5264
57ac406d1d82 fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5198
diff changeset
   146
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
   147
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
   148
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
   149
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
   150
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
   151
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
   152
````````
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
   153
5264
57ac406d1d82 fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5198
diff changeset
   154
Here are all environment variables that may be used to configure *CubicWeb*:
3639
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   155
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   156
.. 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
   157
5264
57ac406d1d82 fix the dosctring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5198
diff changeset
   158
   Resource mode: user or system, as explained in :ref:`ResourceMode`.
3639
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   159
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1446
diff changeset
   160
.. 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
   161
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
   162
   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
   163
   directories using ':' as separator (';' under windows environment).
3639
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   164
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   165
.. 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
   166
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
   167
   Directory where cubicweb instances will be found.
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1446
diff changeset
   168
3639
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   169
.. 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
   170
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
   171
   Directory where cubicweb instances data will be written (backup file...)
3639
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   172
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   173
.. 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
   174
3639
0835e5127f36 more doc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   175
   Directory where pid files will be written
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
"""
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   177
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10568
diff changeset
   178
from __future__ import print_function
5885
5d908f1a7659 [config] use hashlib to avoid warning w/ py2.6
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5817
diff changeset
   179
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   180
import importlib
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
import logging
7178
a62f24e1497e fileConfig is in logging.config
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7086
diff changeset
   182
import logging.config
11458
db2d627e379e [cwconfig] Reorder imports by alphabetic order
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11457
diff changeset
   183
import os
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   184
from os.path import (exists, join, expanduser, abspath, normpath,
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   185
                     basename, isdir, dirname, splitext, realpath)
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   186
import pkgutil
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   187
import pkg_resources
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   188
import re
11458
db2d627e379e [cwconfig] Reorder imports by alphabetic order
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11457
diff changeset
   189
from smtplib import SMTP
db2d627e379e [cwconfig] Reorder imports by alphabetic order
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11457
diff changeset
   190
import stat
db2d627e379e [cwconfig] Reorder imports by alphabetic order
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11457
diff changeset
   191
import sys
db2d627e379e [cwconfig] Reorder imports by alphabetic order
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11457
diff changeset
   192
from threading import Lock
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   193
from warnings import filterwarnings
7822
ce8a4de2ecf1 [warnings] explicitly ask to show DeprecationWarning in debug mode (closes #1942760)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   194
12719
9fb4a71f119d [py3] Pass bytes as "msg" to smtplib.SMTP.sendmail()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12659
diff changeset
   195
from six import PY2, text_type
10622
3cc6154b94a3 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
   196
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
   197
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
   198
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
   199
from logilab.common.logging_ext import set_log_methods, init_log
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
from logilab.common.configuration import (Configuration, Method,
11859
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   201
                                          ConfigurationMixIn, merge_options,
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   202
                                          _validate as lgc_validate)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
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
   204
from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP,
10666
7f6b5f023884 [py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10662
diff changeset
   205
                      ConfigurationError, Binary, _)
11476
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   206
from cubicweb.toolsutils import create_dir, option_value_from_env
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
CONFIGURATIONS = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
   210
SMTP_LOCK = Lock()
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
   211
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
def configuration_cls(name):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
    """return the configuration class registered with the given name"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
        return [c for c in CONFIGURATIONS if c.name == name][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
    except IndexError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
        raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   220
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
def possible_configurations(directory):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
    """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
   223
    according to \*-ctl files
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
    """
12053
c3c9f2e1424c [pyramid] Add a "pyramid" instance configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12015
diff changeset
   225
    return [name for name in ('repository', 'all-in-one', 'pyramid')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
            if exists(join(directory, '%s.conf' % name))]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   228
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
def guess_configuration(directory):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
    """try to guess the configuration to use for a directory. If multiple
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
    configurations are found, ConfigurationError is raised
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
    modes = possible_configurations(directory)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
    if len(modes) != 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
        raise ConfigurationError('unable to guess configuration from %r %s'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
                                 % (directory, modes))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
    return modes[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   239
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   240
def _cube_pkgname(cube):
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   241
    if not cube.startswith('cubicweb_'):
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   242
        return 'cubicweb_' + cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   243
    return cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   244
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   245
12078
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   246
def _cube_modname(cube):
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   247
    modname = _cube_pkgname(cube)
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   248
    loader = pkgutil.find_loader(modname)
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   249
    if loader:
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   250
        return modname
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   251
    else:
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   252
        return 'cubes.' + cube
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   253
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   254
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   255
def _expand_modname(modname, recursive=True):
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   256
    """expand modules names `modname` if exists by recursively walking
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   257
    submodules and subpackages and yield (submodname, filepath) including
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   258
    `modname` itself
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   259
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   260
    If the file ends with .pyc or .pyo (python bytecode) also check that the
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   261
    corresponding source .py file exists before yielding.
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   262
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   263
    If `recursive` is False skip subpackages.
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   264
    """
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   265
    try:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   266
        loader = pkgutil.find_loader(modname)
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   267
    except ImportError:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   268
        return
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   269
    if not loader:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   270
        return
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   271
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   272
    def check_source_file(filepath):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   273
        if filepath[-4:] in ('.pyc', '.pyo'):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   274
            if not exists(filepath[:-1]):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   275
                return False
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   276
        return True
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   277
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   278
    filepath = loader.get_filename()
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   279
    if not check_source_file(filepath):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   280
        return
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   281
    yield modname, filepath
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   282
    if loader.is_package(modname):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   283
        path = dirname(filepath)
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   284
        for subloader, subname, ispkg in pkgutil.walk_packages([path]):
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   285
            submodname = '.'.join([modname, subname])
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   286
            if not ispkg:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   287
                filepath = subloader.find_module(subname).get_filename()
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   288
                if check_source_file(filepath):
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   289
                    yield submodname, filepath
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   290
            elif recursive:
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   291
                for x in _expand_modname(submodname, recursive=True):
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   292
                    yield x
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   293
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   294
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
# persistent options definition
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
PERSISTENT_OPTIONS = (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
    ('encoding',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
      'default': 'UTF-8',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
      'help': _('user interface encoding'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
      'group': 'ui', 'sitewide': True,
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   302
      }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
    ('language',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
      'default': 'en',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
      'vocabulary': Method('available_languages'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
      'help': _('language of the user interface'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   308
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
    ('date-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
      'default': '%Y/%m/%d',
8114
8311cc3b472a Link to python docs about strftime instead of pointing at "man" (closes #2106415)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8049
diff changeset
   313
      'help': _('how to format date in the ui (see <a href="http://docs.python.org/library/datetime.html#strftime-strptime-behavior">this page</a> for format description)'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   314
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
    ('datetime-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
      'default': '%Y/%m/%d %H:%M',
8114
8311cc3b472a Link to python docs about strftime instead of pointing at "man" (closes #2106415)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8049
diff changeset
   319
      'help': _('how to format date and time in the ui (see <a href="http://docs.python.org/library/datetime.html#strftime-strptime-behavior">this page</a> for format description)'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   320
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
    ('time-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
      'default': '%H:%M',
8114
8311cc3b472a Link to python docs about strftime instead of pointing at "man" (closes #2106415)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8049
diff changeset
   325
      'help': _('how to format time in the ui (see <a href="http://docs.python.org/library/datetime.html#strftime-strptime-behavior">this page</a> for format description)'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   326
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
    ('float-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
      'default': '%.3f',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
      'help': _('how to format float numbers in the ui'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   332
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
    ('default-text-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
     {'type' : 'choice',
10012
8c2c6fdd8d56 [RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents: 9990
diff changeset
   336
      'choices': ('text/plain', 'text/rest', 'text/html', 'text/markdown'),
10273
ef74abcf369d [config] disable fckeditor by default (closes #1368900)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10084
diff changeset
   337
      'default': 'text/plain',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
      'help': _('default text format for rich text fields.'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   339
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
    ('short-line-size',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
     {'type' : 'int',
5391
fe3fe2b2b60a [config] augment default value for short-line-size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5264
diff changeset
   343
      'default': 80,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
      'help': _('maximum number of characters in short description'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
      'group': 'navigation',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
    )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   348
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
def register_persistent_options(options):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
    global PERSISTENT_OPTIONS
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   351
    PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   352
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
CFGTYPE2ETYPE_MAP = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
    'string': 'String',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
    'choice': 'String',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
    'yn':     'Boolean',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
    'int':    'Int',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
    'float' : 'Float',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   359
    }
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   360
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
   361
12273
9d08f89a3d85 [cwconfig] Always use "sys.prefix" to determine installation prefix
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12272
diff changeset
   362
_INSTALL_PREFIX = os.environ.get('CW_INSTALL_PREFIX', sys.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
   363
_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
   364
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
class CubicWebNoAppConfiguration(ConfigurationMixIn):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
    """base class for cubicweb configuration without a specific instance directory
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
    # to set in concrete configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
    name = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
    # log messages format (see logging module documentation for available keys)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
    log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s'
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   372
    # the format below can be useful to debug multi thread issues:
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   373
    # 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
   374
    # nor remove appobjects based on unused interface [???]
9258
4e79f587c6ab Rename cleanup_interface_sobjects into cleanup_unused_appobjects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9257
diff changeset
   375
    cleanup_unused_appobjects = True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
10084
eb3681e13ed9 [config] kill a getattr
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10012
diff changeset
   377
    quick_start = False
eb3681e13ed9 [config] kill a getattr
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10012
diff changeset
   378
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   379
    if 'VIRTUAL_ENV' in os.environ:
12266
043db1f91922 [cwconfig] Get rid of _forced_mode global
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12265
diff changeset
   380
        mode = os.environ.get('CW_MODE', 'user')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
    else:
12266
043db1f91922 [cwconfig] Get rid of _forced_mode global
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12265
diff changeset
   382
        mode = os.environ.get('CW_MODE', 'system')
043db1f91922 [cwconfig] Get rid of _forced_mode global
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12265
diff changeset
   383
    assert mode in ('system', 'user'), '"CW_MODE" should be either "user" or "system"'
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   384
12273
9d08f89a3d85 [cwconfig] Always use "sys.prefix" to determine installation prefix
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12272
diff changeset
   385
    _CUBES_DIR = join(_INSTALL_PREFIX, 'share', 'cubicweb', 'cubes')
9d08f89a3d85 [cwconfig] Always use "sys.prefix" to determine installation prefix
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12272
diff changeset
   386
    assert _CUBES_DIR  # XXX only meaningful if CW_CUBES_DIR is not set
11881
6707748e3982 [cwconfig] Retrieve real path of cubes directory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11859
diff changeset
   387
    CUBES_DIR = realpath(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
   388
    CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
1046
52ee022d87e3 simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents: 819
diff changeset
   390
    options = (
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
       ('log-threshold',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
         {'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
   393
          'default': 'WARNING',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   394
          '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
   395
          'group': 'main', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
          }),
6779
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   397
        ('umask',
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   398
         {'type' : 'int',
10591
8e46ed1a0b8a [py3k] octals and long
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10589
diff changeset
   399
          'default': 0o077,
6779
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   400
          '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
   401
          'group': 'main', 'level': 2,
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   402
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
        # common configuration options which are potentially required as soon as
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
        # you're using "base" application objects (ie to really server/web
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
        # specific)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   406
        ('base-url',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
          'default': None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
          '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
   410
          'group': 'main', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
          }),
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
   412
        ('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
   413
         {'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
   414
          '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
   415
          '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
   416
          '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
   417
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
        ('mangle-emails',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
         {'type' : 'yn',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
          'default': False,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   421
          'help': "don't display actual email addresses but mangle them if \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   422
this option is set to yes",
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   423
          'group': 'email', 'level': 3,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   425
        )
11476
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   426
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   427
    def __getitem__(self, key):
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   428
        """Get configuration option, by first looking at environmnent."""
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   429
        file_value = super(CubicWebNoAppConfiguration, self).__getitem__(key)
11859
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   430
        value = option_value_from_env(key, file_value)
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   431
        if value is not None:
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   432
            option_def = self.get_option_def(key)
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   433
            value = lgc_validate(value, option_def)
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   434
        return value
11476
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   435
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   436
    # static and class methods used to get instance independant resources ##
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
    @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
    def cubicweb_version():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
        """return installed cubicweb version"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   440
        from logilab.common.changelog import Version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   441
        from cubicweb import __pkginfo__
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
        version = __pkginfo__.numversion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
        assert len(version) == 3, version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   444
        return Version(version)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   445
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   446
    @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
    def persistent_options_configuration():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   448
        return Configuration(options=PERSISTENT_OPTIONS)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   449
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   451
    def i18n_lib_dir(cls):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   452
        """return instance's i18n directory"""
12268
d84bc85f7f70 [config] Avoid relying on shared_dir method when possible
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12266
diff changeset
   453
        return join(dirname(__file__), 'i18n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
    @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
   456
    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
   457
        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
   458
            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
   459
                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
   460
48f468f33704 [config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6748
diff changeset
   461
48f468f33704 [config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6748
diff changeset
   462
    @classmethod
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   463
    def available_cubes(cls):
12116
3522b19f35d6 [cwconfig] Add a docstring on available_cubes method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12115
diff changeset
   464
        """Return a list of available cube names.
3522b19f35d6 [cwconfig] Add a docstring on available_cubes method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12115
diff changeset
   465
3522b19f35d6 [cwconfig] Add a docstring on available_cubes method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12115
diff changeset
   466
        For cube as package, name is equal to python package's name.
3522b19f35d6 [cwconfig] Add a docstring on available_cubes method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12115
diff changeset
   467
        """
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   468
        cubes = set()
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   469
        for entry_point in pkg_resources.iter_entry_points(
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   470
                group='cubicweb.cubes', name=None):
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   471
            try:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   472
                module = entry_point.load()
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   473
            except ImportError:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   474
                continue
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   475
            else:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   476
                modname = module.__name__
12115
8d0127498a28 Backed out changeset fe995d56c949
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12109
diff changeset
   477
                if not modname.startswith('cubicweb_'):
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   478
                    cls.warning('entry point %s does not appear to be a cube',
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   479
                                entry_point)
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   480
                    continue
12115
8d0127498a28 Backed out changeset fe995d56c949
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12109
diff changeset
   481
                cubes.add(modname)
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   482
        # Legacy cubes.
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   483
        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
   484
            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
   485
                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
   486
                          % directory)
4001
bc31ede2085d dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3915
diff changeset
   487
                continue
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   488
            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
   489
                if cube == 'shared':
5026
1f8238eaec9b [config] more cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5025
diff changeset
   490
                    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
   491
                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
   492
                    continue # skip invalid python package name
11711
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   493
                if cube == 'pyramid':
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   494
                    cls._warn_pyramid_cube()
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   495
                    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
   496
                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
   497
                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
   498
                    cubes.add(cube)
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   499
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   500
        def sortkey(cube):
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   501
            """Preserve sorting with "cubicweb_" prefix."""
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   502
            prefix = 'cubicweb_'
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   503
            if cube.startswith(prefix):
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   504
                # add a suffix to have a deterministic sorting between
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   505
                # 'cubicweb_<cube>' and '<cube>' (useful in tests with "hash
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   506
                # randomization" turned on).
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   507
                return cube[len(prefix):] + '~'
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   508
            return cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   509
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   510
        return sorted(cubes, key=sortkey)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   511
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   512
    @classmethod
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   513
    def cubes_search_path(cls):
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   514
        """return the path of directories where cubes should be searched"""
11881
6707748e3982 [cwconfig] Retrieve real path of cubes directory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11859
diff changeset
   515
        path = [realpath(abspath(normpath(directory))) for directory in cls.CUBES_PATH
5049
1b5c873029a1 take care to empty string in cubes search path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5048
diff changeset
   516
                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
   517
        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
   518
            path.append(cls.CUBES_DIR)
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   519
        return path
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   520
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
   521
    @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
   522
    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
   523
        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
   524
        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
   525
            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
   526
                extrapath[cubesdir] = 'cubes'
4325
16642cc7d497 oops, missing return
syt@www.fleurdetomate.fr
parents: 4324
diff changeset
   527
        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
   528
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   529
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   530
    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
   531
        """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
   532
        `ConfigurationError` if it doesn't exist
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   533
        """
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   534
        pkgname = _cube_pkgname(cube)
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   535
        loader = pkgutil.find_loader(pkgname)
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   536
        if loader:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   537
            return dirname(loader.get_filename())
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   538
        # Legacy cubes.
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   539
        for directory in cls.cubes_search_path():
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   540
            cubedir = join(directory, cube)
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   541
            if exists(cubedir):
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   542
                return cubedir
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   543
        msg = 'no module %(pkg)s in search path nor cube %(cube)r in %(path)s'
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   544
        raise ConfigurationError(msg % {'cube': cube,
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   545
                                        'pkg': _cube_pkgname(cube),
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   546
                                        'path': cls.cubes_search_path()})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   547
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   548
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   549
    def cube_migration_scripts_dir(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   550
        """cube migration scripts directory"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   551
        return join(cls.cube_dir(cube), 'migration')
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   552
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   553
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   554
    def cube_pkginfo(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   555
        """return the information module for the given cube"""
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   556
        pkgname = _cube_pkgname(cube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   557
        try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   558
            return importlib.import_module('%s.__pkginfo__' % pkgname)
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   559
        except ImportError:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   560
            cube = CW_MIGRATION_MAP.get(cube, cube)
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   561
            try:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   562
                parent = __import__('cubes.%s.__pkginfo__' % cube)
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   563
                return getattr(parent, cube).__pkginfo__
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   564
            except Exception as ex:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   565
                raise ConfigurationError(
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   566
                    'unable to find packaging information for cube %s (%s: %s)'
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   567
                    % (cube, ex.__class__.__name__, ex))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   568
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   569
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   570
    def cube_version(cls, cube):
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   571
        """return the version of the cube located in the given directory
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   572
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   573
        from logilab.common.changelog import Version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   574
        version = cls.cube_pkginfo(cube).numversion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   575
        assert len(version) == 3, version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   576
        return Version(version)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   577
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   578
    @classmethod
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   579
    def _cube_deps(cls, cube, key, oldkey):
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   580
        """return cubicweb cubes used by the given cube"""
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   581
        pkginfo = cls.cube_pkginfo(cube)
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   582
        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
   583
            # explicit __xxx_cubes__ attribute
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   584
            deps = getattr(pkginfo, key)
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   585
        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
   586
            # 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
   587
            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
   588
                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
   589
            except AttributeError:
9255
46f41c3e1443 remove 3.8 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9251
diff changeset
   590
                deps = {}
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   591
            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
   592
                deps = dict( (x[len('cubicweb-'):], v)
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10622
diff changeset
   593
                             for x, v in gendeps.items()
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
   594
                             if x.startswith('cubicweb-'))
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
   595
        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
   596
            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
   597
                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
   598
            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
   599
                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
   600
            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
   601
                deps[newname] = deps.pop(depcube)
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   602
        return deps
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   603
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   604
    @classmethod
6659
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   605
    def cube_depends_cubicweb_version(cls, cube):
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   606
        # 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
   607
        try:
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   608
            pkginfo = cls.cube_pkginfo(cube)
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   609
            deps = getattr(pkginfo, '__depends__')
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   610
            return deps.get('cubicweb')
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   611
        except AttributeError:
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   612
            return None
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   613
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   614
    @classmethod
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   615
    def cube_dependencies(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   616
        """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
   617
        return cls._cube_deps(cube, '__depends_cubes__', '__use__')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   618
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   619
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   620
    def cube_recommends(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   621
        """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
   622
        return cls._cube_deps(cube, '__recommends_cubes__', '__recommend__')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   623
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   624
    @classmethod
2762
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   625
    def expand_cubes(cls, cubes, with_recommends=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   626
        """expand the given list of top level cubes used by adding recursivly
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   627
        each cube dependencies
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   628
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   629
        cubes = list(cubes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   630
        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
   631
        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
   632
            available = set(cls.available_cubes())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   633
        while todo:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   634
            cube = todo.pop(0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   635
            for depcube in cls.cube_dependencies(cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   636
                if depcube not in cubes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   637
                    cubes.append(depcube)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   638
                    todo.append(depcube)
2762
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   639
            if with_recommends:
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   640
                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
   641
                    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
   642
                        cubes.append(depcube)
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   643
                        todo.append(depcube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   644
        return cubes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   645
9669
283503f58400 [cwconfig] Remove useless 'ui-cube' configuration option (closes #3728904)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9363
diff changeset
   646
    @classmethod
283503f58400 [cwconfig] Remove useless 'ui-cube' configuration option (closes #3728904)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9363
diff changeset
   647
    def reorder_cubes(cls, cubes):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   648
        """reorder cubes from the top level cubes to inner dependencies
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   649
        cubes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   650
        """
5322
c0b7687bce3d [config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5298
diff changeset
   651
        from logilab.common.graph import ordered_nodes, UnorderableGraph
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   652
        graph = {}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   653
        for cube in cubes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   654
            cube = CW_MIGRATION_MAP.get(cube, cube)
9669
283503f58400 [cwconfig] Remove useless 'ui-cube' configuration option (closes #3728904)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9363
diff changeset
   655
            graph[cube] = set(dep for dep in cls.cube_dependencies(cube)
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   656
                              if dep in cubes)
9669
283503f58400 [cwconfig] Remove useless 'ui-cube' configuration option (closes #3728904)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9363
diff changeset
   657
            graph[cube] |= set(dep for dep in cls.cube_recommends(cube)
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   658
                               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
   659
        try:
c0b7687bce3d [config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5298
diff changeset
   660
            return ordered_nodes(graph)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
   661
        except UnorderableGraph as ex:
8733
bdc50659f648 [cwconfig] Fix exception handling when building the cube dependency graph
Rémi Cardona <remi.cardona@logilab.fr>
parents: 8695
diff changeset
   662
            raise ConfigurationError(ex)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   663
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   664
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   665
    def cls_adjust_sys_path(cls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   666
        """update python path if necessary"""
11457
d404fd8499dd Add an import redirect hook from "cubes.<name>" to "cubicweb_<name>"
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11211
diff changeset
   667
        from cubicweb import _CubesImporter
d404fd8499dd Add an import redirect hook from "cubes.<name>" to "cubicweb_<name>"
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11211
diff changeset
   668
        _CubesImporter.install()
11920
f13799fbcfea [cwconfig] create a virtual "cubes" package
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11918
diff changeset
   669
        import cubes
f13799fbcfea [cwconfig] create a virtual "cubes" package
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11918
diff changeset
   670
        cubes.__path__ = cls.cubes_search_path()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   671
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   672
    @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
   673
    def load_available_configs(cls):
11210
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   674
        for confmod in ('web.webconfig',  'etwist.twconfig',
12053
c3c9f2e1424c [pyramid] Add a "pyramid" instance configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12015
diff changeset
   675
                        'server.serverconfig', 'pyramid.config'):
11210
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   676
            try:
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   677
                __import__('cubicweb.%s' % confmod)
11990
18aafce99b49 [cwconfig] Fix two NameError in load_available_configs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11983
diff changeset
   678
            except ImportError as exc:
11974
d92d75b17a85 [cwconfig] Issue a warning if a configuration module cannot be loaded
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11966
diff changeset
   679
                cls.warning('failed to load config module %s (%s)',
11990
18aafce99b49 [cwconfig] Fix two NameError in load_available_configs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11983
diff changeset
   680
                            confmod, exc)
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
   681
f45f42256905 [config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6846
diff changeset
   682
    @classmethod
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   683
    def load_cwctl_plugins(cls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   684
        cls.cls_adjust_sys_path()
11210
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   685
        for ctlmod in ('web.webctl',  'etwist.twctl', 'server.serverctl',
11681
b23d58050076 Merge cubicweb-pyramid cube
Yann Voté <yann.vote@logilab.fr>
parents: 11476
diff changeset
   686
                       'devtools.devctl', 'pyramid.pyramidctl'):
11210
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   687
            try:
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   688
                __import__('cubicweb.%s' % ctlmod)
11944
5284fee68601 [cwconfig] Issue a warning when a "core" ctl plugin failed to load
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11929
diff changeset
   689
            except ImportError as exc:
5284fee68601 [cwconfig] Issue a warning when a "core" ctl plugin failed to load
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11929
diff changeset
   690
                cls.warning('failed to load cubicweb-ctl plugin %s (%s)',
5284fee68601 [cwconfig] Issue a warning when a "core" ctl plugin failed to load
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11929
diff changeset
   691
                            ctlmod, exc)
11210
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   692
                continue
c582542d3cc1 [cwconfig] Stop using lgc.modutils to load *config.py and *ctl.py files
Rémi Cardona <remi.cardona@logilab.fr>
parents: 11209
diff changeset
   693
            cls.info('loaded cubicweb-ctl plugin %s', ctlmod)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   694
        for cube in cls.available_cubes():
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   695
            cubedir = cls.cube_dir(cube)
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   696
            pluginfile = join(cubedir, 'ccplugin.py')
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   697
            initfile = join(cubedir, '__init__.py')
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   698
            if cube.startswith('cubicweb_'):
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   699
                pkgname = cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   700
            else:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   701
                pkgname = 'cubes.%s' % cube
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   702
            if exists(pluginfile):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   703
                try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   704
                    __import__(pkgname + '.ccplugin')
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
   705
                    cls.info('loaded cubicweb-ctl plugin from %s', cube)
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7691
diff changeset
   706
                except Exception:
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
   707
                    cls.exception('while loading plugin %s', pluginfile)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   708
            elif exists(initfile):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   709
                try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   710
                    __import__(pkgname)
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7691
diff changeset
   711
                except Exception:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   712
                    cls.exception('while loading cube %s', cube)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   713
            else:
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   714
                cls.warning('no __init__ file in cube %s', cube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   715
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2654
diff changeset
   716
    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
   717
    cube_appobject_path = set(['entities'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   718
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
   719
    def __init__(self, debugmode=False):
7822
ce8a4de2ecf1 [warnings] explicitly ask to show DeprecationWarning in debug mode (closes #1942760)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   720
        if debugmode:
ce8a4de2ecf1 [warnings] explicitly ask to show DeprecationWarning in debug mode (closes #1942760)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   721
            # in python 2.7, DeprecationWarning are not shown anymore by default
ce8a4de2ecf1 [warnings] explicitly ask to show DeprecationWarning in debug mode (closes #1942760)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
   722
            filterwarnings('default', category=DeprecationWarning)
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
   723
        register_stored_procedures()
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   724
        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
   725
        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
   726
        self.debugmode = debugmode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   727
        self.adjust_sys_path()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   728
        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
   729
        # will be properly initialized later by _gettext_init
10622
3cc6154b94a3 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
   730
        self.translations = {'en': (text_type, lambda ctx, msgid: text_type(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
   731
        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
   732
        # 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
   733
        # 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
   734
        # 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
   735
        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
   736
            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
   737
        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
   738
            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
   739
        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
   740
            cw_rest_init()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   741
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   742
    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
   743
        # overriden in CubicWebConfiguration
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   744
        self.cls_adjust_sys_path()
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   745
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
   746
    def init_log(self, logthreshold=None, logfile=None, syslog=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   747
        """init the log service"""
180
8bcebdb5f55d code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 140
diff changeset
   748
        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
   749
            if self.debugmode:
180
8bcebdb5f55d code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 140
diff changeset
   750
                logthreshold = 'DEBUG'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   751
            else:
180
8bcebdb5f55d code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 140
diff changeset
   752
                logthreshold = self['log-threshold']
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   753
        if sys.platform == 'win32':
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   754
            # no logrotate on win32, so use logging rotation facilities
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   755
            # 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
   756
            # idea: make this configurable?
5655
ef903fff826d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5633 5647
diff changeset
   757
            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
   758
                     rotation_parameters={'when': 'W6', # every sunday
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   759
                                          '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
   760
                                          'backupCount': 52})
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   761
        else:
5655
ef903fff826d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5633 5647
diff changeset
   762
            init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   763
        # configure simpleTal logger
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   764
        logging.getLogger('simpleTAL').setLevel(logging.ERROR)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   765
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   766
    def schema_modnames(self):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   767
        modnames = []
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   768
        for name in ('bootstrap', 'base', 'workflow', 'Bookmark'):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   769
            modnames.append(('cubicweb', 'cubicweb.schemas.' + name))
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   770
        for cube in reversed(self.cubes()):
12078
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   771
            for modname, filepath in _expand_modname(
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   772
                    '{0}.schema'.format(_cube_modname(cube)),
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   773
                    recursive=False):
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   774
                modnames.append((cube, modname))
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   775
        if self.apphome:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   776
            apphome = realpath(self.apphome)
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   777
            for modname, filepath in _expand_modname(
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   778
                    'schema', recursive=False):
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   779
                if realpath(filepath).startswith(apphome):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   780
                    modnames.append(('data', modname))
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   781
        return modnames
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   782
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
   783
    def appobjects_modnames(self):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
   784
        """return a list of modules where the registry will look for
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
   785
        application objects. By default return nothing in NoApp config.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   786
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   787
        return []
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   788
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
   789
    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
   790
11209
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   791
    def load_site_cubicweb(self, cubes=()):
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   792
        """load site_cubicweb file for `cubes`"""
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   793
        for cube in reversed(cubes or self.cubes()):
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   794
            if cube in self._site_loaded:
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   795
                continue
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   796
            try:
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   797
                self._load_site_cubicweb(cube)
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   798
                self._site_loaded.add(cube)
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   799
            except ImportError:
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   800
                continue
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   801
        if self.apphome is not None:
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   802
            # Would occur, e.g., upon `cubicweb-ctl i18ncube <cube>`.
11211
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   803
            self._load_site_cubicweb(None)
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
   804
11209
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
   805
    def _load_site_cubicweb(self, cube):
11211
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   806
        """Load site_cubicweb.py from `cube` (or apphome if cube is None)."""
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   807
        if cube is not None:
11793
b455460630a0 [config] fix the load_site_cubicweb() method for to 'new-style' cubes (closes #16059402)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
   808
            try:
b455460630a0 [config] fix the load_site_cubicweb() method for to 'new-style' cubes (closes #16059402)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
   809
                modname = 'cubicweb_%s' % cube
b455460630a0 [config] fix the load_site_cubicweb() method for to 'new-style' cubes (closes #16059402)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
   810
                __import__(modname)
b455460630a0 [config] fix the load_site_cubicweb() method for to 'new-style' cubes (closes #16059402)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
   811
            except ImportError:
b455460630a0 [config] fix the load_site_cubicweb() method for to 'new-style' cubes (closes #16059402)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
   812
                modname = 'cubes.%s' % cube
b455460630a0 [config] fix the load_site_cubicweb() method for to 'new-style' cubes (closes #16059402)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
   813
                __import__(modname)
b455460630a0 [config] fix the load_site_cubicweb() method for to 'new-style' cubes (closes #16059402)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
   814
            modname = modname + '.site_cubicweb'
11211
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   815
            __import__(modname)
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   816
            return sys.modules[modname]
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   817
        else:
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   818
            import imp
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   819
            apphome_site = join(self.apphome, 'site_cubicweb.py')
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   820
            if exists(apphome_site):
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   821
                with open(apphome_site, 'rb') as f:
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
   822
                    return imp.load_source('site_cubicweb', apphome_site, f)
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
   823
7031
a04621040cad [config refactoring] rename eproperty_definition method to cwproperty_definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7005
diff changeset
   824
    def cwproperty_definitions(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   825
        cfg = self.persistent_options_configuration()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   826
        for section, options in cfg.options_by_section():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   827
            section = section.lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   828
            for optname, optdict, value in options:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   829
                key = '%s.%s' % (section, optname)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   830
                type, vocab = self.map_option(optdict)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   831
                default = cfg.option_default(optname, optdict)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   832
                pdef = {'type': type, 'vocabulary': vocab, 'default': default,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   833
                        'help': optdict['help'],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   834
                        'sitewide': optdict.get('sitewide', False)}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   835
                yield key, pdef
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   836
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   837
    def map_option(self, optdict):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   838
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   839
            vocab = optdict['choices']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   840
        except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   841
            vocab = optdict.get('vocabulary')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   842
            if isinstance(vocab, Method):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   843
                vocab = getattr(self, vocab.method, ())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   844
        return CFGTYPE2ETYPE_MAP[optdict['type']], vocab
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   845
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
   846
    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
   847
        """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
   848
        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
   849
        """
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
   850
        return None
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   851
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   852
    _cubes = None
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   853
11711
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   854
    @classmethod
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   855
    def _warn_pyramid_cube(cls):
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   856
        cls.warning("cubicweb-pyramid got integrated into CubicWeb; "
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   857
                    "remove it from your project's dependencies")
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   858
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   859
    def init_cubes(self, cubes):
11710
dd5df5fe7137 [config] Exclude "pyramid" cube when initializing application cubes
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11681
diff changeset
   860
        cubes = list(cubes)
dd5df5fe7137 [config] Exclude "pyramid" cube when initializing application cubes
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11681
diff changeset
   861
        if 'pyramid' in cubes:
11711
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   862
            self._warn_pyramid_cube()
11710
dd5df5fe7137 [config] Exclude "pyramid" cube when initializing application cubes
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11681
diff changeset
   863
            cubes.remove('pyramid')
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   864
        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
   865
        # 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
   866
        for cube in cubes:
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   867
            try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   868
                importlib.import_module(_cube_pkgname(cube))
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   869
            except ImportError:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   870
                # Legacy cube.
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   871
                __import__('cubes.%s' % cube)
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   872
        self.load_site_cubicweb()
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   873
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   874
    def cubes(self):
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   875
        """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
   876
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   877
        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
   878
        cubes
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   879
        """
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   880
        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
   881
        return self._cubes
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   882
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   883
    def cubes_path(self):
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   884
        """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
   885
        most to inner most cubes
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   886
        """
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   887
        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
   888
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   889
    # these are overridden by set_log_methods below
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   890
    # only defining here to prevent pylint from complaining
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   891
    @classmethod
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   892
    def debug(cls, msg, *a, **kw):
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   893
        pass
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   894
    info = warning = error = critical = exception = debug
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   895
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   896
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   897
class CubicWebConfiguration(CubicWebNoAppConfiguration):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   898
    """base class for cubicweb server and web configurations"""
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   899
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   900
    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
   901
        _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
   902
    #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
   903
    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
   904
        _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
   905
    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
   906
        _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
   907
7129
455b503fb7ff [config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7086
diff changeset
   908
    # 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
   909
    # 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
   910
    repairing = False
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   911
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   912
    # set by upgrade command
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
   913
    verbosity = 0
10474
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10411
diff changeset
   914
    cmdline_options = None
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   915
    options = CubicWebNoAppConfiguration.options + (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   916
        ('log-file',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   917
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   918
          'default': Method('default_log_file'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   919
          '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
   920
          'group': 'main', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   921
          }),
10477
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   922
        ('statsd-endpoint',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   923
         {'type' : 'string',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   924
          'default': '',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   925
          'help': 'UDP address of the statsd endpoint; it must be formatted'
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   926
                  'like <ip>:<port>; disabled is unset.',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   927
          'group': 'main', 'level': 2,
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   928
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   929
        # email configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   930
        ('smtp-host',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   931
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   932
          'default': 'mail',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   933
          '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
   934
          'group': 'email', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   935
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   936
        ('smtp-port',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   937
         {'type' : 'int',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   938
          'default': 25,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   939
          '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
   940
          'group': 'email', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   941
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   942
        ('sender-name',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   943
         {'type' : 'string',
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   944
          'default': Method('default_instance_id'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   945
          'help': 'name used as HELO name for outgoing emails from the \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   946
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
   947
          'group': 'email', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   948
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   949
        ('sender-addr',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   950
         {'type' : 'string',
2351
dddee537e4d5 don't use internal address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2267
diff changeset
   951
          'default': 'cubicweb@mydomain.com',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   952
          'help': 'email address used as HELO address for outgoing emails from \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   953
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
   954
          'group': 'email', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   955
          }),
10308
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   956
        ('logstat-interval',
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   957
         {'type' : 'int',
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   958
          'default': 0,
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   959
          'help': 'interval (in seconds) at which stats are dumped in the logstat file; set 0 to disable',
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   960
          'group': 'main', 'level': 2,
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   961
          }),
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   962
        ('logstat-file',
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   963
         {'type' : 'string',
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   964
          'default': Method('default_stats_file'),
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   965
          'help': 'file where stats for the instance should be written',
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   966
          'group': 'main', 'level': 2,
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
   967
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   968
        )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   969
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   970
    @classmethod
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   971
    def instances_dir(cls):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   972
        """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
   973
        return abspath(os.environ.get('CW_INSTANCES_DIR', cls._INSTANCES_DIR))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   974
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   975
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   976
    def migration_scripts_dir(cls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   977
        """cubicweb migration scripts directory"""
12272
36032de96867 [cwconfig] Look for migration scripts directory relatively to code
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12269
diff changeset
   978
        mdir = join(dirname(__file__), 'misc', 'migration')
36032de96867 [cwconfig] Look for migration scripts directory relatively to code
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12269
diff changeset
   979
        assert exists(mdir), 'migration path %s does not exist' % mdir
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   980
        return mdir
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   981
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   982
    @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
   983
    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
   984
        """return a configuration instance for the given instance identifier
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   985
        """
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
   986
        cls.load_available_configs()
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   987
        config = config or guess_configuration(cls.instance_home(appid))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   988
        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
   989
        return configcls(appid, debugmode, creating)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   990
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   991
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   992
    def possible_configurations(cls, appid):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   993
        """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
   994
        instance id
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   995
        """
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   996
        home = cls.instance_home(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   997
        return possible_configurations(home)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   998
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   999
    @classmethod
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1000
    def instance_home(cls, appid):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1001
        """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
  1002
        instance id
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1003
        """
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1004
        home = join(cls.instances_dir(), appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1005
        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
  1006
            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
  1007
                                     ' "cubicweb-ctl list")' % appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1008
        return home
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1009
9251
e4d753c8b1c4 remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8850
diff changeset
  1010
    MODES = ('common', 'repository', 'Any')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1011
    MCOMPAT = {'all-in-one': MODES,
12138
10a18c6c5e10 [cwconfig] Add "pyramid" config type to MCOMPAT dict
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12116
diff changeset
  1012
               'pyramid': MODES,
9251
e4d753c8b1c4 remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8850
diff changeset
  1013
               'repository': ('common', 'repository', 'Any')}
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1014
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1015
    def accept_mode(cls, mode):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1016
        #assert mode in cls.MODES, mode
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1017
        return mode in cls.MCOMPAT[cls.name]
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1018
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1019
    # default configuration methods ###########################################
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1020
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1021
    def default_instance_id(self):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1022
        """return the instance identifier, useful for option which need this
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1023
        as default value
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1024
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1025
        return self.appid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1026
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1027
    def default_log_file(self):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1028
        """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
  1029
        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
  1030
            import tempfile
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1031
            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
  1032
                basename(self.appid), self.name))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1033
            path = basepath + '.log'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1034
            i = 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1035
            while exists(path) and i < 100: # arbitrary limit to avoid infinite loop
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1036
                try:
10614
57dfde80df11 [py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10591
diff changeset
  1037
                    open(path, 'a')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1038
                    break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1039
                except IOError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1040
                    path = '%s-%s.log' % (basepath, i)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1041
                    i += 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1042
            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
  1043
        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
  1044
            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
  1045
        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
  1046
            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
  1047
            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
  1048
10308
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
  1049
    def default_stats_file(self):
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
  1050
        """return default path to the stats file of the instance'server"""
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
  1051
        logfile = self.default_log_file()
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
  1052
        if logfile.endswith('.log'):
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
  1053
            logfile = logfile[:-4]
3f94034cc972 [hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents: 10273
diff changeset
  1054
        return logfile + '.stats'
10477
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1055
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1056
    def default_pid_file(self):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1057
        """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
  1058
        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
  1059
            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
  1060
                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
  1061
            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
  1062
                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
  1063
        else:
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1064
            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
  1065
            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
  1066
        # 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
  1067
        # 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
  1068
        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
  1069
        return join(rtdir, '%s-%s.pid' % (self.appid, self.name))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1070
10568
3914388b2d0f [repoapi, cwconfig] give a convenience method to get a repository from a config
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10567
diff changeset
  1071
    # config -> repository
3914388b2d0f [repoapi, cwconfig] give a convenience method to get a repository from a config
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10567
diff changeset
  1072
3914388b2d0f [repoapi, cwconfig] give a convenience method to get a repository from a config
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10567
diff changeset
  1073
    def repository(self, vreg=None):
11983
5de78b6fff2e [server] Separate repository bootstrap from initialization
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11974
diff changeset
  1074
        """Return a new bootstrapped repository."""
10568
3914388b2d0f [repoapi, cwconfig] give a convenience method to get a repository from a config
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10567
diff changeset
  1075
        from cubicweb.server.repository import Repository
12015
fe057cb231b6 [cwconfig] Do not instantiate a repo with a scheduler in repository method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12012
diff changeset
  1076
        repo = Repository(self, vreg=vreg)
11983
5de78b6fff2e [server] Separate repository bootstrap from initialization
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11974
diff changeset
  1077
        repo.bootstrap()
5de78b6fff2e [server] Separate repository bootstrap from initialization
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11974
diff changeset
  1078
        return repo
10568
3914388b2d0f [repoapi, cwconfig] give a convenience method to get a repository from a config
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10567
diff changeset
  1079
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1080
    # instance methods used to get instance specific resources #############
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1081
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
    def __init__(self, appid, debugmode=False, creating=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1083
        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
  1084
        # 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
  1085
        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
  1086
        super(CubicWebConfiguration, self).__init__(debugmode)
10622
3cc6154b94a3 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
  1087
        fake_gettext = (text_type, lambda ctx, msgid: text_type(msgid))
6749
48f468f33704 [config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6748
diff changeset
  1088
        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
  1089
            self.translations[lang] = fake_gettext
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1090
        self._cubes = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1091
        self.load_file_configuration(self.main_config_file())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1092
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1093
    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
  1094
        super(CubicWebConfiguration, self).adjust_sys_path()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1095
        # adding apphome to python path is not usually necessary in production
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1096
        # environments, but necessary for tests
9682
fcb672023553 [cwconfig] use "foo not in bar" instead of "not foo in bar"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9669
diff changeset
  1097
        if self.apphome and self.apphome not in sys.path:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1098
            sys.path.insert(0, self.apphome)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1099
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1100
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1101
    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
  1102
        return join(self.instances_dir(), self.appid)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1103
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1104
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1105
    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
  1106
        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
  1107
            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
  1108
                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
  1109
            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
  1110
                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
  1111
        else:
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1112
            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
  1113
        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
  1114
        return join(iddir, self.appid)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1115
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1116
    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
  1117
        super(CubicWebConfiguration, self).init_cubes(cubes)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1118
        # reload config file in cases options are defined in cubes __init__
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1119
        # or site_cubicweb files
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1120
        self.load_file_configuration(self.main_config_file())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1121
        # configuration initialization hook
10474
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10411
diff changeset
  1122
        self.load_configuration(**(self.cmdline_options or {}))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1123
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1124
    def add_cubes(self, cubes):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1125
        """add given cubes to the list of used cubes"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1126
        if not isinstance(cubes, list):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1127
            cubes = list(cubes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1128
        self._cubes = self.reorder_cubes(list(self._cubes) + cubes)
11209
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
  1129
        self.load_site_cubicweb(cubes)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1130
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1131
    def main_config_file(self):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1132
        """return instance's control configuration file"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1133
        return join(self.apphome, '%s.conf' % self.name)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1134
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1135
    def save(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1136
        """write down current configuration"""
10931
6168a45f62df [cwconfig] Explicitly close generated config file
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10719
diff changeset
  1137
        with open(self.main_config_file(), 'w') as fobj:
6168a45f62df [cwconfig] Explicitly close generated config file
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10719
diff changeset
  1138
            self.generate_config(fobj)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1139
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
  1140
    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
  1141
        """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
  1142
        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
  1143
6135
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1144
        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
  1145
        """
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
  1146
        if not exists(path):
8484
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1147
            self.info('creating %s directory', path)
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1148
            try:
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1149
                os.makedirs(path)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
  1150
            except OSError as ex:
8484
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1151
                self.warning('error while creating %s directory: %s', path, ex)
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1152
                return
11435
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1153
        self.ensure_uid(path)
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1154
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1155
    def get_uid(self):
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
  1156
        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
  1157
            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
  1158
                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
  1159
            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
  1160
                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
  1161
                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
  1162
        else:
6135
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1163
            try:
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1164
                uid = os.getuid()
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1165
            except AttributeError: # we are on windows
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1166
                return
11435
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1167
        return uid
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1168
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1169
    def ensure_uid(self, path, enforce_write=False):
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1170
        if not exists(path):
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1171
            return
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1172
        uid = self.get_uid()
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1173
        if uid is None:
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1174
            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
  1175
        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
  1176
        if fstat.st_uid != uid:
11435
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1177
            self.info('giving ownership of %s to %s', path, self['uid'])
8484
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1178
            try:
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1179
                os.chown(path, uid, os.getgid())
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
  1180
            except OSError as ex:
11435
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1181
                self.warning('error while giving ownership of %s to %s: %s',
8484
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1182
                             path, self['uid'], ex)
11435
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1183
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1184
        if enforce_write and not (fstat.st_mode & stat.S_IWUSR):
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1185
            self.info('forcing write permission on %s', path)
8484
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1186
            try:
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1187
                os.chmod(path, fstat.st_mode | stat.S_IWUSR)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
  1188
            except OSError as ex:
11435
42578bc0b5ef [cwconfig] extract uid file setting code from check_writeable_uid_directory (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11056
diff changeset
  1189
                self.warning('error while forcing write permission on %s: %s',
8484
4c1efb5bde0a [config] load_configuration should not crash because of fs errors. Closes #2286215
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8477
diff changeset
  1190
                             path, ex)
11436
dca6ae982ee5 [cwconfig] add the CubicWebConfiguration.ensure_uid_directory() method (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11435
diff changeset
  1191
dca6ae982ee5 [cwconfig] add the CubicWebConfiguration.ensure_uid_directory() method (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11435
diff changeset
  1192
    def ensure_uid_directory(self, path, enforce_write=False):
dca6ae982ee5 [cwconfig] add the CubicWebConfiguration.ensure_uid_directory() method (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11435
diff changeset
  1193
        self.check_writeable_uid_directory(path)
11461
f5a4e14d1dd2 Merge 3.22 into 3.23
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11436 11444
diff changeset
  1194
        for dirpath, dirnames, filenames in os.walk(path):
f5a4e14d1dd2 Merge 3.22 into 3.23
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11436 11444
diff changeset
  1195
            for name in filenames:
f5a4e14d1dd2 Merge 3.22 into 3.23
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11436 11444
diff changeset
  1196
                self.ensure_uid(join(dirpath, name), enforce_write)
11436
dca6ae982ee5 [cwconfig] add the CubicWebConfiguration.ensure_uid_directory() method (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11435
diff changeset
  1197
        return path
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
  1198
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1199
    @cached
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1200
    def instance_md5_version(self):
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
  1201
        from hashlib import md5 # pylint: disable=E0611
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1202
        infos = []
7264
9ed9e1d77ef3 [web config] fix md5 version to ensure cubes order and to include cubicweb version
Florent Cayré
parents: 7179
diff changeset
  1203
        for pkg in sorted(self.cubes()):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1204
            version = self.cube_version(pkg)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1205
            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
  1206
        infos.append('cubicweb-%s' % str(self.cubicweb_version()))
10671
e08102f45237 [py3k] bytes required for hashlib.{md5,sha1}()
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
  1207
        return md5((';'.join(infos)).encode('ascii')).hexdigest()
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1208
10474
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10411
diff changeset
  1209
    def load_configuration(self, **kw):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1210
        """load instance's configuration files"""
10474
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10411
diff changeset
  1211
        super(CubicWebConfiguration, self).load_configuration(**kw)
7129
455b503fb7ff [config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7086
diff changeset
  1212
        if self.apphome and not self.creating:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1213
            # 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
  1214
            self._gettext_init()
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1215
11209
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
  1216
    def _load_site_cubicweb(self, cube):
10401
4f41eb2f06bc [cwconfig] typo in comment
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10084
diff changeset
  1217
        # overridden to register cube specific options
11209
631fe2751b73 [cwconfig] Stop using lgc.modutils to load site_cubicweb.py files
Rémi Cardona <remi.cardona@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11129
diff changeset
  1218
        mod = super(CubicWebConfiguration, self)._load_site_cubicweb(cube)
11211
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
  1219
        if getattr(mod, 'options', None):
34c903b883ab [cwconfig] Use imp.load_source instead of exec() to load site_cubicweb.py from apphome
Julien Cristau <julien.cristau@logilab.fr>
parents: 11210
diff changeset
  1220
            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
  1221
            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
  1222
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
  1223
    def init_log(self, logthreshold=None, force=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1224
        """init the log service"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1225
        if not force and hasattr(self, '_logging_initialized'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1226
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1227
        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
  1228
        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
  1229
        super_self.init_log(logthreshold, logfile=self.get('log-file'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1230
        # read a config file if it exists
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1231
        logconfig = join(self.apphome, 'logging.conf')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1232
        if exists(logconfig):
7178
a62f24e1497e fileConfig is in logging.config
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7086
diff changeset
  1233
            logging.config.fileConfig(logconfig)
10477
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1234
        # set the statsd address, if any
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1235
        if self.get('statsd-endpoint'):
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1236
            try:
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1237
                address, port = self.get('statsd-endpoint').split(':')
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1238
                port = int(port)
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1239
            except:
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1240
                self.error('statsd-endpoint: invalid address format ({}); '
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1241
                           'it should be "ip:port"'.format(self.get('statsd-endpoint')))
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1242
            else:
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1243
                import statsd_logger
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1244
                statsd_logger.setup('cubicweb.%s' % self.appid, (address, port))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1245
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1246
    def available_languages(self, *args):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1247
        """return available translation for an instance, by looking for
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1248
        compiled catalog
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1249
4936
a4b772a0d801 Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4889
diff changeset
  1250
        take \*args to be usable as a vocabulary method
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1251
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1252
        from glob import glob
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1253
        yield 'en' # ensure 'en' is yielded even if no .mo found
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1254
        for path in glob(join(self.apphome, 'i18n',
3118
9e7a155bc4e5 more i18n commands fixes :
Aurélien Campéas
parents: 3115
diff changeset
  1255
                              '*', 'LC_MESSAGES')):
9e7a155bc4e5 more i18n commands fixes :
Aurélien Campéas
parents: 3115
diff changeset
  1256
            lang = path.split(os.sep)[-2]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1257
            if lang != 'en':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1258
                yield lang
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1259
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5442
diff changeset
  1260
    def _gettext_init(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1261
        """set language for gettext"""
10719
065b5ac5c039 Rename gettext to cwgettext, use stdlib gettext
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10671
diff changeset
  1262
        from cubicweb.cwgettext import translation
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1263
        path = join(self.apphome, 'i18n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1264
        for language in self.available_languages():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1265
            self.info("loading language %s", language)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1266
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1267
                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
  1268
                self.translations[language] = (tr.ugettext, tr.upgettext)
11857
a166ddb503aa [cwconfig] Trim down allowed exceptions in gettext language setting
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11793
diff changeset
  1269
            except IOError:
8436
150191e45ee5 [cwconfig] shutup on absent i18n/ mo files when in operating in tests
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8378
diff changeset
  1270
                if self.mode != 'test':
150191e45ee5 [cwconfig] shutup on absent i18n/ mo files when in operating in tests
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8378
diff changeset
  1271
                    # in test contexts, data/i18n does not exist, hence
150191e45ee5 [cwconfig] shutup on absent i18n/ mo files when in operating in tests
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8378
diff changeset
  1272
                    # logging will only pollute the logs
150191e45ee5 [cwconfig] shutup on absent i18n/ mo files when in operating in tests
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8378
diff changeset
  1273
                    self.exception('localisation support error for language %s',
150191e45ee5 [cwconfig] shutup on absent i18n/ mo files when in operating in tests
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8378
diff changeset
  1274
                                   language)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1275
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1276
    @staticmethod
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1277
    def _sorted_appobjects(appobjects):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1278
        appobjects = sorted(appobjects)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1279
        try:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1280
            index = appobjects.index('entities')
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1281
        except ValueError:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1282
            pass
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1283
        else:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1284
            # put entities first
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1285
            appobjects.insert(0, appobjects.pop(index))
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1286
        return appobjects
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1287
11918
a88101bf9f87 [cwconfig] make appobjects_cubes_modnames() public
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11900
diff changeset
  1288
    def appobjects_cube_modnames(self, cube):
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1289
        modnames = []
12078
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
  1290
        cube_modname = _cube_modname(cube)
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1291
        cube_submodnames = self._sorted_appobjects(self.cube_appobject_path)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1292
        for name in cube_submodnames:
12078
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
  1293
            for modname, filepath in _expand_modname('.'.join([cube_modname, name])):
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1294
                modnames.append(modname)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1295
        return modnames
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1296
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1297
    def appobjects_modnames(self):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1298
        modnames = []
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1299
        for name in self._sorted_appobjects(self.cubicweb_appobject_path):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1300
            for modname, filepath in _expand_modname('cubicweb.' + name):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1301
                modnames.append(modname)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1302
        for cube in reversed(self.cubes()):
11918
a88101bf9f87 [cwconfig] make appobjects_cubes_modnames() public
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11900
diff changeset
  1303
            modnames.extend(self.appobjects_cube_modnames(cube))
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1304
        if self.apphome:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1305
            cube_submodnames = self._sorted_appobjects(self.cube_appobject_path)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1306
            apphome = realpath(self.apphome)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1307
            for name in cube_submodnames:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1308
                for modname, filepath in _expand_modname(name):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1309
                    # ensure file is in apphome
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1310
                    if realpath(filepath).startswith(apphome):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1311
                        modnames.append(modname)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1312
        return modnames
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1313
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1314
    def set_sources_mode(self, sources):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1315
        if not 'all' in sources:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10568
diff changeset
  1316
            print('warning: ignoring specified sources, requires a repository '
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10568
diff changeset
  1317
                  'configuration')
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1318
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1319
    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
  1320
        from cubicweb import i18n
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1321
        if langs is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1322
            langs = self.available_languages()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1323
        i18ndir = join(self.apphome, 'i18n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1324
        if not exists(i18ndir):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1325
            create_dir(i18ndir)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1326
        sourcedirs = [join(path, 'i18n') for path in self.cubes_path()]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1327
        sourcedirs.append(self.i18n_lib_dir())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1328
        return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1329
9363
d773589b6d46 [mail] allow to specify SMTP's MAIL FROM address to config.sendmails(). Closes #3373620
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9258
diff changeset
  1330
    def sendmails(self, msgs, fromaddr=None):
5198
cf8292f80384 [controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5143
diff changeset
  1331
        """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
  1332
        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
  1333
        """
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1334
        server, port = self['smtp-host'], self['smtp-port']
9363
d773589b6d46 [mail] allow to specify SMTP's MAIL FROM address to config.sendmails(). Closes #3373620
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9258
diff changeset
  1335
        if fromaddr is None:
d773589b6d46 [mail] allow to specify SMTP's MAIL FROM address to config.sendmails(). Closes #3373620
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9258
diff changeset
  1336
            fromaddr = '%s <%s>' % (self['sender-name'], self['sender-addr'])
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1337
        SMTP_LOCK.acquire()
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1338
        try:
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1339
            try:
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1340
                smtp = SMTP(server, port)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
  1341
            except Exception as ex:
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1342
                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
  1343
                               server, port, ex)
12659
a422eeca6994 [config] Raise in case of failure to send emails when in test mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12435
diff changeset
  1344
                if self.mode == 'test':
a422eeca6994 [config] Raise in case of failure to send emails when in test mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12435
diff changeset
  1345
                    raise
5198
cf8292f80384 [controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5143
diff changeset
  1346
                return False
12719
9fb4a71f119d [py3] Pass bytes as "msg" to smtplib.SMTP.sendmail()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12659
diff changeset
  1347
            for mimedoc, recipients in msgs:
9fb4a71f119d [py3] Pass bytes as "msg" to smtplib.SMTP.sendmail()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12659
diff changeset
  1348
                msg = mimedoc.as_string() if PY2 else mimedoc.as_bytes()
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1349
                try:
12719
9fb4a71f119d [py3] Pass bytes as "msg" to smtplib.SMTP.sendmail()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12659
diff changeset
  1350
                    smtp.sendmail(fromaddr, recipients, msg)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
  1351
                except Exception as ex:
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1352
                    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
  1353
                                   recipients, ex)
12659
a422eeca6994 [config] Raise in case of failure to send emails when in test mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12435
diff changeset
  1354
                    if self.mode == 'test':
a422eeca6994 [config] Raise in case of failure to send emails when in test mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12435
diff changeset
  1355
                        raise
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1356
            smtp.close()
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1357
        finally:
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1358
            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
  1359
        return True
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1360
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
  1361
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
  1362
                logging.getLogger('cubicweb.configuration'))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1363
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1364
# 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
  1365
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
  1366
application_configuration = deprecated('use instance_configuration')(instance_configuration)
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1367
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1368
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1369
_EXT_REGISTERED = False
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1370
def register_stored_procedures():
4848
41f84eea63c9 rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
  1371
    from logilab.database import FunctionDescr
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1372
    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
  1373
    from rql.nodes import SortTerm, Constant, VariableRef
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1374
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1375
    global _EXT_REGISTERED
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1376
    if _EXT_REGISTERED:
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1377
        return
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1378
    _EXT_REGISTERED = True
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1379
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1380
    class COMMA_JOIN(FunctionDescr):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1381
        supported_backends = ('postgres', 'sqlite',)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1382
        rtype = 'String'
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1383
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
  1384
        def st_description(self, funcnode, mainindex, tr):
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1385
            return ', '.join(sorted(term.get_description(mainindex, tr)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1386
                                    for term in iter_funcnode_variables(funcnode)))
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1387
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1388
    register_function(COMMA_JOIN)  # XXX do not expose?
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1389
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1390
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1391
    class CONCAT_STRINGS(COMMA_JOIN):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1392
        aggregat = True
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1393
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1394
    register_function(CONCAT_STRINGS) # XXX bw compat
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1395
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
  1396
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1397
    class GROUP_CONCAT(CONCAT_STRINGS):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1398
        supported_backends = ('mysql', 'postgres', 'sqlite',)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1399
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1400
    register_function(GROUP_CONCAT)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1401
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1402
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1403
    class LIMIT_SIZE(FunctionDescr):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1404
        supported_backends = ('postgres', 'sqlite',)
7691
c47dcd37d4e3 [rql] fix min/max args definition of [TEXT_]LIMIT_SIZE registered procedures (long outstanding bug discovered after recent fix in lgdb)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7264
diff changeset
  1405
        minargs = maxargs = 3
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1406
        rtype = 'String'
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1407
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
  1408
        def st_description(self, funcnode, mainindex, tr):
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1409
            return funcnode.children[0].get_description(mainindex, tr)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1410
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1411
    register_function(LIMIT_SIZE)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1412
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1413
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1414
    class TEXT_LIMIT_SIZE(LIMIT_SIZE):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1415
        supported_backends = ('mysql', 'postgres', 'sqlite',)
7691
c47dcd37d4e3 [rql] fix min/max args definition of [TEXT_]LIMIT_SIZE registered procedures (long outstanding bug discovered after recent fix in lgdb)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7264
diff changeset
  1416
        minargs = maxargs = 2
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1417
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1418
    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
  1419
f65743cc53e4 first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1420
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
  1421
    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
  1422
        """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
  1423
        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
  1424
        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
  1425
        """
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
  1426
        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
  1427
        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
  1428
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
  1429
        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
  1430
            """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
  1431
            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
  1432
            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
  1433
            """
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
  1434
            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
  1435
                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
  1436
                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
  1437
                    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
  1438
                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
  1439
                    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
  1440
                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
  1441
                    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
  1442
                    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
  1443
                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
  1444
                    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
  1445
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
  1446
    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
  1447
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
  1448
4322
f65743cc53e4 first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1449
    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
  1450
        """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
  1451
        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
  1452
        """
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
  1453
        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
  1454
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
  1455
        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
  1456
            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
  1457
            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
  1458
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
  1459
        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
  1460
            raise NotImplementedError(
0f31ed3fff79 [bfss storage] Improve fspath() error message.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6779
diff changeset
  1461
                '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
  1462
                '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
  1463
5630
40d7c7e180f1 [storage] source's callback has a new prototype, update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5534
diff changeset
  1464
        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
  1465
            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
  1466
            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
  1467
                return Binary(fpath)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
  1468
            except OSError as ex:
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7822
diff changeset
  1469
                source.critical("can't open %s: %s", fpath, ex)
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
  1470
                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
  1471
f65743cc53e4 first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1472
    register_function(FSPATH)