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