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