cubicweb/cwconfig.py
author Philippe Pepiot <philippe.pepiot@logilab.fr>
Wed, 27 Mar 2019 16:19:50 +0100
changeset 12543 71aa20cb43f2
parent 12530 9d88e1177c35
child 12544 56e1132f19c3
permissions -rw-r--r--
[cwconfig] drop legacy cube importer We don't want to support legacy cubes anymore.
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
12361
37bfcaa1792d [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
37bfcaa1792d [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
37bfcaa1792d [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
10622
3cc6154b94a3 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
   195
from six import text_type
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
180
8bcebdb5f55d code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 140
diff changeset
   198
from logilab.common.logging_ext import set_log_methods, init_log
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
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
   200
                                          ConfigurationMixIn, merge_options,
2e1a1ebd4730 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459)
David Douard <david.douard@logilab.fr>
parents: 11793
diff changeset
   201
                                          _validate as lgc_validate)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
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
   203
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
   204
                      ConfigurationError, Binary, _)
11476
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   205
from cubicweb.toolsutils import create_dir, option_value_from_env
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
CONFIGURATIONS = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
   209
SMTP_LOCK = Lock()
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
   210
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
def configuration_cls(name):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
    """return the configuration class registered with the given name"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
        return [c for c in CONFIGURATIONS if c.name == name][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
    except IndexError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
        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
   218
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   219
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
def possible_configurations(directory):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
    """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
   222
    according to \*-ctl files
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
    """
12053
c3c9f2e1424c [pyramid] Add a "pyramid" instance configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12015
diff changeset
   224
    return [name for name in ('repository', 'all-in-one', 'pyramid')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
            if exists(join(directory, '%s.conf' % name))]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   227
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
def guess_configuration(directory):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
    """try to guess the configuration to use for a directory. If multiple
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
    configurations are found, ConfigurationError is raised
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
    modes = possible_configurations(directory)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
    if len(modes) != 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
        raise ConfigurationError('unable to guess configuration from %r %s'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
                                 % (directory, modes))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
    return modes[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
11870
3a84a79c4ed5 Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11857
diff changeset
   238
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   239
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
   240
    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
   241
        return 'cubicweb_' + cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   242
    return cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   243
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   244
12078
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   245
def _cube_modname(cube):
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   246
    modname = _cube_pkgname(cube)
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   247
    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
   248
    if loader:
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   249
        return modname
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   250
    else:
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   251
        return 'cubes.' + cube
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   252
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
   253
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   254
def _expand_modname(modname, recursive=True):
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   255
    """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
   256
    submodules and subpackages and yield (submodname, filepath) including
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   257
    `modname` itself
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   258
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   259
    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
   260
    corresponding source .py file exists before yielding.
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   261
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   262
    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
   263
    """
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   264
    try:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   265
        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
   266
    except ImportError:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   267
        return
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   268
    if not loader:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   269
        return
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   270
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   271
    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
   272
        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
   273
            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
   274
                return False
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   275
        return True
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   276
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   277
    filepath = loader.get_filename()
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   278
    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
   279
        return
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   280
    yield modname, filepath
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   281
    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
   282
        path = dirname(filepath)
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   283
        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
   284
            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
   285
            if not ispkg:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   286
                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
   287
                if check_source_file(filepath):
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   288
                    yield submodname, filepath
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   289
            elif recursive:
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   290
                for x in _expand_modname(submodname, recursive=True):
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   291
                    yield x
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   292
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   293
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
# persistent options definition
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
PERSISTENT_OPTIONS = (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    ('encoding',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
      'default': 'UTF-8',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
      'help': _('user interface encoding'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
      'group': 'ui', 'sitewide': True,
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   301
      }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
    ('language',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
      'default': 'en',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
      'vocabulary': Method('available_languages'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
      'help': _('language of the user interface'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   307
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
    ('date-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
      '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
   312
      '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
   313
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
    ('datetime-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
      '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
   318
      '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
   319
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
    ('time-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
      '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
   324
      '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
   325
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
    ('float-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
     {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
      'default': '%.3f',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
      'help': _('how to format float numbers in the ui'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   331
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
    ('default-text-format',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
     {'type' : 'choice',
10012
8c2c6fdd8d56 [RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents: 9990
diff changeset
   335
      '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
   336
      'default': 'text/plain',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
      'help': _('default text format for rich text fields.'),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   338
      'group': 'ui',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
      }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
    ('short-line-size',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
     {'type' : 'int',
5391
fe3fe2b2b60a [config] augment default value for short-line-size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5264
diff changeset
   342
      'default': 80,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
      'help': _('maximum number of characters in short description'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
      'group': 'navigation',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
      }),
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
def register_persistent_options(options):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
    global PERSISTENT_OPTIONS
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
    PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   351
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
CFGTYPE2ETYPE_MAP = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
    'string': 'String',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
    'choice': 'String',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
    'yn':     'Boolean',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
    'int':    'Int',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
    'float' : 'Float',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
    }
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   359
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
   360
12273
9d08f89a3d85 [cwconfig] Always use "sys.prefix" to determine installation prefix
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12272
diff changeset
   361
_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
   362
_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
   363
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
class CubicWebNoAppConfiguration(ConfigurationMixIn):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
    """base class for cubicweb configuration without a specific instance directory
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
    # to set in concrete configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
    name = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
    # log messages format (see logging module documentation for available keys)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
    log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s'
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   371
    # the format below can be useful to debug multi thread issues:
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   372
    # 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
   373
    # 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
   374
    cleanup_unused_appobjects = True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
10084
eb3681e13ed9 [config] kill a getattr
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10012
diff changeset
   376
    quick_start = False
eb3681e13ed9 [config] kill a getattr
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10012
diff changeset
   377
11072
8c3155a0ae5b Handle virtualenv development mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   378
    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
   379
        mode = os.environ.get('CW_MODE', 'user')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
    else:
12266
043db1f91922 [cwconfig] Get rid of _forced_mode global
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12265
diff changeset
   381
        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
   382
    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
   383
12273
9d08f89a3d85 [cwconfig] Always use "sys.prefix" to determine installation prefix
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12272
diff changeset
   384
    _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
   385
    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
   386
    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
   387
    CUBES_PATH = os.environ.get('CW_CUBES_PATH', '').split(os.pathsep)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
1046
52ee022d87e3 simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents: 819
diff changeset
   389
    options = (
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
       ('log-threshold',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
         {'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
   392
          'default': 'WARNING',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
          '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
   394
          'group': 'main', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
          }),
6779
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   396
        ('umask',
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   397
         {'type' : 'int',
10591
8e46ed1a0b8a [py3k] octals and long
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10589
diff changeset
   398
          'default': 0o077,
6779
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   399
          '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
   400
          'group': 'main', 'level': 2,
accf5978a440 [daemon] make process umask configurable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
   401
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   402
        # common configuration options which are potentially required as soon as
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
        # you're using "base" application objects (ie to really server/web
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
        # specific)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
        ('base-url',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   406
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
          'default': None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
          '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
   409
          'group': 'main', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
          }),
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
   411
        ('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
   412
         {'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
   413
          '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
   414
          '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
   415
          '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
   416
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
        ('mangle-emails',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
         {'type' : 'yn',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
          'default': False,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
          'help': "don't display actual email addresses but mangle them if \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   421
this option is set to yes",
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   422
          'group': 'email', 'level': 3,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
        )
11476
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   425
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   426
    def __getitem__(self, key):
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   427
        """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
   428
        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
   429
        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
   430
        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
   431
            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
   432
            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
   433
        return value
11476
a9f26de5ea6c Let configuration option be overridden by environment variables
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11472
diff changeset
   434
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   435
    # static and class methods used to get instance independant resources ##
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   436
    @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
    def cubicweb_version():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
        """return installed cubicweb version"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
        from logilab.common.changelog import Version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   440
        from cubicweb import __pkginfo__
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   441
        version = __pkginfo__.numversion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
        assert len(version) == 3, version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
        return Version(version)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   444
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   445
    @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   446
    def persistent_options_configuration():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
        return Configuration(options=PERSISTENT_OPTIONS)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   448
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   449
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
    def i18n_lib_dir(cls):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   451
        """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
   452
        return join(dirname(__file__), 'i18n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
    @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
   455
    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
   456
        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
   457
            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
   458
                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
   459
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
    @classmethod
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   462
    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
   463
        """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
   464
3522b19f35d6 [cwconfig] Add a docstring on available_cubes method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12115
diff changeset
   465
        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
   466
        """
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   467
        cubes = set()
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   468
        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
   469
                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
   470
            try:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   471
                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
   472
            except ImportError:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   473
                continue
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   474
            else:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   475
                modname = module.__name__
12115
8d0127498a28 Backed out changeset fe995d56c949
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12109
diff changeset
   476
                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
   477
                    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
   478
                                entry_point)
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   479
                    continue
12115
8d0127498a28 Backed out changeset fe995d56c949
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12109
diff changeset
   480
                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
   481
        # Legacy cubes.
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   482
        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
   483
            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
   484
                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
   485
                          % directory)
4001
bc31ede2085d dont crash if directory doesn't exist
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3915
diff changeset
   486
                continue
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   487
            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
   488
                if cube == 'shared':
5026
1f8238eaec9b [config] more cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5025
diff changeset
   489
                    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
   490
                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
   491
                    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
   492
                if cube == 'pyramid':
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   493
                    cls._warn_pyramid_cube()
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   494
                    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
   495
                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
   496
                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
   497
                    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
   498
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   499
        def sortkey(cube):
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   500
            """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
   501
            prefix = 'cubicweb_'
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   502
            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
   503
                # 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
   504
                # '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
   505
                # randomization" turned on).
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   506
                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
   507
            return cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   508
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   509
        return sorted(cubes, key=sortkey)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   510
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
    @classmethod
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   512
    def cubes_search_path(cls):
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   513
        """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
   514
        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
   515
                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
   516
        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
   517
            path.append(cls.CUBES_DIR)
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   518
        return path
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   519
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
   520
    @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
   521
    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
   522
        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
   523
        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
   524
            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
   525
                extrapath[cubesdir] = 'cubes'
4325
16642cc7d497 oops, missing return
syt@www.fleurdetomate.fr
parents: 4324
diff changeset
   526
        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
   527
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   528
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   529
    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
   530
        """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
   531
        `ConfigurationError` if it doesn't exist
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   532
        """
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   533
        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
   534
        loader = pkgutil.find_loader(pkgname)
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   535
        if loader:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   536
            return dirname(loader.get_filename())
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   537
        # Legacy cubes.
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   538
        for directory in cls.cubes_search_path():
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   539
            cubedir = join(directory, cube)
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   540
            if exists(cubedir):
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 436
diff changeset
   541
                return cubedir
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   542
        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
   543
        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
   544
                                        'pkg': _cube_pkgname(cube),
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   545
                                        'path': cls.cubes_search_path()})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   546
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   547
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   548
    def cube_migration_scripts_dir(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   549
        """cube migration scripts directory"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   550
        return join(cls.cube_dir(cube), 'migration')
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   551
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   552
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   553
    def cube_pkginfo(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   554
        """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
   555
        pkgname = _cube_pkgname(cube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   556
        try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   557
            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
   558
        except ImportError:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   559
            cube = CW_MIGRATION_MAP.get(cube, cube)
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   560
            try:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   561
                parent = __import__('cubes.%s.__pkginfo__' % cube)
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   562
                return getattr(parent, cube).__pkginfo__
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   563
            except Exception as ex:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   564
                raise ConfigurationError(
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   565
                    '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
   566
                    % (cube, ex.__class__.__name__, ex))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   567
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   568
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   569
    def cube_version(cls, cube):
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   570
        """return the version of the cube located in the given directory
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   571
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   572
        from logilab.common.changelog import Version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   573
        version = cls.cube_pkginfo(cube).numversion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   574
        assert len(version) == 3, version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   575
        return Version(version)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   576
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   577
    @classmethod
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   578
    def _cube_deps(cls, cube, key, oldkey):
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   579
        """return cubicweb cubes used by the given cube"""
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   580
        pkginfo = cls.cube_pkginfo(cube)
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   581
        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
   582
            # explicit __xxx_cubes__ attribute
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   583
            deps = getattr(pkginfo, key)
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   584
        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
   585
            # 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
   586
            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
   587
                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
   588
            except AttributeError:
9255
46f41c3e1443 remove 3.8 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9251
diff changeset
   589
                deps = {}
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   590
            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
   591
                deps = dict( (x[len('cubicweb-'):], v)
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10622
diff changeset
   592
                             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
   593
                             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
   594
        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
   595
            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
   596
                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
   597
            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
   598
                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
   599
            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
   600
                deps[newname] = deps.pop(depcube)
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   601
        return deps
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   602
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5023
diff changeset
   603
    @classmethod
6659
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   604
    def cube_depends_cubicweb_version(cls, cube):
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   605
        # 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
   606
        try:
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   607
            pkginfo = cls.cube_pkginfo(cube)
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   608
            deps = getattr(pkginfo, '__depends__')
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   609
            return deps.get('cubicweb')
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   610
        except AttributeError:
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   611
            return None
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   612
6205927e927a fix problem introduced with previous commit
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6657
diff changeset
   613
    @classmethod
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   614
    def cube_dependencies(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   615
        """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
   616
        return cls._cube_deps(cube, '__depends_cubes__', '__use__')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   617
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   618
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   619
    def cube_recommends(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   620
        """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
   621
        return cls._cube_deps(cube, '__recommends_cubes__', '__recommend__')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   622
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   623
    @classmethod
2762
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   624
    def expand_cubes(cls, cubes, with_recommends=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   625
        """expand the given list of top level cubes used by adding recursivly
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   626
        each cube dependencies
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   627
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   628
        cubes = list(cubes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   629
        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
   630
        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
   631
            available = set(cls.available_cubes())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   632
        while todo:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   633
            cube = todo.pop(0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   634
            for depcube in cls.cube_dependencies(cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   635
                if depcube not in cubes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   636
                    cubes.append(depcube)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   637
                    todo.append(depcube)
2762
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   638
            if with_recommends:
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   639
                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
   640
                    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
   641
                        cubes.append(depcube)
b1bb33b37992 [config] new with_recommends option to expand_cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2665
diff changeset
   642
                        todo.append(depcube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   643
        return cubes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   644
9669
283503f58400 [cwconfig] Remove useless 'ui-cube' configuration option (closes #3728904)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9363
diff changeset
   645
    @classmethod
283503f58400 [cwconfig] Remove useless 'ui-cube' configuration option (closes #3728904)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9363
diff changeset
   646
    def reorder_cubes(cls, cubes):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   647
        """reorder cubes from the top level cubes to inner dependencies
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   648
        cubes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   649
        """
5322
c0b7687bce3d [config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5298
diff changeset
   650
        from logilab.common.graph import ordered_nodes, UnorderableGraph
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   651
        graph = {}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   652
        for cube in cubes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   653
            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
   654
            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
   655
                              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
   656
            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
   657
                               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
   658
        try:
c0b7687bce3d [config] graph ordering function moved to lgc 0.50
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5298
diff changeset
   659
            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
   660
        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
   661
            raise ConfigurationError(ex)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   662
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   663
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   664
    def cls_adjust_sys_path(cls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   665
        """update python path if necessary"""
11920
f13799fbcfea [cwconfig] create a virtual "cubes" package
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11918
diff changeset
   666
        import cubes
f13799fbcfea [cwconfig] create a virtual "cubes" package
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11918
diff changeset
   667
        cubes.__path__ = cls.cubes_search_path()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   668
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   669
    @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
   670
    def load_available_configs(cls):
12530
9d88e1177c35 Remove Twisted web server
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12508
diff changeset
   671
        for confmod in ('web.webconfig',
12053
c3c9f2e1424c [pyramid] Add a "pyramid" instance configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12015
diff changeset
   672
                        '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
   673
            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
   674
                __import__('cubicweb.%s' % confmod)
11990
18aafce99b49 [cwconfig] Fix two NameError in load_available_configs()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11983
diff changeset
   675
            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
   676
                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
   677
                            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
   678
f45f42256905 [config] we should load available configuration before search for an instance configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6846
diff changeset
   679
    @classmethod
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   680
    def load_cwctl_plugins(cls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   681
        cls.cls_adjust_sys_path()
12530
9d88e1177c35 Remove Twisted web server
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12508
diff changeset
   682
        for ctlmod in ('web.webctl', 'server.serverctl',
11681
b23d58050076 Merge cubicweb-pyramid cube
Yann Voté <yann.vote@logilab.fr>
parents: 11476
diff changeset
   683
                       '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
   684
            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
   685
                __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
   686
            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
   687
                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
   688
                            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
   689
                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
   690
            cls.info('loaded cubicweb-ctl plugin %s', ctlmod)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   691
        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
   692
            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
   693
            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
   694
            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
   695
            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
   696
                pkgname = cube
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   697
            else:
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   698
                pkgname = 'cubes.%s' % cube
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   699
            if exists(pluginfile):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   700
                try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   701
                    __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
   702
                    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
   703
                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
   704
                    cls.exception('while loading plugin %s', pluginfile)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   705
            elif exists(initfile):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   706
                try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   707
                    __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
   708
                except Exception:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   709
                    cls.exception('while loading cube %s', cube)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   710
            else:
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   711
                cls.warning('no __init__ file in cube %s', cube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   712
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2654
diff changeset
   713
    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
   714
    cube_appobject_path = set(['entities'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   715
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
   716
    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
   717
        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
   718
            # 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
   719
            filterwarnings('default', category=DeprecationWarning)
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
   720
        register_stored_procedures()
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   721
        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
   722
        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
   723
        self.debugmode = debugmode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   724
        self.adjust_sys_path()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   725
        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
   726
        # 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
   727
        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
   728
        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
   729
        # 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
   730
        # 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
   731
        # 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
   732
        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
   733
            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
   734
        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
   735
            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
   736
        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
   737
            cw_rest_init()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   738
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   739
    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
   740
        # overriden in CubicWebConfiguration
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   741
        self.cls_adjust_sys_path()
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   742
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
   743
    def init_log(self, logthreshold=None, logfile=None, syslog=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   744
        """init the log service"""
180
8bcebdb5f55d code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 140
diff changeset
   745
        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
   746
            if self.debugmode:
180
8bcebdb5f55d code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 140
diff changeset
   747
                logthreshold = 'DEBUG'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   748
            else:
180
8bcebdb5f55d code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 140
diff changeset
   749
                logthreshold = self['log-threshold']
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   750
        if sys.platform == 'win32':
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   751
            # no logrotate on win32, so use logging rotation facilities
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   752
            # 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
   753
            # idea: make this configurable?
5655
ef903fff826d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5633 5647
diff changeset
   754
            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
   755
                     rotation_parameters={'when': 'W6', # every sunday
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   756
                                          '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
   757
                                          'backupCount': 52})
5640
8a6d14f4fb9d logging settings
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5456
diff changeset
   758
        else:
5655
ef903fff826d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5633 5647
diff changeset
   759
            init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   760
        # configure simpleTal logger
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   761
        logging.getLogger('simpleTAL').setLevel(logging.ERROR)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   762
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   763
    def schema_modnames(self):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   764
        modnames = []
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   765
        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
   766
            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
   767
        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
   768
            for modname, filepath in _expand_modname(
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   769
                    '{0}.schema'.format(_cube_modname(cube)),
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   770
                    recursive=False):
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   771
                modnames.append((cube, modname))
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   772
        if self.apphome:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   773
            apphome = realpath(self.apphome)
12165
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   774
            for modname, filepath in _expand_modname(
127f7da447a4 [cwconfig] load appobjects subpackages recursively
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12138
diff changeset
   775
                    'schema', recursive=False):
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   776
                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
   777
                    modnames.append(('data', modname))
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   778
        return modnames
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11870
diff changeset
   779
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
   780
    def appobjects_modnames(self):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
   781
        """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
   782
        application objects. By default return nothing in NoApp config.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   783
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   784
        return []
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   785
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
   786
    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
   787
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
   788
    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
   789
        """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
   790
        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
   791
            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
   792
                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
   793
            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
   794
                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
   795
                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
   796
            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
   797
                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
   798
        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
   799
            # 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
   800
            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
   801
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
   802
    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
   803
        """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
   804
        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
   805
            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
   806
                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
   807
                __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
   808
            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
   809
                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
   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
            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
   812
            __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
   813
            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
   814
        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
   815
            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
   816
            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
   817
            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
   818
                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
   819
                    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
   820
7031
a04621040cad [config refactoring] rename eproperty_definition method to cwproperty_definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7005
diff changeset
   821
    def cwproperty_definitions(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   822
        cfg = self.persistent_options_configuration()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   823
        for section, options in cfg.options_by_section():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   824
            section = section.lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   825
            for optname, optdict, value in options:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   826
                key = '%s.%s' % (section, optname)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   827
                type, vocab = self.map_option(optdict)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   828
                default = cfg.option_default(optname, optdict)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   829
                pdef = {'type': type, 'vocabulary': vocab, 'default': default,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   830
                        'help': optdict['help'],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   831
                        'sitewide': optdict.get('sitewide', False)}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   832
                yield key, pdef
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   833
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   834
    def map_option(self, optdict):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   835
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   836
            vocab = optdict['choices']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   837
        except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   838
            vocab = optdict.get('vocabulary')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   839
            if isinstance(vocab, Method):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   840
                vocab = getattr(self, vocab.method, ())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   841
        return CFGTYPE2ETYPE_MAP[optdict['type']], vocab
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   842
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
   843
    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
   844
        """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
   845
        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
   846
        """
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 None
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   848
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   849
    _cubes = None
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   850
11711
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   851
    @classmethod
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   852
    def _warn_pyramid_cube(cls):
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   853
        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
   854
                    "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
   855
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   856
    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
   857
        cubes = list(cubes)
dd5df5fe7137 [config] Exclude "pyramid" cube when initializing application cubes
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11681
diff changeset
   858
        if 'pyramid' in cubes:
11711
fe0fcb9e1fd0 [config] Ignore cubicweb-pyramid in available_cubes()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11710
diff changeset
   859
            self._warn_pyramid_cube()
11710
dd5df5fe7137 [config] Exclude "pyramid" cube when initializing application cubes
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11681
diff changeset
   860
            cubes.remove('pyramid')
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   861
        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
   862
        # 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
   863
        for cube in cubes:
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   864
            try:
11472
bc04039acd2e [config] Make available_cubes aware of cubes installed as packages
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11459
diff changeset
   865
                importlib.import_module(_cube_pkgname(cube))
11459
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   866
            except ImportError:
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   867
                # Legacy cube.
8987a05950dc Handle cubes as packages in cwconfig
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11458
diff changeset
   868
                __import__('cubes.%s' % cube)
6494
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   869
        self.load_site_cubicweb()
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   870
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   871
    def cubes(self):
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   872
        """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
   873
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   874
        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
   875
        cubes
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
        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
   878
        return self._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
    def cubes_path(self):
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   881
        """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
   882
        most to inner most cubes
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   883
        """
70c87c717e4a [config] make config.cubes() available on NoAppCubicWebConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6397
diff changeset
   884
        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
   885
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
   886
    # 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
   887
    # 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
   888
    @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
   889
    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
   890
        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
   891
    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
   892
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   893
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   894
class CubicWebConfiguration(CubicWebNoAppConfiguration):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   895
    """base class for cubicweb server and web configurations"""
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   896
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   897
    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
   898
        _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
   899
    #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
   900
    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
   901
        _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
   902
    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
   903
        _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
   904
7129
455b503fb7ff [config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7086
diff changeset
   905
    # 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
   906
    # 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
   907
    repairing = False
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   908
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
   909
    # 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
   910
    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
   911
    cmdline_options = None
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   912
    options = CubicWebNoAppConfiguration.options + (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   913
        ('log-file',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   914
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   915
          'default': Method('default_log_file'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   916
          '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
   917
          'group': 'main', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   918
          }),
10477
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   919
        ('statsd-endpoint',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   920
         {'type' : 'string',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   921
          'default': '',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   922
          '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
   923
                  'like <ip>:<port>; disabled is unset.',
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   924
          'group': 'main', 'level': 2,
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
   925
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   926
        # email configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   927
        ('smtp-host',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   928
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   929
          'default': 'mail',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   930
          '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
   931
          'group': 'email', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   932
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   933
        ('smtp-port',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   934
         {'type' : 'int',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   935
          'default': 25,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   936
          '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
   937
          'group': 'email', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   938
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   939
        ('sender-name',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   940
         {'type' : 'string',
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   941
          'default': Method('default_instance_id'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   942
          'help': 'name used as HELO name for outgoing emails from the \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   943
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
   944
          'group': 'email', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   945
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   946
        ('sender-addr',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   947
         {'type' : 'string',
2351
dddee537e4d5 don't use internal address
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2267
diff changeset
   948
          'default': 'cubicweb@mydomain.com',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   949
          'help': 'email address used as HELO address for outgoing emails from \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   950
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
   951
          'group': 'email', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   952
          }),
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
   953
        ('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
   954
         {'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
   955
          '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
   956
          '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
   957
          '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
   958
          }),
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
        ('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
   960
         {'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
   961
          '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
   962
          '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
   963
          '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
   964
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   965
        )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   966
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   967
    @classmethod
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
   968
    def instances_dir(cls):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   969
        """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
   970
        return abspath(os.environ.get('CW_INSTANCES_DIR', cls._INSTANCES_DIR))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   971
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   972
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   973
    def migration_scripts_dir(cls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   974
        """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
   975
        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
   976
        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
   977
        return mdir
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   978
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   979
    @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
   980
    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
   981
        """return a configuration instance for the given instance identifier
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   982
        """
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
   983
        cls.load_available_configs()
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   984
        config = config or guess_configuration(cls.instance_home(appid))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   985
        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
   986
        return configcls(appid, debugmode, creating)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   987
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   988
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   989
    def possible_configurations(cls, appid):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   990
        """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
   991
        instance id
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   992
        """
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   993
        home = cls.instance_home(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   994
        return possible_configurations(home)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   995
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   996
    @classmethod
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   997
    def instance_home(cls, appid):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   998
        """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
   999
        instance id
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1000
        """
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1001
        home = join(cls.instances_dir(), appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1002
        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
  1003
            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
  1004
                                     ' "cubicweb-ctl list")' % appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1005
        return home
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1006
9251
e4d753c8b1c4 remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8850
diff changeset
  1007
    MODES = ('common', 'repository', 'Any')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1008
    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
  1009
               'pyramid': MODES,
9251
e4d753c8b1c4 remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8850
diff changeset
  1010
               'repository': ('common', 'repository', 'Any')}
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1011
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1012
    def accept_mode(cls, mode):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1013
        #assert mode in cls.MODES, mode
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1014
        return mode in cls.MCOMPAT[cls.name]
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1015
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1016
    # default configuration methods ###########################################
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1017
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1018
    def default_instance_id(self):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1019
        """return the instance identifier, useful for option which need this
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1020
        as default value
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1021
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1022
        return self.appid
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1023
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1024
    def default_log_file(self):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1025
        """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
  1026
        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
  1027
            import tempfile
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1028
            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
  1029
                basename(self.appid), self.name))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1030
            path = basepath + '.log'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1031
            i = 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1032
            while exists(path) and i < 100: # arbitrary limit to avoid infinite loop
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1033
                try:
10614
57dfde80df11 [py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10591
diff changeset
  1034
                    open(path, 'a')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1035
                    break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1036
                except IOError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1037
                    path = '%s-%s.log' % (basepath, i)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1038
                    i += 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1039
            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
  1040
        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
  1041
            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
  1042
        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
  1043
            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
  1044
            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
  1045
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
  1046
    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
  1047
        """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
  1048
        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
  1049
        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
  1050
            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
  1051
        return logfile + '.stats'
10477
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1052
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1053
    def default_pid_file(self):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1054
        """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
  1055
        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
  1056
            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
  1057
                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
  1058
            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
  1059
                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
  1060
        else:
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1061
            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
  1062
            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
  1063
        # 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
  1064
        # 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
  1065
        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
  1066
        return join(rtdir, '%s-%s.pid' % (self.appid, self.name))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1067
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
  1068
    # 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
  1069
3914388b2d0f [repoapi, cwconfig] give a convenience method to get a repository from a config
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10567
diff changeset
  1070
    def repository(self, vreg=None):
11983
5de78b6fff2e [server] Separate repository bootstrap from initialization
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11974
diff changeset
  1071
        """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
  1072
        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
  1073
        repo = Repository(self, vreg=vreg)
11983
5de78b6fff2e [server] Separate repository bootstrap from initialization
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11974
diff changeset
  1074
        repo.bootstrap()
5de78b6fff2e [server] Separate repository bootstrap from initialization
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11974
diff changeset
  1075
        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
  1076
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1077
    # instance methods used to get instance specific resources #############
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1078
7129
455b503fb7ff [config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7086
diff changeset
  1079
    def __init__(self, appid, debugmode=False, creating=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1080
        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
  1081
        # 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
  1082
        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
  1083
        super(CubicWebConfiguration, self).__init__(debugmode)
10622
3cc6154b94a3 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
  1084
        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
  1085
        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
  1086
            self.translations[lang] = fake_gettext
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1087
        self._cubes = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1088
        self.load_file_configuration(self.main_config_file())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1089
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1090
    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
  1091
        super(CubicWebConfiguration, self).adjust_sys_path()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1092
        # adding apphome to python path is not usually necessary in production
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1093
        # 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
  1094
        if self.apphome and self.apphome not in sys.path:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1095
            sys.path.insert(0, self.apphome)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1096
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1097
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1098
    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
  1099
        return join(self.instances_dir(), self.appid)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1100
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1101
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1102
    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
  1103
        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
  1104
            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
  1105
                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
  1106
            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
  1107
                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
  1108
        else:
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5013
diff changeset
  1109
            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
  1110
        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
  1111
        return join(iddir, self.appid)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1112
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1113
    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
  1114
        super(CubicWebConfiguration, self).init_cubes(cubes)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1115
        # reload config file in cases options are defined in cubes __init__
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1116
        # or site_cubicweb files
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1117
        self.load_file_configuration(self.main_config_file())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1118
        # 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
  1119
        self.load_configuration(**(self.cmdline_options or {}))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1120
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1121
    def add_cubes(self, cubes):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1122
        """add given cubes to the list of used cubes"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1123
        if not isinstance(cubes, list):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1124
            cubes = list(cubes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1125
        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
  1126
        self.load_site_cubicweb(cubes)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1127
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1128
    def main_config_file(self):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1129
        """return instance's control configuration file"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1130
        return join(self.apphome, '%s.conf' % self.name)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1131
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1132
    def save(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1133
        """write down current configuration"""
10931
6168a45f62df [cwconfig] Explicitly close generated config file
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10719
diff changeset
  1134
        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
  1135
            self.generate_config(fobj)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1136
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
  1137
    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
  1138
        """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
  1139
        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
  1140
6135
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1141
        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
  1142
        """
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
        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
  1144
            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
  1145
            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
  1146
                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
  1147
            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
  1148
                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
  1149
                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
  1150
        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
  1151
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
  1152
    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
  1153
        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
  1154
            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
  1155
                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
  1156
            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
  1157
                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
  1158
                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
  1159
        else:
6135
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1160
            try:
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1161
                uid = os.getuid()
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1162
            except AttributeError: # we are on windows
e4b37742f75a [win32] no os.getuid on windows
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6087
diff changeset
  1163
                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
  1164
        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
  1165
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
  1166
    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
  1167
        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
  1168
            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
  1169
        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
  1170
        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
  1171
            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
  1172
        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
  1173
        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
  1174
            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
  1175
            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
  1176
                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
  1177
            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
  1178
                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
  1179
                             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
  1180
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
        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
  1182
            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
  1183
            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
  1184
                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
  1185
            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
  1186
                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
  1187
                             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
  1188
dca6ae982ee5 [cwconfig] add the CubicWebConfiguration.ensure_uid_directory() method (related to #11298794)
David Douard <david.douard@logilab.fr>
parents: 11435
diff changeset
  1189
    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
  1190
        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
  1191
        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
  1192
            for name in filenames:
f5a4e14d1dd2 Merge 3.22 into 3.23
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11436 11444
diff changeset
  1193
                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
  1194
        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
  1195
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1196
    @cached
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1197
    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
  1198
        from hashlib import md5 # pylint: disable=E0611
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1199
        infos = []
7264
9ed9e1d77ef3 [web config] fix md5 version to ensure cubes order and to include cubicweb version
Florent Cayré
parents: 7179
diff changeset
  1200
        for pkg in sorted(self.cubes()):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1201
            version = self.cube_version(pkg)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1202
            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
  1203
        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
  1204
        return md5((';'.join(infos)).encode('ascii')).hexdigest()
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1205
10474
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10411
diff changeset
  1206
    def load_configuration(self, **kw):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1207
        """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
  1208
        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
  1209
        if self.apphome and not self.creating:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1210
            # 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
  1211
            self._gettext_init()
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1212
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
  1213
    def _load_site_cubicweb(self, cube):
10401
4f41eb2f06bc [cwconfig] typo in comment
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10084
diff changeset
  1214
        # 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
  1215
        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
  1216
        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
  1217
            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
  1218
            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
  1219
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
  1220
    def init_log(self, logthreshold=None, force=False):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1221
        """init the log service"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1222
        if not force and hasattr(self, '_logging_initialized'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1223
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1224
        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
  1225
        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
  1226
        super_self.init_log(logthreshold, logfile=self.get('log-file'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1227
        # read a config file if it exists
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1228
        logconfig = join(self.apphome, 'logging.conf')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1229
        if exists(logconfig):
7178
a62f24e1497e fileConfig is in logging.config
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7086
diff changeset
  1230
            logging.config.fileConfig(logconfig)
10477
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1231
        # set the statsd address, if any
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1232
        if self.get('statsd-endpoint'):
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1233
            try:
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1234
                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
  1235
                port = int(port)
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1236
            except:
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1237
                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
  1238
                           '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
  1239
            else:
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1240
                import statsd_logger
ee21c559f94f implement a simple statsd logger (closes #5488711)
David Douard <david.douard@logilab.fr>
parents: 10474
diff changeset
  1241
                statsd_logger.setup('cubicweb.%s' % self.appid, (address, port))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1242
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1243
    def available_languages(self, *args):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1244
        """return available translation for an instance, by looking for
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1245
        compiled catalog
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1246
4936
a4b772a0d801 Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4889
diff changeset
  1247
        take \*args to be usable as a vocabulary method
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1248
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1249
        from glob import glob
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1250
        yield 'en' # ensure 'en' is yielded even if no .mo found
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1251
        for path in glob(join(self.apphome, 'i18n',
3118
9e7a155bc4e5 more i18n commands fixes :
Aurélien Campéas
parents: 3115
diff changeset
  1252
                              '*', 'LC_MESSAGES')):
9e7a155bc4e5 more i18n commands fixes :
Aurélien Campéas
parents: 3115
diff changeset
  1253
            lang = path.split(os.sep)[-2]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1254
            if lang != 'en':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1255
                yield lang
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1256
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5442
diff changeset
  1257
    def _gettext_init(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1258
        """set language for gettext"""
10719
065b5ac5c039 Rename gettext to cwgettext, use stdlib gettext
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10671
diff changeset
  1259
        from cubicweb.cwgettext import translation
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1260
        path = join(self.apphome, 'i18n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1261
        for language in self.available_languages():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1262
            self.info("loading language %s", language)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1263
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1264
                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
  1265
                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
  1266
            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
  1267
                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
  1268
                    # 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
  1269
                    # 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
  1270
                    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
  1271
                                   language)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1272
11900
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1273
    @staticmethod
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1274
    def _sorted_appobjects(appobjects):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1275
        appobjects = sorted(appobjects)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1276
        try:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1277
            index = appobjects.index('entities')
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1278
        except ValueError:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1279
            pass
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1280
        else:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1281
            # put entities first
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1282
            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
  1283
        return appobjects
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1284
11918
a88101bf9f87 [cwconfig] make appobjects_cubes_modnames() public
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11900
diff changeset
  1285
    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
  1286
        modnames = []
12078
82d2c1cdf0c2 [cwconfig] don't rely on _CubeImporter while loading cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12053
diff changeset
  1287
        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
  1288
        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
  1289
        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
  1290
            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
  1291
                modnames.append(modname)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1292
        return modnames
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1293
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1294
    def appobjects_modnames(self):
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1295
        modnames = []
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1296
        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
  1297
            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
  1298
                modnames.append(modname)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1299
        for cube in reversed(self.cubes()):
11918
a88101bf9f87 [cwconfig] make appobjects_cubes_modnames() public
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11900
diff changeset
  1300
            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
  1301
        if self.apphome:
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1302
            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
  1303
            apphome = realpath(self.apphome)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1304
            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
  1305
                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
  1306
                    # 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
  1307
                    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
  1308
                        modnames.append(modname)
8496135b6dc1 [cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11899
diff changeset
  1309
        return modnames
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1310
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1311
    def set_sources_mode(self, sources):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1312
        if not 'all' in sources:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10568
diff changeset
  1313
            print('warning: ignoring specified sources, requires a repository '
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10568
diff changeset
  1314
                  'configuration')
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1315
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1316
    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
  1317
        from cubicweb import i18n
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1318
        if langs is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1319
            langs = self.available_languages()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1320
        i18ndir = join(self.apphome, 'i18n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1321
        if not exists(i18ndir):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1322
            create_dir(i18ndir)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1323
        sourcedirs = [join(path, 'i18n') for path in self.cubes_path()]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1324
        sourcedirs.append(self.i18n_lib_dir())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1325
        return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1326
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
  1327
    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
  1328
        """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
  1329
        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
  1330
        """
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1331
        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
  1332
        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
  1333
            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
  1334
        SMTP_LOCK.acquire()
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1335
        try:
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1336
            try:
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1337
                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
  1338
            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
  1339
                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
  1340
                               server, port, ex)
5198
cf8292f80384 [controller] refactor send mail controller to use cwconfig.sendmails
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5143
diff changeset
  1341
                return False
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1342
            for msg, recipients in msgs:
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1343
                try:
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
  1344
                    smtp.sendmail(fromaddr, recipients, msg.as_string())
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8669
diff changeset
  1345
                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
  1346
                    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
  1347
                                   recipients, ex)
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1348
            smtp.close()
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1349
        finally:
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1350
            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
  1351
        return True
2221
d9b85a7b0bdd create sendmails method on cwconfig, use it in SendMailOp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2220
diff changeset
  1352
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
  1353
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
  1354
                logging.getLogger('cubicweb.configuration'))
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
  1355
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
  1356
# 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
  1357
instance_configuration = CubicWebConfiguration.config_for
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1358
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1359
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1360
_EXT_REGISTERED = False
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1361
def register_stored_procedures():
4848
41f84eea63c9 rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
  1362
    from logilab.database import FunctionDescr
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1363
    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
  1364
    from rql.nodes import SortTerm, Constant, VariableRef
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1365
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1366
    global _EXT_REGISTERED
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1367
    if _EXT_REGISTERED:
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1368
        return
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1369
    _EXT_REGISTERED = True
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1370
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1371
    class COMMA_JOIN(FunctionDescr):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1372
        supported_backends = ('postgres', 'sqlite',)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1373
        rtype = 'String'
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1374
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
  1375
        def st_description(self, funcnode, mainindex, tr):
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1376
            return ', '.join(sorted(term.get_description(mainindex, tr)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1377
                                    for term in iter_funcnode_variables(funcnode)))
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1378
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1379
    register_function(COMMA_JOIN)  # XXX do not expose?
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1380
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1381
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1382
    class CONCAT_STRINGS(COMMA_JOIN):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1383
        aggregat = True
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1384
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1385
    register_function(CONCAT_STRINGS) # XXX bw compat
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1386
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
  1387
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1388
    class GROUP_CONCAT(CONCAT_STRINGS):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1389
        supported_backends = ('mysql', 'postgres', 'sqlite',)
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
    register_function(GROUP_CONCAT)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1392
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
    class LIMIT_SIZE(FunctionDescr):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1395
        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
  1396
        minargs = maxargs = 3
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1397
        rtype = 'String'
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1398
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
  1399
        def st_description(self, funcnode, mainindex, tr):
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1400
            return funcnode.children[0].get_description(mainindex, tr)
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
    register_function(LIMIT_SIZE)
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1403
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1404
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1405
    class TEXT_LIMIT_SIZE(LIMIT_SIZE):
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1406
        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
  1407
        minargs = maxargs = 2
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1408
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4021
diff changeset
  1409
    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
  1410
f65743cc53e4 first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1411
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
  1412
    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
  1413
        """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
  1414
        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
  1415
        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
  1416
        """
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
  1417
        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
  1418
        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
  1419
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
  1420
        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
  1421
            """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
  1422
            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
  1423
            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
  1424
            """
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
            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
  1426
                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
  1427
                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
  1428
                    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
  1429
                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
  1430
                    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
  1431
                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
  1432
                    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
  1433
                    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
  1434
                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
  1435
                    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
  1436
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
    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
  1438
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
4322
f65743cc53e4 first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1440
    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
  1441
        """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
  1442
        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
  1443
        """
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
  1444
        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
  1445
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
  1446
        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
  1447
            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
  1448
            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
  1449
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
        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
  1451
            raise NotImplementedError(
0f31ed3fff79 [bfss storage] Improve fspath() error message.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6779
diff changeset
  1452
                '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
  1453
                '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
  1454
5630
40d7c7e180f1 [storage] source's callback has a new prototype, update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5534
diff changeset
  1455
        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
  1456
            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
  1457
            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
  1458
                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
  1459
            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
  1460
                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
  1461
                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
  1462
f65743cc53e4 first draft for a simple hooks based custom attribute storage,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1463
    register_function(FSPATH)