Vocabulary

This commit is contained in:
Emmanuel Garette 2019-12-02 10:45:07 +01:00 committed by Benjamin Bohard
parent b944a609a5
commit a152654b5b
3 changed files with 44 additions and 1 deletions

View File

@ -8,3 +8,19 @@ CONFIGURATION_DIR = 'configurations'
TEMPLATE_DIR = 'templates'
TMP_DIR = 'tmp'
ROUGAIL_DTD_PATH = '../rougail/data/creole.dtd'
POSTGRESQL_ADDRESS = 'localhost'
POSTGRESQL_PORT = 5432
def get_config():
return {'database': {'host': 'localhost',
'port': 5432,
'dbname': 'risotto',
'user': 'risotto',
'password': 'risotto',
},
'http_server': {'port': 8080},
'global': {'message_root_path': 'messages',
'debug': False,
'internal_user': 'internal',
'rougail_dtd_path': '../rougail/data/creole.dtd'}
}

21
src/risotto/database.py Normal file
View File

@ -0,0 +1,21 @@
import psycopg2
KEY_DATABASE_NAME = 'dbname'
KEY_DATABASE_USER = 'user'
KEY_DATABASE_PASSWORD = 'password'
KEY_DATABASE_HOST = 'host'
def connect(conf, database_options=None):
if database_options is None:
option = conf.option['database']
database_options = {
'host': option[KEY_DATABASE_HOST],
'dbname': option[KEY_DATABASE_NAME],
'user': option[KEY_DATABASE_USER],
'password': option[KEY_DATABASE_PASSWORD]
}
if not database_options['host']:
raise Exception('cannot find postgresql')
return psycopg2.connect(**database_options)

View File

@ -7,9 +7,12 @@ from .utils import _
from .error import CallError, NotAllowedError
from .logger import log
from .config import DEBUG
from .config import get_config
from .context import Context
from . import register
def connect(db_conf):
return psycopg2.connect(**db_conf)
class CallDispatcher:
def valid_public_function(self,
@ -94,11 +97,14 @@ class CallDispatcher:
risotto_context.function = obj['function']
if obj['risotto_context']:
kw['risotto_context'] = risotto_context
if obj['database']:
db_conf = get_config.get('database')
risotto_context.db_cursor = await connect(db_conf).cursor()
returns = await risotto_context.function(self.injected_self[obj['module']], **kw)
except CallError as err:
raise err
except Exception as err:
if DEBUG:
if get_config().get('global').get('debug'):
print_exc()
log.error_msg(risotto_context,
kwargs,