• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python dbengine.get_engine函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中toughlib.dbengine.get_engine函数的典型用法代码示例。如果您正苦于以下问题:Python get_engine函数的具体用法?Python get_engine怎么用?Python get_engine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_engine函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run

def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-manage', '--manage', action='store_true', default=False, dest='manage', help='run manage')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-port', '--port', type=int, default=0, dest='port', help='admin port')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-x', '--xdebug', action='store_true', default=False, dest='xdebug', help='xdebug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughnms.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    with open("/var/toughnms/token","wb") as tf:
        tf.write(md5(config.system.secret.encode('utf-8')).hexdigest())

    update_timezone(config)
    check_env(config)

    if args.debug or args.xdebug:
        config.defaults.debug = True

    if args.port > 0:
        config.server.port = int(args.port)

    if args.manage:
        from toughnms.console import admin_app
        admin_app.run(config,dbengine)
        reactor.run()

    if args.initdb:
        init_db.update(get_engine(config))
开发者ID:lxyjyy,项目名称:ToughNMS,代码行数:35,代码来源:toughctl.py


示例2: __init__

 def __init__(self, config, dbengine):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = mcache.Mcache()
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:7,代码来源:radiusd.py


示例3: __init__

    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config)
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        self.expire_notify_task = expire_notify.ExpireNotifyTask(config,self.db)
        self.ddns_update_task = ddns_update.DdnsUpdateTask(config,self.db)
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:7,代码来源:taskd.py


示例4: run

def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-admin', '--admin', action='store_true', default=False, dest='admin', help='run admin')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughtester.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    update_timezone(config)
    check_env(config)

    if args.debug:
        config.system.debug = True

    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    if args.admin:
        start_admin(config,dbengine=dbengine)
        start_authorized(config, dbengine)
        reactor.run()    


    elif args.initdb:
        start_initdb(config)

    else:
        parser.print_help()
开发者ID:talkincode,项目名称:toughtester,代码行数:31,代码来源:toughctl.py


示例5: __init__

    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config

        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/admin/login",
            template_path=os.path.join(os.path.dirname(toughradius.__file__), "views"),
            static_path=os.path.join(os.path.dirname(toughradius.__file__), "static"),
            xsrf_cookies=True,
            config=self.config,
            debug=self.config.system.debug,
            xheaders=True,
        )

        self.tp_lookup = TemplateLookup(
            directories=[settings['template_path']],
            default_filters=['decode.utf8'],
            input_encoding='utf-8',
            output_encoding='utf-8',
            encoding_errors='ignore',
            module_directory="/tmp/toughradius_admin"
        )

        self.db_engine = dbengine or get_engine(config)
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        self.session_manager = session.SessionManager(settings["cookie_secret"], self.db_engine, 600)

        redisconf = redis_conf(config)
        self.session_manager = redis_session.SessionManager(redisconf,settings["cookie_secret"], 600)
        self.mcache = redis_cache.CacheManager(redisconf,cache_name='RadiusManageCache-%s'%os.getpid())
        self.mcache.print_hit_stat(60)
        
        self.db_backup = DBBackup(models.get_metadata(self.db_engine), excludes=[
            'tr_online','system_session','system_cache','tr_ticket','tr_billing','tr_online_stat',
            'tr_flow_stat'
        ])

        self.aes = utils.AESCipher(key=self.config.system.secret)

        # cache event init
        dispatch.register(self.mcache)

        # app init_route
        load_handlers(handler_path=os.path.join(os.path.abspath(os.path.dirname(__file__))),
            pkg_prefix="toughradius.manage", excludes=['views','webserver','radius'])

        # app event init
        event_params= dict(dbengine=self.db_engine, mcache=self.mcache, aes=self.aes)
        dispatch.load_events(os.path.join(os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))),
            "toughradius.manage.events",event_params=event_params)

        permit.add_route(cyclone.web.StaticFileHandler, 
                            r"/admin/backup/download/(.*)",
                            u"下载数据",MenuSys, 
                            handle_params={"path": self.config.database.backup_path},
                            order=5.0005)
        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:58,代码来源:httpd.py


示例6: run

def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-manage', '--manage', action='store_true', default=False, dest='manage', help='run manage')
    parser.add_argument('-task', '--task', action='store_true', default=False, dest='task', help='run task')
    parser.add_argument('-auth', '--auth', action='store_true', default=False, dest='auth', help='run auth')
    parser.add_argument('-acct', '--acct', action='store_true', default=False, dest='acct', help='run acct')
    parser.add_argument('-worker', '--worker', action='store_true', default=False, dest='worker', help='run worker')
    parser.add_argument('-standalone', '--standalone', action='store_true', default=False, dest='standalone', help='run standalone')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughradius.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    update_timezone(config)
    check_env(config)

    if args.debug:
        config.defaults.debug = True

    if args.manage:
        httpd.run(config,dbengine)
        reactor.run()    

    elif args.auth:
        radiusd.run_auth(config)
        reactor.run()
    
    elif args.acct:
        radiusd.run_acct(config)
        reactor.run()

    elif args.worker:
        radiusd.run_worker(config,dbengine)
        reactor.run()   

    elif args.task:
        taskd.run(config,dbengine)
        reactor.run()

    elif args.standalone:
        httpd.run(config,dbengine)
        radiusd.run_auth(config)
        radiusd.run_acct(config)
        radiusd.run_worker(config,dbengine)
        taskd.run(config,dbengine)
        reactor.run()
        
    elif args.initdb:
        run_initdb(config)
    else:
        parser.print_help()
开发者ID:Evan-hu,项目名称:ToughRADIUS,代码行数:57,代码来源:toughctl.py


示例7: update

def update(config,force=False):
    try:
        db_engine = get_engine(config)
        print 'init test datat'
        db = scoped_session(sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
        inittest(db)
    except:
        import traceback
        traceback.print_exc()
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:9,代码来源:inittest.py


示例8: __init__

    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config)
        self.cache = cache.CacheManager(self.db_engine)
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        # init task
        self.expire_notify_task = expire_notify.ExpireNotifyTask(self)
        self.ddns_update_task = ddns_update.DdnsUpdateTask(self)
        self.radius_stat_task = radius_stat.RadiusStatTask(self)

        dispatch.register(radius_events.__call__(self.db_engine,self.cache))
开发者ID:kozora,项目名称:ToughRADIUS,代码行数:12,代码来源:taskd.py


示例9: __init__

 def __init__(self, config, dbengine):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = mcache.Mcache()
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-result'))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-message'))
     self.puller.onPull = self.process
     logger.info("init auth worker pusher : %s " % (self.pusher))
     logger.info("init auth worker puller : %s " % (self.puller))
开发者ID:niebaopeng,项目名称:ToughRADIUS,代码行数:12,代码来源:radiusd.py


示例10: __init__

 def __init__(self, config=None, dbengine=None, **kwargs):
     self.config = config
     self.db_engine = dbengine or get_engine(config,pool_size=20)
     self.aes = kwargs.pop("aes",None)
     self.cache = kwargs.pop("cache",CacheManager(redis_conf(config),cache_name='RadiusTaskCache-%s'%os.getpid()))
     self.cache.print_hit_stat(60)
     self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
     self.taskclss = []
     self.load_tasks()
     if not kwargs.get('standalone'):
         event_params= dict(dbengine=self.db_engine, mcache=self.cache,aes=self.aes)
         event_path = os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))
         dispatch.load_events(event_path,"toughradius.manage.events",event_params=event_params)
开发者ID:myapple,项目名称:ToughRADIUS,代码行数:13,代码来源:taskd.py


示例11: __init__

    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config,pool_size=20)
        self.cache = cache.CacheManager(self.db_engine,cache_name='RadiusTaskCache-%s'%os.getpid())
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        # init task
        self.expire_notify_task = expire_notify.ExpireNotifyTask(self)
        self.ddns_update_task = ddns_update.DdnsUpdateTask(self)
        self.radius_stat_task = radius_stat.RadiusStatTask(self)
        self.online_stat_task = online_stat.OnlineStatTask(self)
        self.flow_stat_task = flow_stat.FlowStatTask(self)

        dispatch.register(radius_events.__call__(self.db_engine,self.cache))
开发者ID:popoimm,项目名称:ToughRADIUS,代码行数:14,代码来源:taskd.py


示例12: update

def update(config):
    try:
        db_engine = get_engine(config)
        print 'starting update database...'
        metadata = models.get_metadata(db_engine)
        metadata.drop_all(db_engine)
        metadata.create_all(db_engine)
        print 'update database done'
        db = scoped_session(sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
        init_db(db)
    except:
        print 'initdb error, retry wait 5 second'
        time.sleep(5.0)
        update(config)
开发者ID:leigf,项目名称:ToughRADIUS,代码行数:14,代码来源:initdb.py


示例13: update

def update(config):
    try:
        db_engine = get_engine(config)
        if int(os.environ.get("DB_INIT", 1)) == 1:
            print 'starting update database...'
            metadata = models.get_metadata(db_engine)
            metadata.drop_all(db_engine)
            metadata.create_all(db_engine)
            print 'update database done'
            db = scoped_session(sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
            init_db(db)
    except:
        import traceback
        traceback.print_exc()
开发者ID:lxyjyy,项目名称:ToughRADIUS,代码行数:14,代码来源:initdb.py


示例14: __init__

    def __init__(self, config=None, dbengine=None, log=None, **kwargs):

        self.config = config
        self.syslog = log or logger.Logger(config)

        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/admin/login",
            template_path=os.path.join(os.path.dirname(__file__), "views"),
            static_path=os.path.join(os.path.dirname(toughradius.__file__), "static"),
            xsrf_cookies=True,
            config=config,
            debug=self.config.system.debug,
            xheaders=True,
        )

        self.tp_lookup = TemplateLookup(
            directories=[settings["template_path"]],
            default_filters=["decode.utf8"],
            input_encoding="utf-8",
            output_encoding="utf-8",
            encoding_errors="replace",
            module_directory="/tmp/admin",
        )

        self.db_engine = dbengine or get_engine(config)
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        self.session_manager = session.SessionManager(settings["cookie_secret"], self.db_engine, 600)
        self.mcache = cache.CacheManager(self.db_engine)
        self.db_backup = DBBackup(
            models.get_metadata(self.db_engine), excludes=["tr_online", "system_session", "system_cache", "tr_ticket"]
        )

        self.aes = utils.AESCipher(key=self.config.system.secret)

        permit.add_route(
            cyclone.web.StaticFileHandler,
            r"/backup/download/(.*)",
            u"下载数据",
            MenuSys,
            handle_params={"path": self.config.database.backup_path},
            order=1.0405,
        )

        self.init_route()

        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
开发者ID:davisldq,项目名称:ToughRADIUS,代码行数:47,代码来源:webserver.py


示例15: restoredb

def restoredb(config,restorefs):
    if not os.path.exists(restorefs):
        print 'backup file not exists'
    else:
        engine = get_engine(config)
        db = engine.connect()
        metadata = models.get_metadata(engine)
        with gzip.open(restorefs,'rb') as rfs:
            cache_datas = {}
            for line in rfs:
                try:
                    tabname, rdata = json.loads(line)

                    if tabname == 'table_names' and rdata:
                        for table_name in rdata:
                            print "clean table %s" % table_name
                            db.execute("delete from %s;" % table_name)
                        continue

                    if tabname not in cache_datas:
                        cache_datas[tabname] = [rdata]
                    else:
                        cache_datas[tabname].append(rdata)

                    if tabname in cache_datas and len(cache_datas[tabname]) >= 500:
                        print 'insert datas<%s> into %s' % (len(cache_datas[tabname]), tabname)
                        db.execute(metadata.tables[tabname].insert().values(cache_datas[tabname]))
                        del cache_datas[tabname]

                except:
                    print 'error data %s ...'% line
                    import traceback
                    traceback.print_exc()

            print "insert last data"
            for tname, tdata in cache_datas.iteritems():
                try:
                    print 'insert datas<%s> into %s' % (len(tdata), tname)
                    db.execute(metadata.tables[tname].insert().values(tdata))
                except:
                    print 'error data %s ...' % tdata
                    import traceback
                    traceback.print_exc()

            cache_datas.clear()

        db.close()
开发者ID:lanyeit,项目名称:toughwlan,代码行数:47,代码来源:backup.py


示例16: __init__

 def __init__(self, config=None, dbengine=None, **kwargs):
     self.config = config
     self.db_engine = dbengine or get_engine(config,pool_size=20)
     self.aes = kwargs.pop("aes",None)
     self.cache = kwargs.pop("cache",CacheManager(redis_conf(config),cache_name='RadiusTaskCache-%s'%os.getpid()))
     self.cache.print_hit_stat(60)
     self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
     # init task
     self.expire_notify_task = expire_notify.ExpireNotifyTask(self)
     self.ddns_update_task = ddns_update.DdnsUpdateTask(self)
     self.radius_stat_task = radius_stat.RadiusStatTask(self)
     self.online_stat_task = online_stat.OnlineStatTask(self)
     self.flow_stat_task = flow_stat.FlowStatTask(self)
     if not kwargs.get('standalone'):
         event_params= dict(dbengine=self.db_engine, mcache=self.cache,aes=self.aes)
         event_path = os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))
         dispatch.load_events(event_path,"toughradius.manage.events",event_params=event_params)
开发者ID:d1ves,项目名称:ToughRADIUS,代码行数:17,代码来源:taskd.py


示例17: run

def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-admin', '--admin', action='store_true', default=False, dest='admin', help='run admin')
    parser.add_argument('-portal', '--portal', action='store_true', default=False, dest='portal', help='run portal')
    parser.add_argument('-acagent', '--acagent', action='store_true', default=False, dest='acagent', help='run acagent')
    parser.add_argument('-standalone', '--standalone', action='store_true', default=False, dest='standalone', help='run standalone')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughwlan.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    update_timezone(config)
    check_env(config)

    if args.debug:
        config.system.debug = True

    syslog = logger.Logger(config)
    dbengine = get_engine(config)

    if args.admin:
        start_admin(config,dbengine=dbengine,log=syslog)
        reactor.run()    

    elif args.portal:
        start_portal(config,dbengine=dbengine,log=syslog)
        reactor.run()

    elif args.acagent:
        start_acagent(config,dbengine=dbengine,log=syslog)
        reactor.run()

    elif args.standalone:
        start_admin(config,dbengine=dbengine,log=syslog)
        start_portal(config,dbengine=dbengine,log=syslog)
        start_acagent(config,dbengine=dbengine,log=syslog)
        reactor.run()

    elif args.initdb:
        start_initdb(config)

    else:
        parser.print_help()
开发者ID:lanyeit,项目名称:toughwlan,代码行数:45,代码来源:toughctl.py


示例18: dumpdb

def dumpdb(config,dumpfs):
    _dir = os.path.split(dumpfs)[0]
    if not os.path.exists(_dir):
        os.makedirs(_dir)

    engine = get_engine(config)
    db = engine.connect()
    metadata = models.get_metadata(engine)
    with gzip.open(dumpfs, 'wb') as dumpfs:

        table_names = [_name for _name, _ in metadata.tables.items()]
        table_headers = ('table_names', table_names)
        dumpfs.write(json.dumps(table_headers, ensure_ascii=False).encode('utf-8'))
        dumpfs.write('\n')

        for _name,_table in metadata.tables.items():
            if _name in excludes:
                continue
            rows = db.execute(select([_table]))
            for rows in rows:
                obj = (_name, dict(rows.items()))
                dumpfs.write(json.dumps(obj,ensure_ascii=False).encode('utf-8'))
                dumpfs.write('\n')
    db.close()
开发者ID:lanyeit,项目名称:toughwlan,代码行数:24,代码来源:backup.py


示例19: run_initdb

def run_initdb(config):
    init_db.update(get_engine(config))
开发者ID:davislidaqing,项目名称:ToughRADIUS,代码行数:2,代码来源:toughctl.py


示例20: __init__

 def __init__(self, config, dbengine, log):
     self.config = config
     self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(toughradius.__file__), "dictionarys/dictionary"))
     self.syslog = log
     self.db_engine = dbengine or get_engine(config)
     self.mcache = mcache.Mcache()
开发者ID:davisldq,项目名称:ToughRADIUS,代码行数:6,代码来源:radiusd.py



注:本文中的toughlib.dbengine.get_engine函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dispatch.pub函数代码示例发布时间:2022-05-27
下一篇:
Python rules.len_of函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap