--- a/cubicweb/server/__init__.py Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/server/__init__.py Fri Jul 08 09:59:18 2016 +0200
@@ -24,9 +24,6 @@
__docformat__ = "restructuredtext en"
-import sys
-from os.path import join, exists
-from glob import glob
from contextlib import contextmanager
from six import text_type, string_types
@@ -39,9 +36,9 @@
from yams import BASE_GROUPS
-from cubicweb import CW_SOFTWARE_ROOT
from cubicweb.appobject import AppObject
+
class ShuttingDown(BaseException):
"""raised when trying to access some resources while the repository is
shutting down. Inherit from BaseException so that `except Exception` won't
@@ -90,7 +87,7 @@
#: more verbosity
DBG_MORE = 128
#: all level enabled
-DBG_ALL = DBG_RQL + DBG_SQL + DBG_REPO + DBG_MS + DBG_HOOKS + DBG_OPS + DBG_SEC + DBG_MORE
+DBG_ALL = DBG_RQL + DBG_SQL + DBG_REPO + DBG_MS + DBG_HOOKS + DBG_OPS + DBG_SEC + DBG_MORE
_SECURITY_ITEMS = []
_SECURITY_CAPS = ['read', 'add', 'update', 'delete', 'transition']
@@ -98,6 +95,7 @@
#: current debug mode
DEBUG = 0
+
@contextmanager
def tunesecurity(items=(), capabilities=()):
"""Context manager to use in conjunction with DBG_SEC.
@@ -136,6 +134,7 @@
_SECURITY_ITEMS[:] = olditems
_SECURITY_CAPS[:] = oldactions
+
def set_debug(debugmode):
"""change the repository debugging mode"""
global DEBUG
@@ -148,6 +147,7 @@
else:
DEBUG |= debugmode
+
class debugged(object):
"""Context manager and decorator to help debug the repository.
@@ -184,7 +184,6 @@
def __call__(self, func):
"""decorate function"""
def wrapped(*args, **kwargs):
- _clevel = DEBUG
set_debug(self.debugmode)
try:
return func(*args, **kwargs)
@@ -192,6 +191,7 @@
set_debug(self._clevel)
return wrapped
+
# database initialization ######################################################
def create_user(session, login, pwd, *groups):
@@ -203,6 +203,7 @@
{'u': user.eid, 'group': text_type(group)})
return user
+
def init_repository(config, interactive=True, drop=False, vreg=None,
init_config=None):
"""initialise a repository database by creating tables add filling them
@@ -289,18 +290,18 @@
cnx.create_entity('CWGroup', name=text_type(group))
admin = create_user(cnx, login, pwd, u'managers')
cnx.execute('SET X owned_by U WHERE X is IN (CWGroup,CWSource), U eid %(u)s',
- {'u': admin.eid})
+ {'u': admin.eid})
cnx.commit()
repo.shutdown()
# re-login using the admin user
- config._cubes = None # avoid assertion error
+ config._cubes = None # avoid assertion error
repo = get_repository(config=config)
# replace previous schema by the new repo's one. This is necessary so that we give the proper
# schema to `initialize_schema` above since it will initialize .eid attribute of schema elements
schema = repo.schema
with connect(repo, login, password=pwd) as cnx:
with cnx.security_enabled(False, False):
- repo.system_source.eid = ssource.eid # redo this manually
+ repo.system_source.eid = ssource.eid # redo this manually
handler = config.migration_handler(schema, interactive=False,
cnx=cnx, repo=repo)
# serialize the schema
@@ -348,7 +349,7 @@
# sqlite'stored procedures have to be registered at connection opening time
-from logilab.database import SQL_CONNECT_HOOKS
+from logilab.database import SQL_CONNECT_HOOKS # noqa
# add to this set relations which should have their add security checking done
# *BEFORE* adding the actual relation (done after by default)