Exemple #1
0
    def __init__(self):
        handlers = route.get_routes()

        app_settings = dict(
            debug=DEBUG,
            autoescape=None,
            gzip=True,
            static_path=os.path.join(ROOT, "static"),
        )

        tornado.web.Application.__init__(self, handlers, **app_settings)
Exemple #2
0
    def __init__(self, database_name=None):
        handlers = route.get_routes()
        app_settings = dict(
            title=settings.PROJECT_TITLE,
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            cookie_secret=settings.COOKIE_SECRET,
            debug=options.debug,
            twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
            twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
        )
        super(Application, self).__init__(handlers, **app_settings)

        self.redis = redis.client.Redis(settings.REDIS_HOST,
                                        settings.REDIS_PORT)
Exemple #3
0
def main(): # pragma: no cover
    tornado.options.parse_command_line()
    if options.showurls:
        for path, class_ in route.get_routes():
            print path
        return

    http_server = tornado.httpserver.HTTPServer(Application())
    print "Starting tornado on port", options.port
    if options.prefork:
        print "\tpre-forking"
        http_server.bind(options.port)
        http_server.start()
    else:
        http_server.listen(options.port)

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        pass
Exemple #4
0
def main():  # pragma: no cover
    tornado.options.parse_command_line()
    if options.showurls:
        for path, class_ in route.get_routes():
            print path
        return

    http_server = tornado.httpserver.HTTPServer(Application())
    print "Starting tornado on port", options.port
    if options.prefork:
        print "\tpre-forking"
        http_server.bind(options.port)
        http_server.start()
    else:
        http_server.listen(options.port)

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        pass
Exemple #5
0
    def __init__(self,
                 database_name=None,
                 xsrf_cookies=True,
                 optimize_static_content=None):
        ui_modules_map = {}
        for app_name in settings.APPS:
            _ui_modules = __import__('apps.%s' % app_name, globals(), locals(),
                                     ['ui_modules'], -1)
            try:
                ui_modules = _ui_modules.ui_modules
            except AttributeError:
                # this app simply doesn't have a ui_modules.py file
                continue

            for name in [x for x in dir(ui_modules) if re.findall('[A-Z]\w+', x)]:
                thing = getattr(ui_modules, name)
                try:
                    if issubclass(thing, tornado.web.UIModule):
                        ui_modules_map[name] = thing
                except TypeError:
                    # most likely a builtin class or something
                    pass

        try:
            cdn_prefix = [x.strip() for x in file('cdn_prefix.conf')
                             if x.strip() and not x.strip().startswith('#')][0]
            #logging.info("Using %r as static URL prefix" % cdn_prefix)
        except (IOError, IndexError):
            cdn_prefix = None

        # unless explicitly set, then if in debug mode, disable optimization
        # of static content
        if optimize_static_content is None:
            optimize_static_content = not options.debug

        handlers = route.get_routes()
        app_settings = dict(
            title=settings.TITLE,
            template_path=os.path.join(os.path.dirname(__file__), "apps", "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            ui_modules=ui_modules_map,
            xsrf_cookies=xsrf_cookies,
            cookie_secret=settings.COOKIE_SECRET,
            login_url=settings.LOGIN_URL,
            debug=options.debug,
            optimize_static_content=optimize_static_content,
            git_revision=get_git_revision(),
            email_backend=options.debug and \
                 'utils.send_mail.backends.console.EmailBackend' \
              or 'utils.send_mail.backends.smtp.EmailBackend',
            webmaster=settings.WEBMASTER,
            admin_emails=settings.ADMIN_EMAILS,
            CLOSURE_LOCATION=os.path.join(os.path.dirname(__file__),
                                      "static", "compiler.jar"),
            YUI_LOCATION=os.path.join(os.path.dirname(__file__),
                                      "static", "yuicompressor-2.4.2.jar"),
            cdn_prefix=cdn_prefix,
        )
        tornado.web.Application.__init__(self, handlers, **app_settings)

        # Have one global connection to the blog DB across all handlers
        self.database_name = database_name and database_name or options.database_name
        self.con = Connection() # XXX: needs more options for host/username/password

        model_classes = []
        for app_name in settings.APPS:
            _models = __import__('apps.%s' % app_name, globals(), locals(),
                                     ['models'], -1)
            try:
                models = _models.models
            except AttributeError:
                # this app simply doesn't have a models.py file
                continue
            for name in [x for x in dir(models) if re.findall('[A-Z]\w+', x)]:
                thing = getattr(models, name)
                if issubclass(thing, mongokit_Document):
                    model_classes.append(thing)

        self.con.register(model_classes)
Exemple #6
0
    def __init__(self,
                 database_name=None,
                 xsrf_cookies=True,
                 optimize_static_content=None):
        ui_modules_map = {}
        for app_name in settings.APPS:
            _ui_modules = __import__('apps.%s' % app_name, globals(), locals(),
                                     ['ui_modules'], -1)
            try:
                ui_modules = _ui_modules.ui_modules
            except AttributeError:
                # this app simply doesn't have a ui_modules.py file
                continue

            for name in [
                    x for x in dir(ui_modules) if re.findall('[A-Z]\w+', x)
            ]:
                thing = getattr(ui_modules, name)
                try:
                    if issubclass(thing, tornado.web.UIModule):
                        ui_modules_map[name] = thing
                except TypeError:
                    # most likely a builtin class or something
                    pass

        try:
            cdn_prefix = [
                x.strip() for x in file('cdn_prefix.conf')
                if x.strip() and not x.strip().startswith('#')
            ][0]
            #logging.info("Using %r as static URL prefix" % cdn_prefix)
        except (IOError, IndexError):
            cdn_prefix = None

        # unless explicitly set, then if in debug mode, disable optimization
        # of static content
        if optimize_static_content is None:
            optimize_static_content = not options.debug

        handlers = route.get_routes()
        app_settings = dict(
            title=settings.TITLE,
            template_path=os.path.join(os.path.dirname(__file__), "apps", "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            ui_modules=ui_modules_map,
            xsrf_cookies=xsrf_cookies,
            cookie_secret=settings.COOKIE_SECRET,
            login_url=settings.LOGIN_URL,
            debug=options.debug,
            optimize_static_content=optimize_static_content,
            git_revision=get_git_revision(),
            email_backend=options.debug and \
                 'utils.send_mail.backends.console.EmailBackend' \
              or 'utils.send_mail.backends.smtp.EmailBackend',
            webmaster=settings.WEBMASTER,
            admin_emails=settings.ADMIN_EMAILS,
            CLOSURE_LOCATION=os.path.join(os.path.dirname(__file__),
                                      "static", "compiler.jar"),
            YUI_LOCATION=os.path.join(os.path.dirname(__file__),
                                      "static", "yuicompressor-2.4.2.jar"),
            cdn_prefix=cdn_prefix,
        )
        tornado.web.Application.__init__(self, handlers, **app_settings)

        # Have one global connection to the blog DB across all handlers
        self.database_name = database_name and database_name or options.database_name
        self.con = Connection(
        )  # XXX: needs more options for host/username/password

        model_classes = []
        for app_name in settings.APPS:
            _models = __import__('apps.%s' % app_name, globals(), locals(),
                                 ['models'], -1)
            try:
                models = _models.models
            except AttributeError:
                # this app simply doesn't have a models.py file
                continue
            for name in [x for x in dir(models) if re.findall('[A-Z]\w+', x)]:
                thing = getattr(models, name)
                if issubclass(thing, mongokit_Document):
                    model_classes.append(thing)

        self.con.register(model_classes)