server/serverconfig.py
author Rémi Cardona <remi.cardona@logilab.fr>
Wed, 16 Sep 2015 15:17:42 +0200
changeset 10689 49a62b8f6d43
parent 10617 c36cda9074c5
child 10793 8316fdad9987
permissions -rw-r--r--
[py3k] unicode vs str vs bytes vs the world
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10235
684215aca046 Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9468
diff changeset
     1
# copyright 2003-2014 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: 5326
diff changeset
     2
# 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: 5326
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5326
diff changeset
     4
# 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: 5326
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5326
diff changeset
     6
# 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: 5326
diff changeset
     7
# 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: 5326
diff changeset
     8
# 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: 5326
diff changeset
     9
# 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: 5326
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# 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: 5326
diff changeset
    12
# 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: 5326
diff changeset
    13
# 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: 5326
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5326
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5326
diff changeset
    16
# 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: 5326
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
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: 5456
diff changeset
    18
"""server.serverconfig definition"""
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10301
diff changeset
    19
from __future__ import print_function
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    23
import sys
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
from os.path import join, exists
10617
c36cda9074c5 [py3k] io.StringIO
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
    25
from io import StringIO
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    27
import logilab.common.configuration as lgconfig
9468
39b7a91a3f4c [repo] pylint cleanup, mainly of imports, with a bit of style
Julien Cristau <julien.cristau@logilab.fr>
parents: 9460
diff changeset
    28
from logilab.common.decorators import cached
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
3637
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3547
diff changeset
    30
from cubicweb.toolsutils import read_config, restrict_perms_to_user
8989
8742f4bf029f import merge_options directly from logilab.common
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8988
diff changeset
    31
from cubicweb.cwconfig import CONFIGURATIONS, CubicWebConfiguration
2107
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    32
from cubicweb.server import SOURCE_TYPES
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
2107
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    35
USER_OPTIONS =  (
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    36
    ('login', {'type' : 'string',
3835
a191b3b9e455 more sensible default values to c-c "create" inputs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
    37
               'default': 'admin',
2107
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    38
               'help': "cubicweb manager account's login "
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    39
               '(this user will be created)',
5323
329b4f6d18b4 [config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5059
diff changeset
    40
               'level': 0,
2107
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    41
               }),
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    42
    ('password', {'type' : 'password',
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    43
                  'default': lgconfig.REQUIRED,
2107
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    44
                  'help': "cubicweb manager account's password",
5323
329b4f6d18b4 [config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5059
diff changeset
    45
                  'level': 0,
2107
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    46
                  }),
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    47
    )
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
    48
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    49
class SourceConfiguration(lgconfig.Configuration):
6299
51a9494b5efb [sqlite] quick hacks to fix #1251873 and #1251874
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6128
diff changeset
    50
    def __init__(self, appconfig, options):
51a9494b5efb [sqlite] quick hacks to fix #1251873 and #1251874
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6128
diff changeset
    51
        self.appconfig = appconfig # has to be done before super call
3904
dc7d315165fc default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3900
diff changeset
    52
        super(SourceConfiguration, self).__init__(options=options)
dc7d315165fc default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3900
diff changeset
    53
dc7d315165fc default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3900
diff changeset
    54
    # make Method('default_instance_id') usable in db option defs (in native.py)
3905
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3904
diff changeset
    55
    def default_instance_id(self):
6299
51a9494b5efb [sqlite] quick hacks to fix #1251873 and #1251874
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6128
diff changeset
    56
        return self.appconfig.appid
3904
dc7d315165fc default_instance id should also be available when silently rebuilding soures file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3900
diff changeset
    57
6299
51a9494b5efb [sqlite] quick hacks to fix #1251873 and #1251874
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6128
diff changeset
    58
    def input_option(self, option, optdict, inputlevel):
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    59
        try:
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    60
            dbdriver = self['db-driver']
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    61
        except lgconfig.OptionError:
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    62
            pass
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    63
        else:
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    64
            if dbdriver == 'sqlite':
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    65
                if option in ('db-user', 'db-password'):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    66
                    return
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    67
                if option == 'db-name':
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    68
                    optdict = optdict.copy()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    69
                    optdict['help'] = 'path to the sqlite database'
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    70
                    optdict['default'] = join(self.appconfig.appdatahome,
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    71
                                              self.appconfig.appid + '.sqlite')
6299
51a9494b5efb [sqlite] quick hacks to fix #1251873 and #1251874
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6128
diff changeset
    72
        super(SourceConfiguration, self).input_option(option, optdict, inputlevel)
51a9494b5efb [sqlite] quick hacks to fix #1251873 and #1251874
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6128
diff changeset
    73
51a9494b5efb [sqlite] quick hacks to fix #1251873 and #1251874
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6128
diff changeset
    74
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    75
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    76
def ask_source_config(appconfig, type, inputlevel=0):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    77
    options = SOURCE_TYPES[type].options
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    78
    sconfig = SourceConfiguration(appconfig, options=options)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    79
    sconfig.input_config(inputlevel=inputlevel)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    80
    return sconfig
2105
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    81
6627
430b7703b3fd [sources] method to ease modification of a source config through c-c shell
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6478
diff changeset
    82
def generate_source_config(sconfig, encoding=sys.stdin.encoding):
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    83
    """serialize a repository source configuration as text"""
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    84
    stream = StringIO()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    85
    optsbysect = list(sconfig.options_by_section())
8708
78a99960286a [ldapfeed] all options of a source should be in the same group, else you get AssertionError on c-c add-source. Closes #2538398
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8670
diff changeset
    86
    assert len(optsbysect) == 1, (
78a99960286a [ldapfeed] all options of a source should be in the same group, else you get AssertionError on c-c add-source. Closes #2538398
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8670
diff changeset
    87
        'all options for a source should be in the same group, got %s'
78a99960286a [ldapfeed] all options of a source should be in the same group, else you get AssertionError on c-c add-source. Closes #2538398
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8670
diff changeset
    88
        % [x[0] for x in optsbysect])
6627
430b7703b3fd [sources] method to ease modification of a source config through c-c shell
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6478
diff changeset
    89
    lgconfig.ini_format(stream, optsbysect[0][1], encoding)
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    90
    return stream.getvalue()
2105
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    91
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    92
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
class ServerConfiguration(CubicWebConfiguration):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
    """standalone RQL server"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
    name = 'repository'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
2835
04034421b072 [hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2810
diff changeset
    97
    cubicweb_appobject_path = CubicWebConfiguration.cubicweb_appobject_path | set(['sobjects', 'hooks'])
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    98
    cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['sobjects', 'hooks'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
8989
8742f4bf029f import merge_options directly from logilab.common
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8988
diff changeset
   100
    options = lgconfig.merge_options((
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
        # ctl configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
        ('host',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
          'default': None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
          'help': 'host name if not correctly detectable through gethostname',
5323
329b4f6d18b4 [config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5059
diff changeset
   106
          'group': 'main', 'level': 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        ('pid-file',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
         {'type' : 'string',
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   110
          'default': lgconfig.Method('default_pid_file'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
          'help': 'repository\'s pid file',
5323
329b4f6d18b4 [config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5059
diff changeset
   112
          'group': 'main', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
        ('uid',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
         {'type' : 'string',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
          'default': None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
          'help': 'if this option is set, use the specified user to start \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
the repository rather than the user running the command',
5323
329b4f6d18b4 [config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5059
diff changeset
   119
          'group': 'main', 'level': (CubicWebConfiguration.mode == 'installed') and 0 or 1,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
          }),
6012
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   121
        ('cleanup-session-time',
5326
0d9054eb3bd1 [config] properly use time type for options representing a time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5059
diff changeset
   122
         {'type' : 'time',
6012
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   123
          'default': '24h',
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   124
          'help': 'duration of inactivity after which a session '
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   125
          'will be closed, to limit memory consumption (avoid sessions that '
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   126
          'never expire and cause memory leak when http-session-time is 0, or '
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   127
          'because of bad client that never closes their connection). '
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   128
          'So notice that even if http-session-time is 0 and the user don\'t '
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   129
          'close his browser, he will have to reauthenticate after this time '
d56fd78006cd [session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   130
          'of inactivity. Default to 24h.',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   131
          'group': 'main', 'level': 3,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
        ('connections-pool-size',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
         {'type' : 'int',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
          'default': 4,
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7301
diff changeset
   136
          'help': 'size of the connections pool. Each source supporting multiple \
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
connections will have this number of opened connections.',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   138
          'group': 'main', 'level': 3,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        ('rql-cache-size',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
         {'type' : 'int',
8182
d062d3b7da6c [config] fix rql-cache-size initial values (closes #2162160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7896
diff changeset
   142
          'default': 3000,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
          'help': 'size of the parsed rql cache size.',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   144
          'group': 'main', 'level': 3,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
          }),
8306
4da49700b06a [config, undo] Fix undo-support option migration
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8265
diff changeset
   146
        ('undo-enabled',
8265
9747ab9230ad [repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8216
diff changeset
   147
         {'type' : 'yn', 'default': False,
9747ab9230ad [repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents: 8216
diff changeset
   148
          'help': 'enable undo support',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   149
          'group': 'main', 'level': 3,
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4834
diff changeset
   150
          }),
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4834
diff changeset
   151
        ('keep-transaction-lifetime',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4834
diff changeset
   152
         {'type' : 'int', 'default': 7,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4834
diff changeset
   153
          'help': 'number of days during which transaction records should be \
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4834
diff changeset
   154
kept (hence undoable).',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   155
          'group': 'main', 'level': 3,
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4834
diff changeset
   156
          }),
5059
1d5c81588144 [repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5043
diff changeset
   157
        ('multi-sources-etypes',
1d5c81588144 [repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5043
diff changeset
   158
         {'type' : 'csv', 'default': (),
1d5c81588144 [repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5043
diff changeset
   159
          'help': 'defines which entity types from this repository are used \
6128
fbb8398f80dc cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6126
diff changeset
   160
by some other instances. You should set this properly for these instances to \
5059
1d5c81588144 [repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5043
diff changeset
   161
detect updates / deletions.',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   162
          'group': 'main', 'level': 3,
5059
1d5c81588144 [repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5043
diff changeset
   163
          }),
1d5c81588144 [repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5043
diff changeset
   164
1160
77bf88f01fcc new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents: 136
diff changeset
   165
        ('delay-full-text-indexation',
77bf88f01fcc new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents: 136
diff changeset
   166
         {'type' : 'yn', 'default': False,
77bf88f01fcc new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents: 136
diff changeset
   167
          'help': 'When full text indexation of entity has a too important cost'
77bf88f01fcc new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents: 136
diff changeset
   168
          ' to be done when entity are added/modified by users, activate this '
77bf88f01fcc new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents: 136
diff changeset
   169
          'option and setup a job using cubicweb-ctl db-rebuild-fti on your '
77bf88f01fcc new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents: 136
diff changeset
   170
          'system (using cron for instance).',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   171
          'group': 'main', 'level': 3,
1160
77bf88f01fcc new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents: 136
diff changeset
   172
          }),
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   173
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        # email configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
        ('default-recipients-mode',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
         {'type' : 'choice',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
          'choices' : ('default-dest-addrs', 'users', 'none'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
          'default': 'default-dest-addrs',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
          'help': 'when a notification should be sent with no specific rules \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
to find recipients, recipients will be found according to this mode. Available \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
modes are "default-dest-addrs" (emails specified in the configuration \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
variable with the same name), "users" (every users which has activated \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
account with an email set), "none" (no notification).',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   184
          'group': 'email', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
        ('default-dest-addrs',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
         {'type' : 'csv',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
          'default': (),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
          'help': 'comma separated list of email addresses that will be used \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
as default recipient when an email is sent and the notification has no \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
specific recipient rules.',
5456
d040889fac4e merged back oldstable into stable
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5426 5428
diff changeset
   192
          'group': 'email', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
        ('supervising-addrs',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
         {'type' : 'csv',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
          'default': (),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
          'help': 'comma separated list of email addresses that will be \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
notified of every changes.',
5323
329b4f6d18b4 [config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5059
diff changeset
   199
          'group': 'email', 'level': 2,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
          }),
8211
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   201
         ('zmq-address-sub',
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   202
          {'type' : 'csv',
10233
f7dfcb3add15 [server] Make sure 'zmq-address-sub' config is always iterable
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9468
diff changeset
   203
           'default' : (),
8670
f02139297beb prefix "tcp://" zmq uris with "zmqpickle" (closes #2574114)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   204
           'help': ('List of ZMQ addresses to subscribe to (requires pyzmq) '
8993
82ffa4b68c9e [server] fix documentation of ZMQ options harder
Julien Cristau <julien.cristau@logilab.fr>
parents: 8991
diff changeset
   205
                    '(of the form `tcp://<ipaddr>:<port>`)'),
8211
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   206
           'group': 'zmq', 'level': 1,
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   207
           }),
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   208
         ('zmq-address-pub',
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   209
          {'type' : 'string',
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   210
           'default' : None,
8670
f02139297beb prefix "tcp://" zmq uris with "zmqpickle" (closes #2574114)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   211
           'help': ('ZMQ address to use for publishing (requires pyzmq) '
8993
82ffa4b68c9e [server] fix documentation of ZMQ options harder
Julien Cristau <julien.cristau@logilab.fr>
parents: 8991
diff changeset
   212
                    '(of the form `tcp://<ipaddr>:<port>`)'),
8211
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   213
           'group': 'zmq', 'level': 1,
543e1579ba0d [repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents: 7896
diff changeset
   214
           }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
        ) + CubicWebConfiguration.options)
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   216
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7301
diff changeset
   217
    # should we init the connections pool (eg connect to sources). This is
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7301
diff changeset
   218
    # usually necessary...
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7301
diff changeset
   219
    init_cnxset_pool = True
2959
daabb9bc5233 make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   220
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
    # read the schema from the database
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2107
diff changeset
   222
    read_instance_schema = True
5043
fe52dd3936cf [repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   223
    # set this to true to get a minimal repository, for instance to get cubes
fe52dd3936cf [repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   224
    # information on commands such as i18ninstance, db-restore, etc...
fe52dd3936cf [repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   225
    quick_start = False
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
    # check user's state at login time
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
    consider_user_state = True
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   228
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
    # should some hooks be deactivated during [pre|post]create script execution
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
    free_wheel = False
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   231
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
    # list of enables sources when sources restriction is necessary
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
    # (eg repository initialization at least)
6126
aca6a2c357fd [repository] enabled sources refactoring: to avoid error, we should always have all known source in repo.sources_by_uri and only enabled ones in repo.sources, so we still have access to the definition of temporarily disabled sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   234
    enabled_sources = None
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   235
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
    def bootstrap_cubes(self):
2633
bc9386c3b2c9 get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2493
diff changeset
   237
        from logilab.common.textutils import splitstrip
10614
57dfde80df11 [py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10589
diff changeset
   238
        for line in open(join(self.apphome, 'bootstrap_cubes')):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
            line = line.strip()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
            if not line or line.startswith('#'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
                continue
2633
bc9386c3b2c9 get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2493
diff changeset
   242
            self.init_cubes(self.expand_cubes(splitstrip(line)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
            break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
            # no cubes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
            self.init_cubes(())
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   247
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
    def write_bootstrap_cubes_file(self, cubes):
10614
57dfde80df11 [py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10589
diff changeset
   249
        stream = open(join(self.apphome, 'bootstrap_cubes'), 'w')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
        stream.write('# this is a generated file only used for bootstraping\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
        stream.write('# you should not have to edit this\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
        stream.write('%s\n' % ','.join(cubes))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
        stream.close()
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   254
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
    def sources_file(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
        return join(self.apphome, 'sources')
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   257
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
    # this method has to be cached since when the server is running using a
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
    # restricted user, this user usually don't have access to the sources
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
    # configuration file (#16102)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
    @cached
2105
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   262
    def read_sources_file(self):
9460
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   263
        """return a dictionary of values found in the sources file"""
7301
93e96700e0c0 [configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7129
diff changeset
   264
        return read_config(self.sources_file(), raise_if_unreadable=True)
2105
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   265
9460
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   266
    @property
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   267
    def system_source_config(self):
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   268
        return self.read_sources_file()['system']
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   269
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   270
    @property
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   271
    def default_admin_config(self):
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9165
diff changeset
   272
        return self.read_sources_file()['admin']
6126
aca6a2c357fd [repository] enabled sources refactoring: to avoid error, we should always have all known source in repo.sources_by_uri and only enabled ones in repo.sources, so we still have access to the definition of temporarily disabled sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5933
diff changeset
   273
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   274
    def source_enabled(self, source):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   275
        if self.sources_mode is not None:
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   276
            if 'migration' in self.sources_mode:
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   277
                assert len(self.sources_mode) == 1
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   278
                if source.connect_for_migration:
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   279
                    return True
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10301
diff changeset
   280
                print('not connecting to source', source.uri, 'during migration')
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   281
                return False
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   282
            if 'all' in self.sources_mode:
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   283
                assert len(self.sources_mode) == 1
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   284
                return True
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   285
            return source.uri in self.sources_mode
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   286
        if self.quick_start:
8613
9d792e9f1c79 [server config] on quick start, system source is still activated. Closes #2535714
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8350
diff changeset
   287
            return source.uri == 'system'
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   288
        return (not source.disabled and (
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   289
            not self.enabled_sources or source.uri in self.enabled_sources))
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   290
2105
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   291
    def write_sources_file(self, sourcescfg):
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   292
        """serialize repository'sources configuration into a INI like file"""
2105
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   293
        sourcesfile = self.sources_file()
2107
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
   294
        if exists(sourcesfile):
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
   295
            import shutil
6c4a4c514ac2 add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2105
diff changeset
   296
            shutil.copy(sourcesfile, sourcesfile + '.bak')
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   297
        stream = open(sourcesfile, 'w')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   298
        for section in ('admin', 'system'):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   299
            sconfig = sourcescfg[section]
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   300
            if isinstance(sconfig, dict):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   301
                # get a Configuration object
8988
6cd912702239 [server] fix error messages in write_sources_file()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8708
diff changeset
   302
                assert section == 'system', '%r is not system' % section
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   303
                _sconfig = SourceConfiguration(
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   304
                    self, options=SOURCE_TYPES['native'].options)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   305
                for attr, val in sconfig.items():
6670
e22bd5eb6ffd [c-c reset-admin-pwd] don't crash on unknown option, and silently ignore 'adapter' which may be present in pre 3.10 sources file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6627
diff changeset
   306
                    try:
e22bd5eb6ffd [c-c reset-admin-pwd] don't crash on unknown option, and silently ignore 'adapter' which may be present in pre 3.10 sources file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6627
diff changeset
   307
                        _sconfig.set_option(attr, val)
e22bd5eb6ffd [c-c reset-admin-pwd] don't crash on unknown option, and silently ignore 'adapter' which may be present in pre 3.10 sources file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6627
diff changeset
   308
                    except lgconfig.OptionError:
e22bd5eb6ffd [c-c reset-admin-pwd] don't crash on unknown option, and silently ignore 'adapter' which may be present in pre 3.10 sources file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6627
diff changeset
   309
                        # skip adapter, may be present on pre 3.10 instances
e22bd5eb6ffd [c-c reset-admin-pwd] don't crash on unknown option, and silently ignore 'adapter' which may be present in pre 3.10 sources file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6627
diff changeset
   310
                        if attr != 'adapter':
8988
6cd912702239 [server] fix error messages in write_sources_file()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8708
diff changeset
   311
                            self.error('skip unknown option %s in sources file' % attr)
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   312
                sconfig = _sconfig
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7398
diff changeset
   313
            stream.write('[%s]\n%s\n' % (section, generate_source_config(sconfig)))
2105
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   314
        restrict_perms_to_user(sourcesfile)
92ea410806fe refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   315
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   316
    def load_schema(self, expand_cubes=False, **kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
        from cubicweb.schema import CubicWebSchemaLoader
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
        if expand_cubes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
            # in case some new dependencies have been introduced, we have to
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
            # reinitialize cubes so the full filesystem schema is read
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
            origcubes = self.cubes()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
            self._cubes = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
            self.init_cubes(self.expand_cubes(origcubes))
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   324
        schema = CubicWebSchemaLoader().load(self, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
        if expand_cubes:
9165
7ebf3b1cdb4c Use the list of cubes from the filesystem when reading the schema from the filesystem
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9013
diff changeset
   326
            # restore original value
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
            self._cubes = origcubes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
        return schema
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   329
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
    def load_bootstrap_schema(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
        from cubicweb.schema import BootstrapSchemaLoader
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
        schema = BootstrapSchemaLoader().load(self)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
        schema.name = 'bootstrap'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
        return schema
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   335
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   336
    sources_mode = None
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
    def set_sources_mode(self, sources):
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   338
        self.sources_mode = sources
1666
bf4bdc601779 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   339
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
    def migration_handler(self, schema=None, interactive=True,
2493
9806571ea790 major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2489
diff changeset
   341
                          cnx=None, repo=None, connect=True, verbosity=None):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
        """return a migration handler instance"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
        from cubicweb.server.migractions import ServerMigrationHelper
2493
9806571ea790 major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2489
diff changeset
   344
        if verbosity is None:
9806571ea790 major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2489
diff changeset
   345
            verbosity = getattr(self, 'verbosity', 0)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
        return ServerMigrationHelper(self, schema, interactive=interactive,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
                                     cnx=cnx, repo=repo, connect=connect,
2493
9806571ea790 major refactoring of database dump/restore:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2489
diff changeset
   348
                                     verbosity=verbosity)