server/__init__.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 09 Mar 2010 11:05:29 +0100
changeset 4845 dc351b96f596
parent 4834 b718626a0e60
parent 4837 54969eec48eb
child 4848 41f84eea63c9
permissions -rw-r--r--
backport stable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""Server subcube of cubicweb : defines objects used only on the server
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
(repository) side
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
This module contains functions to initialize a new repository.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
:organization: Logilab
4212
ab6573088b4a update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3903
diff changeset
     7
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1802
diff changeset
     9
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
"""
4834
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
    11
from __future__ import with_statement
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
    12
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
import sys
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
from os.path import join, exists
2730
bb6fcb8c5d71 to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2633
diff changeset
    17
from glob import glob
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
from logilab.common.modutils import LazyObject
2633
bc9386c3b2c9 get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2631
diff changeset
    20
from logilab.common.textutils import splitstrip
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
2730
bb6fcb8c5d71 to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2633
diff changeset
    22
from yams import BASE_GROUPS
bb6fcb8c5d71 to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2633
diff changeset
    23
bb6fcb8c5d71 to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2633
diff changeset
    24
from cubicweb import CW_SOFTWARE_ROOT
bb6fcb8c5d71 to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2633
diff changeset
    25
2593
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    26
# server-side debugging #########################################################
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    27
2628
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    28
# server debugging flags. They may be combined using binary operators.
2766
07e47b84acc2 DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    29
DBG_NONE = 0  # no debug information
07e47b84acc2 DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    30
DBG_RQL = 1   # rql execution information
07e47b84acc2 DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    31
DBG_SQL = 2   # executed sql
07e47b84acc2 DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    32
DBG_REPO = 4  # repository events
07e47b84acc2 DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    33
DBG_MS = 8    # multi-sources
3823
94aa250cff9b fix cut and paste
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3699
diff changeset
    34
DBG_MORE = 16 # more verbosity
4223
4fb00ccad3df new DBG_ALL debug level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4107
diff changeset
    35
DBG_ALL = 1 + 2 + 4 + 8 + 16
2628
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    36
# current debug mode
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    37
DEBUG = 0
2593
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    38
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    39
def set_debug(debugmode):
2628
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    40
    """change the repository debugging mode"""
2593
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    41
    global DEBUG
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    42
    if not debugmode:
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    43
        DEBUG = 0
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    44
        return
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    45
    if isinstance(debugmode, basestring):
2633
bc9386c3b2c9 get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2631
diff changeset
    46
        for mode in splitstrip(debugmode, sep='|'):
2628
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    47
            DEBUG |= globals()[mode]
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    48
    else:
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    49
        DEBUG |= debugmode
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    50
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    51
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    52
class debugged(object):
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    53
    """repository debugging context manager / decorator
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    54
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    55
    Can be used either as a context manager:
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    56
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    57
    >>> with debugged(server.DBG_RQL | server.DBG_REPO):
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    58
    ...     # some code in which you want to debug repository activity,
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    59
    ...     # seing information about RQL being executed an repository events.
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    60
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    61
    or as a function decorator:
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    62
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    63
    >>> @debugged(server.DBG_RQL | server.DBG_REPO)
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    64
    ... def some_function():
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    65
    ...     # some code in which you want to debug repository activity,
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    66
    ...     # seing information about RQL being executed an repository events
2593
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    67
2628
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    68
    debug mode will be reseted at its original value when leaving the "with"
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    69
    block or the decorated function
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    70
    """
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    71
    def __init__(self, debugmode):
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    72
        self.debugmode = debugmode
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    73
        self._clevel = None
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    74
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    75
    def __enter__(self):
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    76
        """enter with block"""
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    77
        self._clevel = DEBUG
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    78
        set_debug(self.debugmode)
2593
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    79
2628
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    80
    def __exit__(self, exctype, exc, traceback):
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    81
        """leave with block"""
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    82
        set_debug(self._clevel)
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    83
        return traceback is None
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    84
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    85
    def __call__(self, func):
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    86
        """decorate function"""
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    87
        def wrapped(*args, **kwargs):
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    88
            _clevel = DEBUG
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    89
            set_debug(self.debugmode)
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    90
            try:
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    91
                return func(*args, **kwargs)
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    92
            finally:
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    93
                set_debug(self._clevel)
a2cc32c1d982 document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2595
diff changeset
    94
        return wrapped
2593
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    95
16d9419a4a79 F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2589
diff changeset
    96
# database initialization ######################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
4612
d6ae30c5d055 added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    98
def create_user(session, login, pwd, *groups):
d6ae30c5d055 added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    99
    # monkey patch this method if you want to customize admin/anon creation
d6ae30c5d055 added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   100
    # (that maybe necessary if you change CWUser's schema)
4634
b2a3232783f8 fix create_user function introduced in d6ae30c5d055 for database initialization: messup admin user groups when anon is created due to missing restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4612
diff changeset
   101
    user = session.create_entity('CWUser', login=login, upassword=pwd)
4612
d6ae30c5d055 added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   102
    for group in groups:
4634
b2a3232783f8 fix create_user function introduced in d6ae30c5d055 for database initialization: messup admin user groups when anon is created due to missing restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4612
diff changeset
   103
        session.execute('SET U in_group G WHERE U eid %(u)s, G name %(group)s',
b2a3232783f8 fix create_user function introduced in d6ae30c5d055 for database initialization: messup admin user groups when anon is created due to missing restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4612
diff changeset
   104
                        {'u': user.eid, 'group': group})
b2a3232783f8 fix create_user function introduced in d6ae30c5d055 for database initialization: messup admin user groups when anon is created due to missing restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4612
diff changeset
   105
    return user
4612
d6ae30c5d055 added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   106
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
def init_repository(config, interactive=True, drop=False, vreg=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
    """initialise a repository database by creating tables add filling them
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
    with the minimal set of entities (ie at least the schema, base groups and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
    a initial user)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
    from cubicweb.dbapi import in_memory_cnx
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
    from cubicweb.server.repository import Repository
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
    from cubicweb.server.utils import manager_userpasswd
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
    from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
    # configuration to avoid db schema loading and user'state checking
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
    # on connection
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2458
diff changeset
   118
    read_instance_schema = config.read_instance_schema
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
    bootstrap_schema = config.bootstrap_schema
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2458
diff changeset
   120
    config.read_instance_schema = False
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    config.creating = True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
    config.bootstrap_schema = True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
    config.consider_user_state = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
    config.set_language = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
    # only enable the system source at initialization time + admin which is not
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
    # an actual source but contains initial manager account information
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
    config.enabled_sources = ('system', 'admin')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
    repo = Repository(config, vreg=vreg)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
    assert len(repo.sources) == 1, repo.sources
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
    schema = repo.schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
    sourcescfg = config.sources()
2396
8bfb99d7bbcc [cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2395
diff changeset
   132
    _title = '-> creating tables '
8bfb99d7bbcc [cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2395
diff changeset
   133
    print _title,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
    source = sourcescfg['system']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
    driver = source['db-driver']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
    sqlcnx = repo.system_source.get_connection()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    sqlcursor = sqlcnx.cursor()
2306
95da5d9f0870 give session to doexec so it's able to rollback the connection on unexpected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2172
diff changeset
   138
    execute = sqlcursor.execute
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
    if drop:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        dropsql = sqldropschema(schema, driver)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
            sqlexec(dropsql, execute)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
        except Exception, ex:
2394
92bba46b853f [cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2306
diff changeset
   144
            print '-> drop failed, skipped (%s).' % ex
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
            sqlcnx.rollback()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
    # schema entities and relations tables
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
    # can't skip entities table even if system source doesn't support them,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    # they are used sometimes by generated sql. Keeping them empty is much
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
    # simpler than fixing this...
4837
54969eec48eb misc fixes to ensure logilab.db compatibility
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4759
diff changeset
   150
    schemasql = sqlschema(schema, driver)
54969eec48eb misc fixes to ensure logilab.db compatibility
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4759
diff changeset
   151
    #skip_entities=[str(e) for e in schema.entities()
54969eec48eb misc fixes to ensure logilab.db compatibility
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4759
diff changeset
   152
    #               if not repo.system_source.support_entity(str(e))])
2396
8bfb99d7bbcc [cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2395
diff changeset
   153
    sqlexec(schemasql, execute, pbtitle=_title)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    sqlcursor.close()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    sqlcnx.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
    sqlcnx.close()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
    session = repo.internal_session()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
        login = unicode(sourcescfg['admin']['login'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
        pwd = sourcescfg['admin']['password']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
    except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
        if interactive:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
            msg = 'enter login and password of the initial manager account'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
            login, pwd = manager_userpasswd(msg=msg, confirm=True)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
            login, pwd = unicode(source['db-user']), source['db-password']
2394
92bba46b853f [cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2306
diff changeset
   167
    print '-> inserting default user and default groups.'
2595
e76bf303c6f2 [F server test] sort for test predictability
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2593
diff changeset
   168
    # sort for eid predicatability as expected in some server tests
e76bf303c6f2 [F server test] sort for test predictability
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2593
diff changeset
   169
    for group in sorted(BASE_GROUPS):
2631
90dd26e61361 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2628
diff changeset
   170
        session.execute('INSERT CWGroup X: X name %(name)s',
90dd26e61361 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2628
diff changeset
   171
                        {'name': unicode(group)})
4612
d6ae30c5d055 added a function to create admin/anon user during db initialization process so one get a chance to monkey patch it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   172
    create_user(session, login, pwd, 'managers')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    session.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    # reloging using the admin user
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
    config._cubes = None # avoid assertion error
3647
2941f4a0aab9 refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3530
diff changeset
   176
    repo, cnx = in_memory_cnx(config, login, password=pwd)
3699
20ba545e00e1 initialize entity classes in repository initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3530
diff changeset
   177
    # trigger vreg initialisation of entity classes
20ba545e00e1 initialize entity classes in repository initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3530
diff changeset
   178
    config.cubicweb_appobject_path = set(('entities',))
20ba545e00e1 initialize entity classes in repository initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3530
diff changeset
   179
    config.cube_appobject_path = set(('entities',))
20ba545e00e1 initialize entity classes in repository initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3530
diff changeset
   180
    repo.vreg.set_schema(repo.schema)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
    assert len(repo.sources) == 1, repo.sources
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
    handler = config.migration_handler(schema, interactive=False,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
                                       cnx=cnx, repo=repo)
3903
7967d3766ecf fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3823
diff changeset
   184
    # install additional driver specific sql files
7967d3766ecf fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3823
diff changeset
   185
    handler.install_custom_sql_scripts(join(CW_SOFTWARE_ROOT, 'schemas'), driver)
7967d3766ecf fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3823
diff changeset
   186
    for directory in reversed(config.cubes_path()):
7967d3766ecf fix #544758 by calling custom sql scripts in add_cubes.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3823
diff changeset
   187
        handler.install_custom_sql_scripts(join(directory, 'schema'), driver)
4759
af2e6c377c71 cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4634
diff changeset
   188
    # serialize the schema
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
    initialize_schema(config, schema, handler)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
    # yoo !
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
    cnx.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
    config.enabled_sources = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
    for uri, source_config in config.sources().items():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
        if uri in ('admin', 'system'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
            # not an actual source or init_creating already called
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
            continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
        source = repo.get_source(uri, source_config)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
        source.init_creating()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
    cnx.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
    cnx.close()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
    session.close()
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4759
diff changeset
   202
    repo.shutdown()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
    # restore initial configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
    config.creating = False
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2458
diff changeset
   205
    config.read_instance_schema = read_instance_schema
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
    config.bootstrap_schema = bootstrap_schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
    config.consider_user_state = True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
    config.set_language = True
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2458
diff changeset
   209
    print '-> database for instance %s initialized.' % config.appid
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
def initialize_schema(config, schema, mhandler, event='create'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
    from cubicweb.server.schemaserial import serialize_schema
4834
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   214
    from cubicweb.server.session import hooks_control
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   215
    session = mhandler.session
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
    paths = [p for p in config.cubes_path() + [config.apphome]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
             if exists(join(p, 'migration'))]
4834
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   218
    # deactivate every hooks but those responsible to set metadata
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   219
    # so, NO INTEGRITY CHECKS are done, to have quicker db creation
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   220
    with hooks_control(session, session.HOOKS_DENY_ALL, 'metadata'):
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   221
        # execute cubicweb's pre<event> script
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   222
        mhandler.exec_event_script('pre%s' % event)
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   223
        # execute cubes pre<event> script if any
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   224
        for path in reversed(paths):
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   225
            mhandler.exec_event_script('pre%s' % event, path)
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   226
        # enter instance'schema into the database
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   227
        session.set_pool()
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   228
        serialize_schema(session, schema)
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   229
        # execute cubicweb's post<event> script
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   230
        mhandler.exec_event_script('post%s' % event)
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   231
        # execute cubes'post<event> script if any
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   232
        for path in reversed(paths):
b718626a0e60 move hooks activation control on session object, so we can have a per transaction control. Added a new `hooks_control` context manager for usual modification of hooks activation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4831
diff changeset
   233
            mhandler.exec_event_script('post%s' % event, path)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
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: 4766
diff changeset
   236
# sqlite'stored procedures have to be registered at connection opening time
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: 4766
diff changeset
   237
from logilab.db import SQL_CONNECT_HOOKS
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
# add to this set relations which should have their add security checking done
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
# *BEFORE* adding the actual relation (done after by default)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
BEFORE_ADD_RELATIONS = set(('owned_by',))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
# add to this set relations which should have their add security checking done
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
# *at COMMIT TIME* (done after by default)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
ON_COMMIT_ADD_RELATIONS = set(())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
# available sources registry
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
SOURCE_TYPES = {'native': LazyObject('cubicweb.server.sources.native', 'NativeSQLSource'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
                # XXX private sources installed by an external cube
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
                'pyrorql': LazyObject('cubicweb.server.sources.pyrorql', 'PyroRQLSource'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
                'ldapuser': LazyObject('cubicweb.server.sources.ldapuser', 'LDAPUserSource'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
                }