Ejemplo n.º 1
0
    def __init__(self, db, opts, embedded=False, show_tracebacks=True,
            wsgi=False):
        self.is_wsgi = bool(wsgi)
        self.opts = opts
        self.embedded = embedded
        self.state_callback = None
        self.start_failure_callback = None
        try:
            self.max_cover_width, self.max_cover_height = \
                        map(int, self.opts.max_cover.split('x'))
        except:
            self.max_cover_width = 1200
            self.max_cover_height = 1600
        path = P('content_server')
        self.build_time = fromtimestamp(os.stat(path).st_mtime)
        self.default_cover = open(P('content_server/default_cover.jpg'), 'rb').read()
        if not opts.url_prefix:
            opts.url_prefix = ''

        cherrypy.engine.bonjour.ip_address = listen_on
        cherrypy.engine.bonjour.port = opts.port
        cherrypy.engine.bonjour.prefix = opts.url_prefix

        Cache.__init__(self)

        self.set_database(db)

        st = 0.1 if opts.develop else 1

        cherrypy.config.update({
            'log.screen'             : opts.develop,
            'engine.autoreload_on'   : getattr(opts,
                                        'auto_reload', False),
            'tools.log_headers.on'   : opts.develop,
            'tools.encode.encoding'  : 'UTF-8',
            'checker.on'             : opts.develop,
            'request.show_tracebacks': show_tracebacks,
            'server.socket_host'     : listen_on,
            'server.socket_port'     : opts.port,
            'server.socket_timeout'  : opts.timeout, #seconds
            'server.thread_pool'     : opts.thread_pool, # number of threads
            'server.shutdown_timeout': st, # minutes
        })
        if embedded or wsgi:
            cherrypy.config.update({'engine.SIGHUP'          : None,
                                    'engine.SIGTERM'         : None,})
        self.config = {}
        self.is_running = False
        self.exception = None
        auth_controller = None
        self.users_dict = {}
        #self.config['/'] = {
        #    'tools.sessions.on' : True,
        #    'tools.sessions.timeout': 60, # Session times out after 60 minutes
        #}

        if not wsgi:
            self.setup_loggers()
            cherrypy.engine.bonjour.subscribe()
            self.config['global'] = {
                'tools.gzip.on'        : True,
                'tools.gzip.mime_types': ['text/html', 'text/plain',
                    'text/xml', 'text/javascript', 'text/css'],
            }

            if opts.password:
                self.users_dict[opts.username.strip()] = opts.password.strip()
                auth_controller = AuthController('Your calibre library',
                        self.users_dict)

        self.__dispatcher__ = DispatchController(self.opts.url_prefix,
                wsgi=wsgi, auth_controller=auth_controller)
        for x in self.__class__.__bases__:
            if hasattr(x, 'add_routes'):
                x.__init__(self)
                x.add_routes(self, self.__dispatcher__)
        root_conf = self.config.get('/', {})
        root_conf['request.dispatch'] = self.__dispatcher__.dispatcher
        self.config['/'] = root_conf
Ejemplo n.º 2
0
    def __init__(self,
                 db,
                 opts,
                 embedded=False,
                 show_tracebacks=True,
                 wsgi=False):
        self.is_wsgi = bool(wsgi)
        self.opts = opts
        self.embedded = embedded
        self.state_callback = None
        self.start_failure_callback = None
        try:
            self.max_cover_width, self.max_cover_height = \
                        map(int, self.opts.max_cover.split('x'))
        except:
            self.max_cover_width = 1200
            self.max_cover_height = 1600
        path = P('content_server')
        self.build_time = fromtimestamp(os.stat(path).st_mtime)
        self.default_cover = open(P('content_server/m/img/default_cover.jpg'),
                                  'rb').read()
        if not opts.url_prefix:
            opts.url_prefix = ''

        cherrypy.engine.bonjour.ip_address = listen_on
        cherrypy.engine.bonjour.port = opts.port
        cherrypy.engine.bonjour.prefix = opts.url_prefix

        self.last_lang = "en"
        self.all_langs = dict(get_all_translators())
        cherrypy.request.hooks.attach('before_handler', self.update_lang)
        cherrypy.request.hooks.attach('before_handler', self.load_user)
        #cherrypy.request.hooks.attach('on_end_resource', self.save_session)

        #cherrypy.tools.authenticate = cherrypy.Tool('before_handler', self.load_user)
        #cherrypy.tools.session = cherrypy.Tool('on_end_resource', self.save_session)

        Cache.__init__(self)

        self.set_database(db)

        st = 1 if opts.develop else 1

        cherrypy.config.update({
            'log.screen':
            opts.develop,
            'engine.autoreload_on':
            getattr(opts, 'auto_reload', False),
            'tools.log_headers.on':
            opts.develop,
            'tools.encode.encoding':
            'UTF-8',
            'checker.on':
            opts.develop,
            'request.show_tracebacks':
            show_tracebacks,
            'server.socket_host':
            listen_on,
            'server.socket_port':
            opts.port,
            'server.socket_timeout':
            opts.timeout,  # seconds
            'server.thread_pool':
            opts.thread_pool,  # number of threads
            'server.shutdown_timeout':
            st,  # minutes
            'tools.sessions.on':
            True,
            #'tools.sessions.storage_type': 'ram',
            'tools.sessions.timeout':
            60000,  # Session times out after 60 minutes
            'tools.sessions.storage_type':
            "file",
            'tools.sessions.storage_path':
            "/data/tmp/cherrypy/",
            'SOCIAL_AUTH_USER_MODEL':
            'calibre.library.server.auth.FuckUser',
            'SOCIAL_AUTH_LOGIN_URL':
            '/auth/',
            'SOCIAL_AUTH_LOGIN_REDIRECT_URL':
            '/',
            'SOCIAL_AUTH_AUTHENTICATION_BACKENDS': (
                'social.backends.douban.DoubanOAuth',
                'social.backends.douban.DoubanOAuth2',
            ),
            'SOCIAL_AUTH_DOUBAN_OAUTH2_KEY':
            '052c9ac15e9870500f85d0441bc950f0',
            'SOCIAL_AUTH_DOUBAN_OAUTH2_SECRET':
            '3b524f1487999fc6',
        })
        cherrypy.tools.jinja2env = build_jinja2_env()
        if embedded or wsgi:
            cherrypy.config.update({
                'engine.SIGHUP': None,
                'engine.SIGTERM': None,
            })
        self.config = {}
        self.is_running = False
        self.exception = None
        auth_controller = None
        self.users_dict = {}

        if not wsgi:
            self.setup_loggers()
            cherrypy.engine.bonjour.subscribe()
            self.config['global'] = {
                'tools.gzip.on':
                True,
                'tools.gzip.mime_types': [
                    'text/html', 'text/plain', 'text/xml', 'text/javascript',
                    'text/css'
                ],
            }

            if opts.username and opts.password:
                self.users_dict[opts.username.strip()] = opts.password.strip()
                auth_controller = AuthController('Your calibre library',
                                                 self.users_dict)

        self.__dispatcher__ = DispatchController(
            self.opts.url_prefix, wsgi=wsgi, auth_controller=auth_controller)
        for x in self.__class__.__bases__:
            if hasattr(x, 'add_routes'):
                x.__init__(self)
                x.add_routes(self, self.__dispatcher__)
        root_conf = self.config.get('/', {})
        root_conf['request.dispatch'] = self.__dispatcher__.dispatcher
        self.config['/'] = root_conf
Ejemplo n.º 3
0
    def __init__(self, db, opts, embedded=False, show_tracebacks=True,
            wsgi=False):
        self.is_wsgi = bool(wsgi)
        self.opts = opts
        self.embedded = embedded
        self.state_callback = None
        self.start_failure_callback = None
        try:
            self.max_cover_width, self.max_cover_height = \
                        map(int, self.opts.max_cover.split('x'))
        except:
            self.max_cover_width = 1200
            self.max_cover_height = 1600
        path = P('content_server')
        self.build_time = fromtimestamp(os.stat(path).st_mtime)
        self.default_cover = open(P('content_server/default_cover.jpg'), 'rb').read()
        if not opts.url_prefix:
            opts.url_prefix = ''

        cherrypy.engine.bonjour.ip_address = listen_on
        cherrypy.engine.bonjour.port = opts.port
        cherrypy.engine.bonjour.prefix = opts.url_prefix

        Cache.__init__(self)

        self.set_database(db)

        st = 0.1 if opts.develop else 1

        cherrypy.config.update({
            'log.screen'             : opts.develop,
            'engine.autoreload_on'   : getattr(opts,
                                        'auto_reload', False),
            'tools.log_headers.on'   : opts.develop,
            'tools.encode.encoding'  : 'UTF-8',
            'checker.on'             : opts.develop,
            'request.show_tracebacks': show_tracebacks,
            'server.socket_host'     : listen_on,
            'server.socket_port'     : opts.port,
            'server.socket_timeout'  : opts.timeout,  # seconds
            'server.thread_pool'     : opts.thread_pool,  # number of threads
            'server.shutdown_timeout': st,  # minutes
        })
        if embedded or wsgi:
            cherrypy.config.update({'engine.SIGHUP'          : None,
                                    'engine.SIGTERM'         : None,})
        self.config = {}
        self.is_running = False
        self.exception = None
        auth_controller = None
        self.users_dict = {}
        # self.config['/'] = {
        #    'tools.sessions.on' : True,
        # 'tools.sessions.timeout': 60, # Session times out after 60 minutes
        #}

        if not wsgi:
            self.setup_loggers()
            cherrypy.engine.bonjour.subscribe()
            self.config['global'] = {
                'tools.gzip.on'        : True,
                'tools.gzip.mime_types': ['text/html', 'text/plain',
                    'text/xml', 'text/javascript', 'text/css'],
            }

            if opts.username and opts.password:
                self.users_dict[opts.username.strip()] = opts.password.strip()
                auth_controller = AuthController('Your calibre library',
                        self.users_dict)

        self.__dispatcher__ = DispatchController(self.opts.url_prefix,
                wsgi=wsgi, auth_controller=auth_controller)
        for x in self.__class__.__bases__:
            if hasattr(x, 'add_routes'):
                x.__init__(self)
                x.add_routes(self, self.__dispatcher__)
        root_conf = self.config.get('/', {})
        root_conf['request.dispatch'] = self.__dispatcher__.dispatcher
        self.config['/'] = root_conf
Ejemplo n.º 4
0
    def __init__(self, db, opts, embedded=False, show_tracebacks=True,
            wsgi=False):
        self.is_wsgi = bool(wsgi)
        self.opts = opts
        self.embedded = embedded
        self.state_callback = None
        self.start_failure_callback = None
        try:
            self.max_cover_width, self.max_cover_height = \
                        map(int, self.opts.max_cover.split('x'))
        except:
            self.max_cover_width = 1200
            self.max_cover_height = 1600
        path = P('content_server')
        self.build_time = fromtimestamp(os.stat(path).st_mtime)
        self.default_cover = open(P('content_server/m/img/default_cover.jpg'), 'rb').read()
        if not opts.url_prefix:
            opts.url_prefix = ''


        cherrypy.engine.bonjour.ip_address = listen_on
        cherrypy.engine.bonjour.port = opts.port
        cherrypy.engine.bonjour.prefix = opts.url_prefix

        self.last_lang = "en"
        self.all_langs = dict(get_all_translators())
        cherrypy.request.hooks.attach('before_handler', self.update_lang)
        cherrypy.request.hooks.attach('before_handler', self.load_user)
        #cherrypy.request.hooks.attach('on_end_resource', self.save_session)

        #cherrypy.tools.authenticate = cherrypy.Tool('before_handler', self.load_user)
        #cherrypy.tools.session = cherrypy.Tool('on_end_resource', self.save_session)

        Cache.__init__(self)

        self.set_database(db)

        st = 1 if opts.develop else 1

        cherrypy.config.update({
            'log.screen'             : opts.develop,
            'engine.autoreload_on'   : getattr(opts,
                                        'auto_reload', False),
            'tools.log_headers.on'   : opts.develop,
            'tools.encode.encoding'  : 'UTF-8',
            'checker.on'             : opts.develop,
            'request.show_tracebacks': show_tracebacks,
            'server.socket_host'     : listen_on,
            'server.socket_port'     : opts.port,
            'server.socket_timeout'  : opts.timeout,  # seconds
            'server.thread_pool'     : opts.thread_pool,  # number of threads
            'server.shutdown_timeout': st,  # minutes
            'tools.sessions.on' : True,
            #'tools.sessions.storage_type': 'ram',
            'tools.sessions.timeout': 60000, # Session times out after 60 minutes
            'tools.sessions.storage_type': "file",
            'tools.sessions.storage_path': "/data/tmp/cherrypy/",
            'SOCIAL_AUTH_USER_MODEL': 'calibre.library.server.auth.FuckUser',
            'SOCIAL_AUTH_LOGIN_URL': '/auth/',
            'SOCIAL_AUTH_LOGIN_REDIRECT_URL': '/',
            'SOCIAL_AUTH_AUTHENTICATION_BACKENDS': (
                'social.backends.douban.DoubanOAuth',
                'social.backends.douban.DoubanOAuth2',
            ),
            'SOCIAL_AUTH_DOUBAN_OAUTH2_KEY': '052c9ac15e9870500f85d0441bc950f0',
            'SOCIAL_AUTH_DOUBAN_OAUTH2_SECRET': '3b524f1487999fc6',
        });
        cherrypy.tools.jinja2env = build_jinja2_env()
        if embedded or wsgi:
            cherrypy.config.update({'engine.SIGHUP'          : None,
                                    'engine.SIGTERM'         : None,})
        self.config = {}
        self.is_running = False
        self.exception = None
        auth_controller = None
        self.users_dict = {}

        if not wsgi:
            self.setup_loggers()
            cherrypy.engine.bonjour.subscribe()
            self.config['global'] = {
                'tools.gzip.on'        : True,
                'tools.gzip.mime_types': ['text/html', 'text/plain',
                    'text/xml', 'text/javascript', 'text/css'],
            }

            if opts.username and opts.password:
                self.users_dict[opts.username.strip()] = opts.password.strip()
                auth_controller = AuthController('Your calibre library',
                        self.users_dict)

        self.__dispatcher__ = DispatchController(self.opts.url_prefix,
                wsgi=wsgi, auth_controller=auth_controller)
        for x in self.__class__.__bases__:
            if hasattr(x, 'add_routes'):
                x.__init__(self)
                x.add_routes(self, self.__dispatcher__)
        root_conf = self.config.get('/', {})
        root_conf['request.dispatch'] = self.__dispatcher__.dispatcher
        self.config['/'] = root_conf