server/__init__.py
changeset 2593 16d9419a4a79
parent 2589 92f2bc945261
child 2595 e76bf303c6f2
equal deleted inserted replaced
2592:c97c4b56e6a0 2593:16d9419a4a79
    13 import sys
    13 import sys
    14 from os.path import join, exists
    14 from os.path import join, exists
    15 
    15 
    16 from logilab.common.modutils import LazyObject
    16 from logilab.common.modutils import LazyObject
    17 
    17 
       
    18 # server-side debugging #########################################################
       
    19 
    18 # server debugging flag
    20 # server debugging flag
    19 DEBUG = False
    21 DBG_RQL = 1 # rql execution information
       
    22 DBG_SQL = 2 # executed sql
       
    23 DBG_REPO = 4 # repository events
       
    24 DBG_MORE = 8 # repository events
       
    25 
       
    26 
       
    27 # 2: + executed sql
       
    28 # 3: + additional debug information
       
    29 DEBUG = 0
       
    30 def set_debug(debugmode):
       
    31     global DEBUG
       
    32     if not debugmode:
       
    33         DEBUG = 0
       
    34         return
       
    35     if isinstance(debugmode, basestring):
       
    36         debugmode = globals()[debugmode]
       
    37     DEBUG |= debugmode
       
    38 
       
    39 def debugged(func):
       
    40     """decorator to activate debug mode"""
       
    41     def wrapped(*args, **kwargs):
       
    42         global DEBUG
       
    43         DEBUG = True
       
    44         try:
       
    45             return func(*args, **kwargs)
       
    46         finally:
       
    47             DEBUG = False
       
    48     return wrapped
       
    49 
       
    50 
       
    51 # database initialization ######################################################
    20 
    52 
    21 def init_repository(config, interactive=True, drop=False, vreg=None):
    53 def init_repository(config, interactive=True, drop=False, vreg=None):
    22     """initialise a repository database by creating tables add filling them
    54     """initialise a repository database by creating tables add filling them
    23     with the minimal set of entities (ie at least the schema, base groups and
    55     with the minimal set of entities (ie at least the schema, base groups and
    24     a initial user)
    56     a initial user)
   158     mhandler.exec_event_script('post%s' % event)
   190     mhandler.exec_event_script('post%s' % event)
   159     # execute cubes'post<event> script if any
   191     # execute cubes'post<event> script if any
   160     for path in reversed(paths):
   192     for path in reversed(paths):
   161         mhandler.exec_event_script('post%s' % event, path)
   193         mhandler.exec_event_script('post%s' % event, path)
   162 
   194 
   163 def set_debug(debugmode):
       
   164     global DEBUG
       
   165     DEBUG = debugmode
       
   166 
       
   167 def debugged(func):
       
   168     """decorator to activate debug mode"""
       
   169     def wrapped(*args, **kwargs):
       
   170         global DEBUG
       
   171         DEBUG = True
       
   172         try:
       
   173             return func(*args, **kwargs)
       
   174         finally:
       
   175             DEBUG = False
       
   176     return wrapped
       
   177 
   195 
   178 # sqlite'stored procedures have to be registered at connexion opening time
   196 # sqlite'stored procedures have to be registered at connexion opening time
   179 SQL_CONNECT_HOOKS = {}
   197 SQL_CONNECT_HOOKS = {}
   180 
   198 
   181 # add to this set relations which should have their add security checking done
   199 # add to this set relations which should have their add security checking done