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