Beispiel #1
0
 def task_actions(task_action, task_subject):
     for subject_name in task_subject:
         subject = Subject.get(subject_name)
         q2html = subject.render.q2html
         subject_db = db[subject_name]
         if 'suits' in task_action:
             print subject_name, 'cache suits start'
             cache_suits(subject_db, q2html, subject_name=subject_name)
         if 'plans' in task_action:
             print subject_name, 'cache plans start'
             cache_plans(subject_db, q2html, subject_name=subject_name)
         if 'items' in task_action:
             print subject_name, 'cache all items start'
             cache_items(subject_db, q2html, subject_name=subject_name)
Beispiel #2
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