コード例 #1
0
ファイル: app.py プロジェクト: peterbe/tornado_gkc
def main(): # pragma: no cover
    tornado.options.parse_command_line()
    if options.showurls:
        for each in route.get_routes():
            if isinstance(each, tornado.web.URLSpec):
                print dir(each.regex)
                print repr(each.regex.sub('x','y'))
                print each.name
                print each.kwargs
                print each.handler_class
                print "\n"
            else:
                path = each[0]
                if len(each) == 3 and 'url' in each[2]:
                    print path, '-->', each[2]['url']
                else:
                    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
コード例 #2
0
ファイル: app.py プロジェクト: amitdash/worklog
def main(): # pragma: no cover
    tornado.options.parse_command_line()
    if options.showurls:
        for each in route.get_routes():
            path = each[0]
            if len(each) == 3 and 'url' in each[2]:
                print path, '-->', each[2]['url']
            else:
                print path
        return

    if os.path.isfile('static_index.html'):
        import warnings
        warnings.warn("Running with static_index.html")
    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
コード例 #3
0
def main():  # pragma: no cover
    tornado.options.parse_command_line()
    if options.showurls:
        for each in route.get_routes():
            if isinstance(each, tornado.web.URLSpec):
                print dir(each.regex)
                print repr(each.regex.sub('x', 'y'))
                print each.name
                print each.kwargs
                print each.handler_class
                print "\n"
            else:
                path = each[0]
                if len(each) == 3 and 'url' in each[2]:
                    print path, '-->', each[2]['url']
                else:
                    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
コード例 #4
0
 def __init__(self):
     #        handlers = [
     #            ################用户页面#############
     #            (r'/people/([^/]+)', empty),
     #            ################愿望相关##############
     #            (r'/wish/pool', empty),
     #            (r'/wish/([^/]+)', empty),
     #            (r'/wish/([^/]+)/add', empty),
     #            (r'/wish/([^/]+)/edit', empty),
     #            (r'/wish/([^/]+)/delete', empty),
     #            (r'/wish/([^/]+)/reply', empty),
     #            ###############设置系统###############
     #            (r'/settings/profile',empty),
     #            (r'/settings/email',empty),
     #            (r'/settings/profile',empty),
     #            (r'/settings/acount',empty),
     #            ################通知系统##############
     #            (r'/notifications',empty),
     #            (r'/notifications/all',empty)
     #        ]
     routed_handlers = route.get_routes()
     routed_handlers.append(
         tornado.web.url(r"/static/(.*)", t.StaticFileHandler,
                         app_config['static_path']))
     routed_handlers.append(
         tornado.web.url('/.*?',
                         base.PageNotFoundHandler,
                         name='page_not_found'))
     settings = app_config
     tornado.web.Application.__init__(self, routed_handlers, **settings)
     self.session = ConnectDB()
     self.r = ConnectRDB()
コード例 #5
0
ファイル: app.py プロジェクト: satishvis/worklog
def main():  # pragma: no cover
    tornado.options.parse_command_line()
    if options.showurls:
        for each in route.get_routes():
            path = each[0]
            if len(each) == 3 and 'url' in each[2]:
                print path, '-->', each[2]['url']
            else:
                print path
        return

    if os.path.isfile('static_index.html'):
        import warnings
        warnings.warn("Running with static_index.html")
    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
コード例 #6
0
ファイル: server.py プロジェクト: filod/vixi
 def __init__(self):
     #        handlers = [
     #            ################用户页面#############
     #            (r'/people/([^/]+)', empty),
     #            ################愿望相关##############
     #            (r'/wish/pool', empty),
     #            (r'/wish/([^/]+)', empty),
     #            (r'/wish/([^/]+)/add', empty),
     #            (r'/wish/([^/]+)/edit', empty),
     #            (r'/wish/([^/]+)/delete', empty),
     #            (r'/wish/([^/]+)/reply', empty),
     #            ###############设置系统###############
     #            (r'/settings/profile',empty),
     #            (r'/settings/email',empty),
     #            (r'/settings/profile',empty),
     #            (r'/settings/acount',empty),
     #            ################通知系统##############
     #            (r'/notifications',empty),
     #            (r'/notifications/all',empty)
     #        ]
     routed_handlers = route.get_routes()
     routed_handlers.append(tornado.web.url(r"/static/(.*)", t.StaticFileHandler, app_config["static_path"]))
     routed_handlers.append(tornado.web.url("/.*?", base.PageNotFoundHandler, name="page_not_found"))
     settings = app_config
     tornado.web.Application.__init__(self, routed_handlers, **settings)
     self.session = ConnectDB()
     self.r = ConnectRDB()
コード例 #7
0
ファイル: app.py プロジェクト: awesome/tiler
    def __init__(self, database_name=None, optimize_static_content=None):
        ui_modules_map = {}
        for each in ('ui_modules',):
            _ui_modules = __import__(each, globals(), locals(),
                                     ['ui_modules'], -1)
            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:  # pragma: no cover
                    # most likely a builtin class or something
                    pass

        if optimize_static_content is None:
            optimize_static_content = not options.dont_optimize_static_content

        try:
            cdn_prefix = [x.strip() for x in open('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

        from tornado_utils import tornado_static
        ui_modules_map['Static'] = tornado_static.Static
        ui_modules_map['StaticURL'] = tornado_static.StaticURL
        ui_modules_map['Static64'] = tornado_static.Static64
        if not optimize_static_content:
            ui_modules_map['Static'] = tornado_static.PlainStatic
            ui_modules_map['StaticURL'] = tornado_static.PlainStaticURL

        routed_handlers = route.get_routes()
        app_settings = dict(
            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,
            xsrf_cookies=True,
            debug=options.debug,
            email_backend=options.debug and \
                 'tornado_utils.send_mail.backends.console.EmailBackend' \
              or 'tornado_utils.send_mail.backends.pickle.EmailBackend',
            admin_emails=settings.ADMIN_EMAILS,
            ui_modules=ui_modules_map,
            embed_static_url_timestamp=not options.dont_embed_static_url,
            optimize_static_content=optimize_static_content,
            cdn_prefix=cdn_prefix,
            CLOSURE_LOCATION=os.path.join(os.path.dirname(__file__),
                                          "static", "compiler.jar"),
        )
        routed_handlers.append(
            tornado.web.url('/.*?',
                            handlers.PageNotFoundHandler,
                            name='page_not_found')
        )
        super(Application, self).__init__(routed_handlers, **app_settings)

        self.db  # property gets created
コード例 #8
0
ファイル: app.py プロジェクト: aikomastboom/tiler
    def __init__(self, database_name=None, optimize_static_content=None):
        ui_modules_map = {}
        for each in ('ui_modules',):
            _ui_modules = __import__(each, globals(), locals(),
                                     ['ui_modules'], -1)
            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:  # pragma: no cover
                    # most likely a builtin class or something
                    pass

        if optimize_static_content is None:
            optimize_static_content = not options.dont_optimize_static_content

        try:
            cdn_prefix = [x.strip() for x in open('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

        from tornado_utils import tornado_static
        ui_modules_map['Static'] = tornado_static.Static
        ui_modules_map['StaticURL'] = tornado_static.StaticURL
        ui_modules_map['Static64'] = tornado_static.Static64
        if not optimize_static_content:
            ui_modules_map['Static'] = tornado_static.PlainStatic
            ui_modules_map['StaticURL'] = tornado_static.PlainStaticURL

        routed_handlers = route.get_routes()
        app_settings = dict(
            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,
            xsrf_cookies=True,
            debug=options.debug,
            email_backend=options.debug and \
                 'tornado_utils.send_mail.backends.console.EmailBackend' \
              or 'tornado_utils.send_mail.backends.pickle.EmailBackend',
            admin_emails=settings.ADMIN_EMAILS,
            ui_modules=ui_modules_map,
            embed_static_url_timestamp=not options.dont_embed_static_url,
            optimize_static_content=optimize_static_content,
            cdn_prefix=cdn_prefix,
            CLOSURE_LOCATION=os.path.join(os.path.dirname(__file__),
                                          "static", "compiler.jar"),
        )
        routed_handlers.append(
            tornado.web.url('/.*?',
                            handlers.PageNotFoundHandler,
                            name='page_not_found')
        )
        super(Application, self).__init__(routed_handlers, **app_settings)

        self.db  # property gets created
コード例 #9
0
ファイル: app.py プロジェクト: peterbe/aroundtheworld
    def __init__(self, database_name=None, optimize_static_content=None):
        ui_modules_map = {}
        for each in ("core.ui_modules", "admin.ui_modules"):
            _ui_modules = __import__(each, globals(), locals(), ["ui_modules"], -1)
            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:  # pragma: no cover
                    # most likely a builtin class or something
                    pass
        if optimize_static_content is None:
            optimize_static_content = not options.dont_optimize_static_content

        try:
            cdn_prefix = [x.strip() for x in open("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

        from tornado_utils import tornado_static

        ui_modules_map["Static"] = tornado_static.Static
        ui_modules_map["StaticInline"] = tornado_static.StaticInline
        ui_modules_map["StaticURL"] = tornado_static.StaticURL
        ui_modules_map["Static64"] = tornado_static.Static64
        routed_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,
            email_backend=options.debug
            and "tornado_utils.send_mail.backends.console.EmailBackend"
            or "tornado_utils.send_mail.backends.pickle.EmailBackend",
            admin_emails=settings.ADMIN_EMAILS,
            ui_modules=ui_modules_map,
            embed_static_url_timestamp=not options.dont_embed_static_url,
            optimize_static_content=optimize_static_content,
            cdn_prefix=cdn_prefix,
            CLOSURE_LOCATION=os.path.join(os.path.dirname(__file__), "static", "compiler.jar"),
            twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
            twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
        )
        routed_handlers.append(tornado.web.url("/.*?", core.handlers.PageNotFoundHandler, name="page_not_found"))
        super(Application, self).__init__(routed_handlers, **app_settings)

        self.redis = redis.client.Redis(settings.REDIS_HOST, settings.REDIS_PORT)

        from core.models import connection
        import admin.models  # so it gets registered

        self.db = connection[database_name or settings.DATABASE_NAME]
コード例 #10
0
ファイル: __init__.py プロジェクト: orchod/bootornado
    def __init__(self):
        handlers = route.get_routes()

        settings = dict(
            title = "bootornado",
            template_path = os.path.join(os.path.dirname(__file__),"templates"),
            static_path = os.path.join(os.path.dirname(__file__),"static"),
            debug = True,
            ui_modules = uimodules,
            autoescape = None,
            cookie_secret = "bootornado"
        )
        
        tornado.web.Application.__init__(self, handlers, **settings)
コード例 #11
0
ファイル: app.py プロジェクト: sobtiankit/toocool
    def __init__(self, database_name=None):
        routed_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__(routed_handlers, **app_settings)

        self.redis = redis.client.Redis(settings.REDIS_HOST,
                                        settings.REDIS_PORT)

        from models import connection
        self.db = connection[settings.DATABASE_NAME]
コード例 #12
0
    def __init__(self, database_name=None):
        _ui_modules = __import__('ui_modules', globals(), locals(),
                                 ['ui_modules'], -1)
        ui_modules_map = {}
        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:  # pragma: no cover
                # most likely a builtin class or something
                pass

        routed_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,
            email_backend=options.debug and \
                 'tornado_utils.send_mail.backends.console.EmailBackend' \
              or 'tornado_utils.send_mail.backends.pickle.EmailBackend',
            admin_emails=settings.ADMIN_EMAILS,
            ui_modules=ui_modules_map,
            twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
            twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
        )
        if 1 or not options.debug:
            routed_handlers.append(
                tornado.web.url('/.*?',
                                handlers.PageNotFoundHandler,
                                name='page_not_found'))
        super(Application, self).__init__(routed_handlers, **app_settings)

        self.redis = redis.client.Redis(settings.REDIS_HOST,
                                        settings.REDIS_PORT)

        from models import connection
        self.db = connection[database_name or settings.DATABASE_NAME]
コード例 #13
0
ファイル: server.py プロジェクト: baden/navi.cc
    def __init__(self, opts):
        handlers = [
            (r'/point/test(.*)', TestHandler)
        ] + config.router + route.get_routes()
        # print ' Application:opts=', repr(opts)
        settings = dict(
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            # xsrf_cookies=True,
            login_url="/auth/login",
            autoescape=None  # ,
            #**{k: v.value() for k, v in opts.items()}
        )
        #settings.update(opts)
        for k, v in opts.items():
            settings[k] = v.value()
        print 'settings=', repr(settings)
        web.Application.__init__(self, handlers, **settings)

        # Единое соединение с базой данных для всех обработчиков
        #self.db = base.DB.db(DB_URL, DB_REPLICASET)
        self.db = getdb(opts.mongodb_url, opts.mongodb_replicaset)
コード例 #14
0
ファイル: app.py プロジェクト: amitdash/toocool
    def __init__(self, database_name=None):
        _ui_modules = __import__('ui_modules', globals(), locals(), ['ui_modules'], -1)
        ui_modules_map = {}
        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:  # pragma: no cover
                # most likely a builtin class or something
                pass

        routed_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,
            email_backend=options.debug and \
                 'tornado_utils.send_mail.backends.console.EmailBackend' \
              or 'tornado_utils.send_mail.backends.pickle.EmailBackend',
            admin_emails=settings.ADMIN_EMAILS,
            ui_modules=ui_modules_map,
            twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
            twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
        )
        if 1 or not options.debug:
            routed_handlers.append(
              tornado.web.url('/.*?', handlers.PageNotFoundHandler,
                            name='page_not_found')
            )
        super(Application, self).__init__(routed_handlers, **app_settings)

        self.redis = redis.client.Redis(settings.REDIS_HOST,
                                        settings.REDIS_PORT)

        from models import connection
        self.db = connection[database_name or settings.DATABASE_NAME]
コード例 #15
0
ファイル: manage.py プロジェクト: onary/boilerplate
    def __init__(self, *args, **kwargs):
        # Init jiaja2 environment
        self.jinja_env = settings.JINJA_ENV
        # Register filters for jinja2
        self.jinja_env.filters.update(filters.register_filters())
        self.jinja_env.tests.update({})
        self.jinja_env.globals['settings'] = settings.APP_SETTINGS
        handlers = route.get_routes()

        # Register mongo db
        self.db = connect_mongo(settings.MONGO_DB, **kwargs)

        # compress css and js
        self.assets = lambda x: settings.ASSETS[x].urls()[0]

        # registr admin list
        self.admin_apps = get_admin_apps()

        # registr models
        self.models = import_models()

        tornado.web.Application.__init__(
            self, handlers, *args, **dict(settings.APP_SETTINGS, **kwargs))
コード例 #16
0
ファイル: __init__.py プロジェクト: cokeboy/bootornado
    def __init__(self):
        handlers = route.get_routes()

        settings = dict(
            title         = "bootornado",
            template_path = os.path.join(os.path.dirname(__file__),"templates"),
            static_path   = os.path.join(os.path.dirname(__file__),"static"),
            login_url     = '/auth/login',
            debug         = True,
            ui_modules    = uimodules,
            autoescape    = None,
            cookie_secret = "bootornado"
        )
        settings['session'] = {
            'engine': 'redis',
            'storage': {
                'host': 'localhost',
                'port': 6379,
                'db_sessions': 10,
                'db_notifications': 11
            }
        }
        tornado.web.Application.__init__(self, handlers, **settings)
コード例 #17
0
ファイル: manage.py プロジェクト: onary/boilerplate
    def __init__(self, *args, **kwargs):
        # Init jiaja2 environment
        self.jinja_env = settings.JINJA_ENV
        # Register filters for jinja2
        self.jinja_env.filters.update(filters.register_filters())
        self.jinja_env.tests.update({})
        self.jinja_env.globals['settings'] = settings.APP_SETTINGS
        handlers = route.get_routes()

        # Register mongo db
        self.db = connect_mongo(settings.MONGO_DB, **kwargs)

        # compress css and js
        self.assets = lambda x: settings.ASSETS[x].urls()[0]

        # registr admin list
        self.admin_apps = get_admin_apps()

        # registr models
        self.models = import_models()

        tornado.web.Application.__init__(
            self, handlers, *args, **dict(settings.APP_SETTINGS, **kwargs))
コード例 #18
0
ファイル: app.py プロジェクト: amitdash/worklog
    def __init__(self,
                 database_name=None,
                 xsrf_cookies=True,
                 optimize_static_content=None):
        ui_modules_map = {}
        for app_name in settings.APPS:
            # XXX consider replacing this with use of tornado.util.import_object
            _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

        if options.dont_combine:
            ui_modules_map['Static'] = ui_modules_map['PlainStatic']
            ui_modules_map['StaticURL'] = ui_modules_map['PlainStaticURL']

        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"),
            embed_static_url_timestamp=True and not options.dont_embed_static_url,
            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"),
            UNDOER_GUID=u'UNDOER', # must be a unicode string
            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()
        self.redis = redis.client.Redis(settings.REDIS_HOST,
                                        settings.REDIS_PORT)

        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)
コード例 #19
0
ファイル: app.py プロジェクト: satishvis/worklog
    def __init__(self,
                 database_name=None,
                 xsrf_cookies=True,
                 optimize_static_content=None):
        ui_modules_map = {}
        for app_name in settings.APPS:
            # XXX consider replacing this with use of tornado.util.import_object
            _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

        if options.dont_combine:
            ui_modules_map['Static'] = ui_modules_map['PlainStatic']
            ui_modules_map['StaticURL'] = ui_modules_map['PlainStaticURL']

        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"),
            embed_static_url_timestamp=True and not options.dont_embed_static_url,
            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"),
            UNDOER_GUID=u'UNDOER', # must be a unicode string
            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()
        self.redis = redis.client.Redis(settings.REDIS_HOST,
                                        settings.REDIS_PORT)

        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)
コード例 #20
0
ファイル: app.py プロジェクト: peterbe/tornado_gkc
    def __init__(self,
                 database_name=None,
                 xsrf_cookies=True,
                 optimize_static_content=None,
                 embed_static_url=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

        if options.dont_combine:
            ui_modules_map['Static'] = ui_modules_map['PlainStatic']
            ui_modules_map['StaticURL'] = ui_modules_map['PlainStaticURL']

        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

        if embed_static_url is None:
            embed_static_url = not options.dont_embed_static_url

        handlers = route.get_routes()
        app_settings = dict(
            title=settings.PROJECT_TITLE,
            template_path=os.path.join(os.path.dirname(__file__), "apps", "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            embed_static_url_timestamp=embed_static_url,
            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.pickle.EmailBackend',
            webmaster=settings.WEBMASTER,
            admin_emails=settings.ADMIN_EMAILS,
            UGLIFYJS_LOCATION=os.path.expanduser('~/bin/uglifyjs'),
            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,
            twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
            twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
            facebook_api_key=settings.FACEBOOK_API_KEY,
            facebook_secret=settings.FACEBOOK_SECRET,
            twitter_postings_consumer_key=settings.TWITTER_POSTINGS_CONSUMER_KEY,
            twitter_postings_consumer_secret=settings.TWITTER_POSTINGS_CONSUMER_SECRET,
        )
        if 1 or not options.debug:
            from apps.main.handlers import PageNotFoundHandler
            handlers.append(tornado.web.url('/.*?', PageNotFoundHandler,
                            name='page_not_found'))
        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()

        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)
                try:
                    if issubclass(thing, mongokit_Document):
                        model_classes.append(thing)
                except TypeError:
                    pass

        self.con.register(model_classes)
        self._search_connection = None
コード例 #21
0
    def __init__(self,
                 database_name=None,
                 xsrf_cookies=True,
                 optimize_static_content=None,
                 embed_static_url=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

        if options.dont_combine:
            ui_modules_map['Static'] = ui_modules_map['PlainStatic']
            ui_modules_map['StaticURL'] = ui_modules_map['PlainStaticURL']

        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

        if embed_static_url is None:
            embed_static_url = not options.dont_embed_static_url

        handlers = route.get_routes()
        app_settings = dict(
            title=settings.PROJECT_TITLE,
            template_path=os.path.join(os.path.dirname(__file__), "apps", "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            embed_static_url_timestamp=embed_static_url,
            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.pickle.EmailBackend',
            webmaster=settings.WEBMASTER,
            admin_emails=settings.ADMIN_EMAILS,
            UGLIFYJS_LOCATION=os.path.expanduser('~/bin/uglifyjs'),
            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,
            twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
            twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
            facebook_api_key=settings.FACEBOOK_API_KEY,
            facebook_secret=settings.FACEBOOK_SECRET,
            twitter_postings_consumer_key=settings.TWITTER_POSTINGS_CONSUMER_KEY,
            twitter_postings_consumer_secret=settings.TWITTER_POSTINGS_CONSUMER_SECRET,
        )
        if 1 or not options.debug:
            from apps.main.handlers import PageNotFoundHandler
            handlers.append(
                tornado.web.url('/.*?',
                                PageNotFoundHandler,
                                name='page_not_found'))
        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()

        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)
                try:
                    if issubclass(thing, mongokit_Document):
                        model_classes.append(thing)
                except TypeError:
                    pass

        self.con.register(model_classes)
        self._search_connection = None
コード例 #22
0
    def __init__(self, database_name=None, optimize_static_content=None):
        ui_modules_map = {}
        for each in ('core.ui_modules', 'admin.ui_modules'):
            _ui_modules = __import__(each, globals(), locals(),
                                     ['ui_modules'], -1)
            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:  # pragma: no cover
                    # most likely a builtin class or something
                    pass
        if optimize_static_content is None:
            optimize_static_content = not options.dont_optimize_static_content

        try:
            cdn_prefix = [x.strip() for x in open('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

        from tornado_utils import tornado_static
        ui_modules_map['Static'] = tornado_static.Static
        ui_modules_map['StaticInline'] = tornado_static.StaticInline
        ui_modules_map['StaticURL'] = tornado_static.StaticURL
        ui_modules_map['Static64'] = tornado_static.Static64
        routed_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,
            email_backend=options.debug and \
                 'tornado_utils.send_mail.backends.console.EmailBackend' \
              or 'tornado_utils.send_mail.backends.pickle.EmailBackend',
            admin_emails=settings.ADMIN_EMAILS,
            ui_modules=ui_modules_map,
            embed_static_url_timestamp=not options.dont_embed_static_url,
            optimize_static_content=optimize_static_content,
            cdn_prefix=cdn_prefix,
            CLOSURE_LOCATION=os.path.join(os.path.dirname(__file__),
                                          "static", "compiler.jar"),
            twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
            twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,


        )
        routed_handlers.append(
          tornado.web.url('/.*?',
                          core.handlers.PageNotFoundHandler,
                          name='page_not_found')
        )
        super(Application, self).__init__(routed_handlers, **app_settings)

        self.redis = redis.client.Redis(settings.REDIS_HOST,
                                        settings.REDIS_PORT)

        from core.models import connection
        import admin.models  # so it gets registered
        self.db = connection[database_name or settings.DATABASE_NAME]