예제 #1
0
파일: postgres.py 프로젝트: efphe/mother
def init_postgres(vars):
    try:
        _PostgresInfo.dbuser= vars['DB_USER']
    except:
        Speaker.log_int_raise('Variable %s not specified!', ERR_COL('DB_USER'))
    try:
        _PostgresInfo.dbname= vars['DB_NAME']
    except:
        Speaker.log_int_raise('Variable %s not specified!', ERR_COL('DB_NAME'))
    
    _PostgresInfo.dbpasswd= vars.get('DB_PASSWD', '')
    _PostgresInfo.dbhost= vars.get('DB_HOST', 'localhost')
    _PostgresInfo.dbport= vars.get('DB_PORT', 5432)
예제 #2
0
파일: abdbda.py 프로젝트: efphe/mother
    def export_iface(where):

        if not DbOne._db_initialized:
            err= ERR_COL('!!!No Session Available!!!')
            Speaker.log_int_raise("%s You are using the Db Pool, you "
                               "have disabled the persistent connection, "
                               "but no session was used to initialize this "
                               "Mother class", err)

        for attr in DbOne._exported_methods:
            setattr(where, attr, getattr(DbOne, attr))

        mog= getattr(DbOne, 'mogrify', None)
        if mog:
            setattr(where, 'mogrify', mog)
예제 #3
0
파일: abdbda.py 프로젝트: efphe/mother
    def newSession(name= None):

        Speaker.log_info("Initializing session %s", INF_COL(name))

        if not MotherPool._pool_initialized:
            return DbFly(name)

        m= MotherPool._pool_get_mutex
        m.acquire()

        try:
            session= MotherPool._get_session()

        except Exception, ss:
            m.release()
            Speaker.log_int_raise(
                    "Cannot retrieve Session from Pool (%s). FATAL.", 
                    ERR_COL(ss))
예제 #4
0
파일: abdbda.py 프로젝트: efphe/mother
    def return_filter(self):
        pre= self.pre_filter
        post= self.post_filter

        if len(pre) > 1 or len(post) > 1:
            Speaker.log_int_raise('Cannot handle Filter: pre, post= %s, %s', 
                    ERR_COL(pre), ERR_COL(post))

        if pre: f= pre[0]
        else:   f= '' 

        strfilter= self.strfilter
        if len(strfilter):
            strfilter= _A(strfilter)
            strfilter= ('WHERE' in strfilter or 'WHERE' in f )  \
                               and 'AND %s' % strfilter         \
                               or  'WHERE %s' % strfilter
            f= '%s %s' % (f, strfilter)

        if post:
            f= '%s %s' % (f, post[0])

        return f, self.locals
예제 #5
0
파일: abdbda.py 프로젝트: efphe/mother
    def _do_query(s, ftr= None, result= True):

        execattr= result and DbOne._gquery or DbOne._qquery

        if not ftr:
            d= {}
        elif isinstance(ftr, MoFilter):
            s, d= ftr.return_ftrqry(s)
        elif isinstance(ftr, dict):
            d= ftr
        elif isinstance(ftr, tuple):
            d= ftr
        else:
            Speaker.log_int_raise('Invalid Filter Type: %s', 
                    ERR_COL(type(ftr)))

        # logging info...
        mogrify= getattr(DbOne._iface_instance, '_mogrify', None)
        try:
            Speaker.log_debug("QSQL- %s", mogrify(s, d))
        except:
            Speaker.log_debug("QSQL- %s, Filter= %s", s, d)

        return DbOne._safe_execute(execattr, s, d)
예제 #6
0
파일: abdbda.py 프로젝트: efphe/mother
            execfile(conf, names_dict, loc)
        except Exception, ss:
            err= "Unable to read Mother configuration "  \
                 "file %s: %s" % (ERR_COL(conf), ss)
    else:
        loc= conf

    loc.update(forced)

    if hasattr(Speaker, '_spkr_initialized'):
        from mother.speaker import init_speaker
        init_speaker(loc)

    # now that speaker is up, error is printable
    if err:
        Speaker.log_int_raise(err)

    # set the right db engine
    db_engine= loc.get('DB_ENGINE', DB_ENGINE_PGRES)
    if db_engine == DB_ENGINE_PGRES:
        from mother.postgres import MotherPostgres as _builder, \
                                     init_postgres as init_engine
        _DbInfo.arg_format= '%%(%s)s'
    elif db_engine == DB_ENGINE_SQLITE:
        from mother.sqlite import MotherSqlite as _builder, \
                                   init_sqlite as init_engine
        _DbInfo.arg_format= ':%s'

    init_engine(loc)
    _DbInfo.iface_builder= _builder
예제 #7
0
파일: sqlite.py 프로젝트: efphe/mother
def init_sqlite(vars):
    try:
        _SqliteInfo.dbfile= vars['DB_FILE']
    except:
        Speaker.log_int_raise('Variable %s not specified!', ERR_COL('DB_FILE'))