def setup_flask_initial_options(): static_folder = ResourceLoader.get().configs.get('STATIC_FOLDER') template_folder = ResourceLoader.get().configs.get('TEMPLATE_FOLDER') if not static_folder: static_folder = os.path.join(ROOT, 'static') if not template_folder: template_folder = os.path.join(ROOT, 'templates') options = dict(static_url_path=STATIC_URL_PATH) options['static_folder'] = static_folder options['template_folder'] = template_folder return options
def startup_app(): # initial settings first, or change to use confd like curupira? global app if not app: args = setup_flask_initial_options() app = Flask('vclassifieds', **args) app.config.update(ResourceLoader.get().configs) app.debug = app.config.get('DEBUG', False) init_logger() try: init_mongo_engine() init_jinja_env() init_error_handler() init_login_manager() init_interceptors() init_bp_modules() app.logger.info('Start vclassifieds success from ROOT [%s]', ROOT) except Exception, e: app.logger.error('Start vclassifieds faild!') app.logger.exception(e) raise e
def init_db(): with current_app.app_context(): folder_name = app.config.get('INIT_DATA_FOLDER_NAME') folder_path = ResourceLoader.get().get_resoure(folder_name).path if folder_path and os.path.isdir(folder_path): for data_file in os.listdir(folder_path): with open(folder_path + os.path.sep + data_file, 'r') as mqls: get_db().eval(mqls.read())