Exemple #1
0
    def setup(self):
        settings.define_app_options()
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s %(filename)s %(levelname)s %(message)s',
            datefmt='%a, %d %b %Y %H:%M:%S',
        )
        parse_command_line(final=False)
        # current_dir = os.path.dirname(os.path.abspath(__file__))
        # current_dir = os.path.split(os.path.realpath(sys.argv[0]))[0]
        current_dir = sys.path[0]
        logging.info('Running in %s mode' %
                     ('debug' if options.debug else 'production'))
        if options.debug:
            conf_file_path = os.path.join(current_dir, 'server.conf')
        else:
            conf_file_path = os.path.join(current_dir, 'prod.conf')
        if os.path.exists(conf_file_path):
            parse_config_file(conf_file_path, final=False)

        parse_command_line(final=True)
        self.subjects = {}
        self.oss_bucket = self.setup_oss_bucket()
        for subject_name in ALL_SUPPORT_SUBJECTS:
            self.load_subject_conf(subject_name)
            subject = Subject(None, subject_name, options.types)
            # 脚本暂时不需要motor
            self.subjects[subject_name] = subject
Exemple #2
0
    def __init__(self):
        settings.define_app_options()
        parse_command_line(final=False)
        self_dir = os.path.dirname(os.path.abspath(__file__))
        upload_files_dir = self_dir + '/upload_files'
        conf_file_path = os.path.join(self_dir, 'server.conf')
        if os.path.exists(conf_file_path):
            parse_config_file(conf_file_path, final=False)
        parse_command_line(final=True)

        loader = JinjaLoader(loader=ChoiceLoader([
            FileSystemLoader(os.path.join(self_dir, 'template')),
        ]),
                             debug=options.debug)
        SmartStaticFileHandler.file_finder = MultiFileFindler([],
                                                              os.path.join(
                                                                  self_dir,
                                                                  'static'))

        mongodb_client = self.setup_mongodb_client()
        app_settings = {
            'template_loader': loader,
            'upload_dir': upload_files_dir,
            'mongodb_client': mongodb_client,
            'static_handler_class': SmartStaticFileHandler,
            'xsrf_cookies': False,
            'static_path': u'/static/',
            'debug': options.debug,
            'cookie_secret': 'bZJc2sWbQLKos6GkHn/VB9oXwQt8S0R0kRvJ5/xJ89E=',
            'login_url': '/login',
        }
        super(RunReport, self).__init__(routes.get(), **app_settings)
def config_repo(auto_gen_pincode=True):
    ret = False
    if load_config_file():
        # reload settings.
        settings.define_app_options()
        if auto_gen_pincode:
            ret = generate_pincode()
    return ret
Exemple #4
0
def main():
    settings.define_app_options()
    parse_command_line(final=True)

    logging.info('Runing at port %s in %s mode' % (options.port, 'debug' if options.debug else 'production'))

    app = App(options)
    server = HTTPServer(app, xheaders=True)
    server.listen(options.port)

    install_tornado_shutdown_handler(IOLoop.instance(), server)
    logging.info('Good to go!')

    IOLoop.instance().start()
    logging.info('Exiting...waiting for background jobs done...')
    logging.info('Done. Bye.')
Exemple #5
0
def main():
    settings.define_app_options()
    parse_command_line(final=True)

    logging.info('Runing at port %s in %s mode' %
                 (options.port, 'debug' if options.debug else 'production'))

    app = App(options)
    server = HTTPServer(app, xheaders=True)
    server.listen(options.port)

    install_tornado_shutdown_handler(IOLoop.instance(), server)
    logging.info('Good to go!')

    IOLoop.instance().start()
    logging.info('Exiting...waiting for background jobs done...')
    logging.info('Done. Bye.')
Exemple #6
0
    def __init__(self, **more_settings):
        settings.define_app_options()
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s %(filename)s %(levelname)s %(message)s',
            datefmt='%a, %d %b %Y %H:%M:%S',
        )
        parse_command_line(final=False)
        self_dir_path = os.path.abspath(os.path.dirname(__file__))
        if options.debug:
            conf_file_path = os.path.join(self_dir_path, 'server.conf')
        else:
            conf_file_path = os.path.join(self_dir_path, 'prod.conf')
        if os.path.exists(conf_file_path):
            parse_config_file(conf_file_path, final=False)
        parse_command_line(final=True)

        rds = None

        # self.jyeoo_admin_db = subject_db_client['jyeoo_admin']
        self.subjects = {}
        self.default_subject = ALL_SUPPORT_SUBJECTS[0]

        logging.info("Connecting to redis %s ...", options.redis_url)
        self.redis = StrictRedis.from_url(options.redis_url,
                                          db=options.redis_db,
                                          socket_timeout=5.0)
        self.redis.exists("dumb_key_test_connectivity")  # force to connect
        logging.info("Redis connected. Seems good.")

        the_routes = routes.get_main_route()
        the_settings = {
            'debug': options.debug,
            'cookie_secret': options.cookie_secret,
            'xsrf_cookies': False,
            # 'mysql_db': self.setup_subject_mysql_db(),
            # 'static_path': u'/static/',
            # 'static_handler_class': SmartStaticFileHandler,
            'oss_bucket': self.setup_oss_bucket(),
            'subjects': self.subjects,
            'default_subject': self.default_subject,
            'redis': self.redis,
        }
        the_settings.update(more_settings)
        # routes = get_routes()
        self.app = Application(the_routes, **the_settings)
Exemple #7
0
    def __init__(self, **more_settings):
        settings.define_app_options()
        parse_command_line(final=False)
        self_dir_path = os.path.abspath(os.path.dirname(__file__))
        if options.debug:
            conf_file_path = os.path.join(self_dir_path, 'server.conf')
        else:
            conf_file_path = os.path.join(self_dir_path, 'prod.conf')
        if os.path.exists(conf_file_path):
            parse_config_file(conf_file_path, final=False)
        parse_command_line(final=True)
        """
        loader = ChoiceLoader([
            FileSystemLoader(os.path.join(self_dir_path, 'templates')),
        ])
        """
        loader = JinjaLoader(loader=ChoiceLoader([
            FileSystemLoader(os.path.join(self_dir_path, 'templates')),
        ]),
                             debug=options.debug)
        SmartStaticFileHandler.file_finder = MultiFileFindler(
            [], os.path.join(self_dir_path, 'static'))
        the_settings = {
            'template_loader': loader,
            'debug': options.debug,
            'cookie_secret': options.cookie_secret,
            'xsrf_cookies': True,
            'db': self.setup_db_client(),
            'asy_db': self.setup_asy_db_client(),
            'userdb': self.setup_user_db(),
            'oss_bucket': self.setup_oss_bucket(),
            'static_path': u'/static/',
            'static_handler_class': SmartStaticFileHandler,
        }

        the_settings.update(more_settings)
        routes = get_routes()
        self.app = Application(routes, **the_settings)
        self.app.settings['template_loader'].env.globals.update({
            'options':
            options,
            'datetime':
            datetime.datetime,
        })
Exemple #8
0
    def setup(self):
        settings.define_app_options()
        parse_command_line(final=False)
        current_dir = os.path.dirname(os.path.abspath(__file__))
        logging.info('Running in %s mode' % ('debug' if options.debug else 'production'))
        print '#' * 23
        print options.debug

        if options.debug:
            conf_file_path = os.path.join(current_dir, 'server.conf')
        else:
            conf_file_path = os.path.join(current_dir, 'prod.conf')

        if os.path.exists(conf_file_path):
            parse_config_file(conf_file_path, final=False)

        parse_command_line(final=True)
        self.db = self.setup_db()
        self.userdb = self.setup_userdb()
Exemple #9
0
    def get_settings(self, proj_template_path, proj_static_paths):
        settings.define_app_options()
        parse_command_line(final=True)

        self_dir_path = os.path.abspath(os.path.dirname(__file__))
        loader = ChoiceLoader(
            [FileSystemLoader(proj_template_path), FileSystemLoader(os.path.join(self_dir_path, "templates"))]
        )

        SmartStaticFileHandler.file_finder = MultiFileFinder(proj_static_paths, os.path.join(self_dir_path, "static"))

        return {
            "template_loader": JinjaLoader(loader=loader, auto_escape=False),
            "debug": options.debug,
            "cookie_secret": options.cookie_secret,
            "xsrf_cookies": True,
            "static_path": u"/static/",
            "static_handler_class": SmartStaticFileHandler,
        }
Exemple #10
0
    def get_settings(self, proj_template_path, proj_static_paths):
        settings.define_app_options()
        parse_command_line(final=True)

        self_dir_path = os.path.abspath(os.path.dirname(__file__))
        loader = ChoiceLoader([
            FileSystemLoader(proj_template_path),
            FileSystemLoader(os.path.join(self_dir_path, 'templates')),
            ])

        SmartStaticFileHandler.file_finder = MultiFileFinder(
            proj_static_paths,
            os.path.join(self_dir_path, 'static'))

        return {
            'template_loader': JinjaLoader(loader=loader, auto_escape=False),
            'debug': options.debug,
            'cookie_secret': options.cookie_secret,
            'xsrf_cookies': True,

            'static_path': u'/static/',
            'static_handler_class': SmartStaticFileHandler,
        }
Exemple #11
0
    def get_settings(self, proj_template_path, proj_static_paths):
        settings.define_app_options()
        parse_command_line(final=True)

        self_dir_path = os.path.abspath(os.path.dirname(__file__))
        loader = ChoiceLoader([
            FileSystemLoader(proj_template_path),
            FileSystemLoader(os.path.join(self_dir_path, 'templates')),
            ])

        SmartStaticFileHandler.file_finder = MultiFileFinder(
            proj_static_paths,
            os.path.join(self_dir_path, 'static'))

        return {
            'template_loader': JinjaLoader(loader=loader, auto_escape=False),
            'debug': options.debug,
            'cookie_secret': options.cookie_secret,
            'xsrf_cookies': True,

            'static_path': u'/static/',
            'static_handler_class': SmartStaticFileHandler,
        }
Exemple #12
0
def setup(script_name=''):
    Subject.Subject_name
    settings.define_app_options()
    self_dir = os.path.dirname(os.path.abspath(__file__))
    parse_command_line(final=False)
    conf_filename = "server.conf"
    if not options.debug:
        conf_filename = "prod.conf"
    conf_filename = os.path.join(os.path.dirname(self_dir), conf_filename)
    if os.path.exists(conf_filename):
        parse_config_file(conf_filename, final=False)
    else:
        print 'no {} found. skip it'.format(conf_filename)
    parse_command_line(final=True)
    setup_log(options)

    dbs = {}
    for subject in Subject.Subject_name:
        dbs[subject] = MongoClient(options.mongodb_host,
                     replicaSet=options.replica_set)[options[subject+'db_name']]
        print 'Connected to '+subject+'db ', options.mongodb_host

    env = Env
    env.db = dbs
    env.tc = {}
    env.deeprender_host = options.deeprender_host

    env.subject = Subject.get('math')

    if not options.debug:
        channel = logging.StreamHandler(sys.stdout)
        channel.setFormatter(LogFormatter())
        logging.getLogger().addHandler(channel)

    gen_log.info("Env was setup for %s. Subject: %s", script_name, env.subject.zh_name)

    return env
Exemple #13
0
    def setup(self):
        settings.define_app_options()
        parse_command_line(final=True)

        self.db = self.setup_db()