def update(config): print 'starting update database...' try: db_engine = get_engine(config) 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()
def __init__(self, config=None, dbengine=None, **kwargs): self.config = config self.db_engine = dbengine settings = dict( cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=", login_url="/login", template_path=os.path.join(os.path.dirname(toughtester.__file__), "views"), static_path=os.path.join(os.path.dirname(toughtester.__file__), "static"), xsrf_cookies=True, config=self.config, db_engine=self.db_engine, debug=self.config.system.debug, xheaders=True, ) self.cache = CacheManager(**parse_cache_config_options({ 'cache.type': 'file', 'cache.data_dir': '/tmp/cache/data', 'cache.lock_dir': '/tmp/cache/lock' })) 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") self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False)) self.session_manager = session.SessionManager(settings["cookie_secret"], self.db_engine, 86400) self.mcache = cache.CacheManager(self.db_engine) self.db_backup = DBBackup(models.get_metadata(self.db_engine), excludes=['system_session','system_cache']) permit.add_route(cyclone.web.StaticFileHandler, r"/backup/download/(.*)", u"下载数据", u"系统管理", handle_params={"path": self.config.database.backup_path}, order=1.0405) self.init_route() cyclone.web.Application.__init__(self, permit.all_handlers, **settings)