<s> from debile . utils . config import get_config <EOL> from contextlib import contextmanager <EOL> from importlib import import_module <EOL> from sqlalchemy import create_engine <EOL> from sqlalchemy . orm import sessionmaker <EOL> config = { } <EOL> Session = sessionmaker ( ) <EOL> fedmsg = None <EOL> def _init_config ( path ) : <EOL> config . update ( get_config ( name = "<STR_LIT>" , path = path ) ) <EOL> return config <EOL> def _init_sqlalchemy ( config ) : <EOL> engine = create_engine ( config [ '<STR_LIT>' ] , implicit_returning = False ) <EOL> Session . configure ( bind = engine ) <EOL> def _init_fedmsg ( config ) : <EOL> global fedmsg <EOL> if '<STR_LIT>' not in config : <EOL> return <EOL> try : <EOL> fedmsg = import_module ( "<STR_LIT>" ) <EOL> except : <EOL> return <EOL> fedmsg . init ( <EOL> topic_prefix = config [ '<STR_LIT>' ] . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> environment = config [ '<STR_LIT>' ] . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> sign_messages = config [ '<STR_LIT>' ] . get ( "<STR_LIT>" , False ) , <EOL> endpoints = config [ '<STR_LIT>' ] . get ( "<STR_LIT>" , { } ) , <EOL> ) <EOL> def init_master ( confpath = None , fedmsg = True ) : <EOL> c = _init_config ( confpath ) <EOL> _init_sqlalchemy ( c ) <EOL> if fedmsg : <EOL> _init_fedmsg ( c ) <EOL> return c <EOL> @ contextmanager <EOL> def session ( ) : <EOL> session_ = Session ( ) <EOL> if session_ . get_bind ( ) . driver == "<STR_LIT>" : <EOL> print ( "<STR_LIT>" ) <EOL> session_ . execute ( "<STR_LIT>" ) <EOL> try : <EOL> yield session_ <EOL> session_ . commit ( ) <EOL> except : <EOL> session_ . rollback ( ) <EOL> raise <EOL> finally : <EOL> session_ . close ( ) <EOL> def emit ( topic , modname , message ) : <EOL> modname = "<STR_LIT>" % ( modname ) <EOL> if fedmsg : <EOL> return fedmsg . publish ( topic = topic , modname = modname , msg = message ) </s>
