Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
        # The web app connects to the OAuth provider using this URI.
        # The remote service verifies information provided to the user
        # when they connected to AUTHORIZATION_URL.
        #
        # - Why is this not set to an absolute URI, as done above for
        #   AUTHORIZATION_URI?
        #
        #   This call is made from the webserver itself, sometimes
        #   running inside a Docker container.  A server may be
        #   visible to the outside world on port 9000 (due to Docker
        #   port mapping), but from the perspective of (inside) the
        #   running container, the fakeoauth server only responds to
        #   `localhost:5000`.  If we try to connect to
        #   `localhost:9000/fakeoauth2`, we won't get through.
        #
        # Instead, we always connect to localhost:63000.

        env, cfg = load_env()
        return f'http://*****:*****@cesium-ml.org',
            'email': '*****@*****.**'
        }


# Set up TornadoStorage
init_social(Base, DBSession,
            {'SOCIAL_AUTH_USER_MODEL': 'baselayer.app.models.User'})
Ejemplo n.º 3
0
#!/usr/bin/env python

import sys

import tornado.httpserver
import tornado.ioloop

from social_tornado.models import init_social

from example.app import Base, session, engine, application, tornado_settings


if __name__ == '__main__':
    if len(sys.argv) > 1 and sys.argv[1] == 'syncdb':
        from example.models import User
        init_social(Base, session, tornado_settings)
        Base.metadata.create_all(engine)
    else:
        init_social(Base, session, tornado_settings)
        http_server = tornado.httpserver.HTTPServer(application)
        listen_port = 8001
        listen_interface = "0.0.0.0"
        if len(sys.argv) > 1:
            listen_interface, listen_port = sys.argv[1].rsplit(':', 1)
        http_server.listen(listen_port, address=listen_interface)
        tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)