def make_app(): init_calibre() import handlers from calibre.db.legacy import LibraryDatabase from calibre.utils.date import fromtimestamp auth_db_path = CONF['user_database'] logging.info("Init library with [%s]" % options.with_library) logging.info("Init AuthDB with [%s]" % auth_db_path) logging.info("Init Static with [%s]" % CONF['static_path']) logging.info("Init HTML with [%s]" % CONF['html_path']) book_db = LibraryDatabase(os.path.expanduser(options.with_library)) cache = book_db.new_api # hook 1: 按字母作为第一级目录,解决书库子目录太多的问题 if CONF['BOOK_NAMES_FORMAT'].lower() == 'utf8': bind_utf8_book_names(cache) else: bind_topdir_book_names(cache) # hook 2: don't force GUI from calibre import gui2 old_must_use_qt = gui2.must_use_qt def new_must_use_qt(headless=True): try: old_must_use_qt(headless) except: pass gui2.must_use_qt = new_must_use_qt # build sql session factory engine = create_engine(auth_db_path, echo=False) ScopedSession = scoped_session( sessionmaker(bind=engine, autoflush=True, autocommit=False)) models.bind_session(ScopedSession) init_social(models.Base, ScopedSession, CONF) if options.syncdb: models.user_syncdb(engine) logging.info("Create tables into DB") sys.exit(0) path = CONF['static_path'] + '/calibre/default_cover.jpg' with open(path, 'rb') as cover_file: default_cover = cover_file.read() app_settings = dict(CONF) app_settings.update({ "legacy": book_db, "cache": cache, "ScopedSession": ScopedSession, "build_time": fromtimestamp(os.stat(path).st_mtime), "default_cover": default_cover, }) logging.info("Now, Running...") return web.Application( social_routes.SOCIAL_AUTH_ROUTES + handlers.routes(), **app_settings)
def make_app(): try: import local_settings settings.update(local_settings.settings) except Exception as e: logging.error("read local_settings fail") pass init_calibre() import handlers from calibre.db.legacy import LibraryDatabase auth_db_path = settings['user_database'] logging.info("Init library with [%s]" % options.with_library) logging.info("Init AuthDB with [%s]" % auth_db_path) logging.info("Init Static with [%s]" % settings['static_path']) logging.info("Init LANG with [%s]" % P('localization/locales.zip')) book_db = LibraryDatabase(os.path.expanduser(options.with_library)) cache = book_db.new_api Base = declarative_base() engine = create_engine(auth_db_path, echo=False) session = scoped_session( sessionmaker(bind=engine, autoflush=True, autocommit=False)) init_social(Base, session, settings) models.bind_session(session) load_calibre_translations() if options.syncdb: models.user_syncdb(engine) sys.exit(0) if options.test: from test import email email.do_send_mail() sys.exit(0) settings.update({ "legacy": book_db, "cache": cache, "session": session, }) return web.Application(SOCIAL_AUTH_ROUTES + handlers.routes(), **settings)
def make_app(): init_calibre() import handlers from calibre.db.legacy import LibraryDatabase from calibre.utils.date import fromtimestamp auth_db_path = CONF['user_database'] logging.info("Init library with [%s]" % options.with_library) logging.info("Init AuthDB with [%s]" % auth_db_path ) logging.info("Init Static with [%s]" % CONF['static_path'] ) logging.info("Init HTML with [%s]" % CONF['html_path'] ) logging.info("Init LANG with [%s]" % P('localization/locales.zip') ) book_db = LibraryDatabase(os.path.expanduser(options.with_library)) cache = book_db.new_api # hook 1: 按字母作为第一级目录,解决书库子目录太多的问题 old_construct_path_name = cache.backend.construct_path_name def new_construct_path_name(*args, **kwargs): s = old_construct_path_name(*args, **kwargs) ns = s[0] + "/" + s logging.debug("new str = %s" % ns) return ns cache.backend.construct_path_name = new_construct_path_name # hook 2: don't force GUI from calibre import gui2 old_must_use_qt = gui2.must_use_qt def new_must_use_qt(headless=True): try: old_must_use_qt(headless) except: pass gui2.must_use_qt = new_must_use_qt # build sql session factory engine = create_engine(auth_db_path, echo=False) ScopedSession = scoped_session(sessionmaker(bind=engine, autoflush=True, autocommit=False)) models.bind_session(ScopedSession) init_social(models.Base, ScopedSession, CONF) if options.syncdb: models.user_syncdb(engine) logging.info("Create tables into DB") sys.exit(0) path = CONF['static_path'] + '/calibre/default_cover.jpg' app_settings = dict(CONF) app_settings.update({ "legacy": book_db, "cache": cache, "ScopedSession": ScopedSession , "build_time": fromtimestamp(os.stat(path).st_mtime), "default_cover": open(path, 'rb').read(), }) #load_calibre_translations() logging.info("Now, Running...") return web.Application( SOCIAL_AUTH_ROUTES + handlers.routes(), **app_settings)
def make_app(): try: import local_settings settings.update(local_settings.settings) logging.info("loading local_settings.py") except Exception as e: pass init_calibre() import handlers from calibre.db.legacy import LibraryDatabase auth_db_path = settings['user_database'] logging.info("Init library with [%s]" % options.with_library) logging.info("Init AuthDB with [%s]" % auth_db_path ) logging.info("Init Static with [%s]" % settings['static_path'] ) logging.info("Init LANG with [%s]" % P('localization/locales.zip') ) book_db = LibraryDatabase(os.path.expanduser(options.with_library)) cache = book_db.new_api # hook 1: 按字母作为第一级目录,解决书库子目录太多的问题 old_construct_path_name = cache.backend.construct_path_name def new_construct_path_name(*args, **kwargs): s = old_construct_path_name(*args, **kwargs) ns = s[0] + "/" + s logging.debug("new str = %s" % ns) return ns cache.backend.construct_path_name = new_construct_path_name # hook 2: don't force GUI from calibre import gui2 old_must_use_qt = gui2.must_use_qt def new_must_use_qt(headless=True): try: old_must_use_qt(headless) except: pass gui2.must_use_qt = new_must_use_qt Base = declarative_base() engine = create_engine(auth_db_path, echo=False) session = scoped_session(sessionmaker(bind=engine, autoflush=True, autocommit=False)) init_social(Base, session, settings) models.bind_session(session) load_calibre_translations() if options.syncdb: models.user_syncdb(engine) sys.exit(0) if options.testmail: from test import email email.do_send_mail() sys.exit(0) settings.update({ "legacy": book_db, "cache": cache, "session": session, }) return web.Application( SOCIAL_AUTH_ROUTES + handlers.routes(), **settings)