Ejemplo n.º 1
0
def create_app(config_filepath='resource/config.cfg'):
    '''
    포토로그 애플리케이션을 생성하는 함수.
    Args:
        config_filepath: 설정파일의 위치

    Returns: Flask 객체

    '''
    photolog_app = Flask(__name__)

    # 기본 설정은 PhotologConfig 객체에 정의되있고 운영 환경 또는 기본 설정을 변경을 하려면
    # 실행 환경변수인 PHOTOLOG_SETTINGS에 변경할 설정을 담고 있는 파일 경로를 설정
    from photolog.photolog_config import PhotologConfig
    photolog_app.config.from_object(
        PhotologConfig)  # photolog_config.py로부터(기본설정)
    photolog_app.config.from_pyfile(config_filepath,
                                    silent=True)  # config.cfg 로부터
    print_settings(photolog_app.config.iteritems())

    # 로그 초기화
    from photolog.photolog_logger import Log
    log_filepath = os.path.join(photolog_app.root_path,
                                photolog_app.config['LOG_FILE_PATH'])
    Log.init(log_filepath=log_filepath)

    # 데이터베이스 처리
    from photolog.database import DBManager
    db_filepath = os.path.join(photolog_app.root_path,
                               photolog_app.config['DB_FILE_PATH'])
    db_url = photolog_app.config['DB_URL'] + db_filepath
    DBManager.init(db_url, eval(photolog_app.config['DB_LOG_FLAG']))
    DBManager.init_db()

    # 뷰 함수 모듈은 어플리케이션 객체 생성하고 블루프린트 등록전에
    # 뷰 함수가 있는 모듈을 임포트해야 해당 뷰 함수들을 인식할 수 있음
    from photolog.controller import *

    from photolog.photolog_blueprint import photolog
    photolog_app.register_blueprint(photolog)

    # SessionInterface 설정.
    # Redis를 이용한 세션 구현은 cache_session.RedisCacheSessionInterface 임포트하고
    # app.session_interface에 RedisCacheSessionInterface를 할당
    from photolog.cache_session import SimpleCacheSessionInterface
    photolog_app.session_interface = SimpleCacheSessionInterface()

    # 공통으로 적용할 HTTP 404과 500 에러 핸들러를 설정
    photolog_app.error_handler_spec[None][404] = not_found
    photolog_app.error_handler_spec[None][500] = server_error

    # 페이징 처리를 위한 템플릿 함수
    photolog_app.jinja_env.globals['url_for_other_page'] = \
        url_for_other_page

    return photolog_app
Ejemplo n.º 2
0
def create_app(config_filepath='resource/config.cfg'):
    photolog_app = Flask(__name__)

    # 기본 설정은 PhotologConfig 객체에 정의되있고 운영 환경 또는 기본 설정을 변경을 하려면
    # 실행 환경변수인 PHOTOLOG_SETTINGS에 변경할 설정을 담고 있는 파일 경로를 설정
    from photolog.photolog_config import PhotologConfig
    photolog_app.config.from_object(PhotologConfig)
    # photolog_app.config.from_pyfile(config_filepath, silent=True)
    print_settings(photolog_app.config.items())


    # 로그 초기화
    from photolog.photolog_logger import Log
    log_filepath = os.path.join(photolog_app.root_path,
                                photolog_app.config['LOG_FILE_PATH'])
    Log.init(log_filepath=log_filepath)

    # 데이터베이스 처리
    from photolog.database import DBManager
    db_filepath = os.path.join(photolog_app.root_path,
                               photolog_app.config['DB_FILE_PATH'])
    db_url = photolog_app.config['DB_URL'] + db_filepath
    DBManager.__init__(db_url, eval(photolog_app.config['DB_LOG_FLAG']))
    DBManager.init_db()

    # 뷰 함수 모듈은 어플리케이션 객체 생성하고 블루프린트 등록전에 뷰 함수가 있는 모듈을 임포트해야 해당 뷰 함수들을 인식할 수 있음
    from photolog.controller import login
    from photolog.controller import register_user


    from photolog.photolog_blueprint import photolog
    photolog_app.register_blueprint(photolog)




    # sessionInterface 설정
    # Redis를 이용한 세션 구현은 cache_session.RedisCacheSessionInterface 임포트하고
    # app.session_interface에 RedisCacheSessionInterface를 할당
    from photolog.cache_session import SimpleCacheSessionInterface
    photolog_app.session_interface = SimpleCacheSessionInterface()

    # 공통으로 적용할 HTTP 404, 500 에러 핸들러를 설정
    # error_handler_spec() 함수는 딕셔너리의 값으로 다시 딕셔너리가 사용된 중첩 딕셔너리
    # 첫 번째 키는 블루프린트이고 'None'으로 설정하면 애플리케이션 단위로 에러 핸들러가 등록된다.
    # photolog_app.error_handler_spec[None][404] = not_found
    # photolog_app.error_handler_spec[None][500] = server_error

    # 페이징 처리를 위한 템플릿 함수
    photolog_app.jinja_env.globals['url_for_other_page'] = \
        url_for_other_page

    return photolog_app
Ejemplo n.º 3
0
def create_app(config_filepath='resource/config.cfg'):
    photolog_app = Flask(__name__)

    # 기본 설정은 PhotologConfig 객체에 정의되있고 운영 환경 또는 기본 설정을 변경을 하려면
    # 실행 환경변수인 PHOTOLOG_SETTINGS에 변경할 설정을 담고 있는 파일 경로를 설정 
    from photolog.photolog_config import PhotologConfig
    photolog_app.config.from_object(PhotologConfig)
    photolog_app.config.from_pyfile(config_filepath, silent=True)
    print_settings(photolog_app.config.items())
        
    # 로그 초기화
    from photolog.photolog_logger import Log
    log_filepath = os.path.join(photolog_app.root_path, 
                                photolog_app.config['LOG_FILE_PATH'])
    Log.init(log_filepath=log_filepath)
    
    # 데이터베이스 처리 
    from photolog.database import DBManager
    db_filepath = os.path.join(photolog_app.root_path, 
                               photolog_app.config['DB_FILE_PATH'])
    db_url = photolog_app.config['DB_URL'] + db_filepath
    DBManager.init(db_url, eval(photolog_app.config['DB_LOG_FLAG']))    
    DBManager.init_db()
       
    # 뷰 함수 모듈은 어플리케이션 객체 생성하고 블루프린트 등록전에 
    # 뷰 함수가 있는 모듈을 임포트해야 해당 뷰 함수들을 인식할 수 있음
    from photolog.controller import login
    from photolog.controller import photo_show
    from photolog.controller import photo_upload
    from photolog.controller import register_user
    from photolog.controller import twitter
    
    from photolog.photolog_blueprint import photolog
    photolog_app.register_blueprint(photolog)
    
    # SessionInterface 설정.
    # Redis를 이용한 세션 구현은 cache_session.RedisCacheSessionInterface 임포트하고
    # app.session_interface에 RedisCacheSessionInterface를 할당
    from photolog.cache_session import SimpleCacheSessionInterface
    photolog_app.session_interface = SimpleCacheSessionInterface()
    
    # 공통으로 적용할 HTTP 404과 500 에러 핸들러를 설정
    photolog_app.error_handler_spec[None][404] = not_found
    photolog_app.error_handler_spec[None][500] = server_error
    
    # 페이징 처리를 위한 템플릿 함수
    photolog_app.jinja_env.globals['url_for_other_page'] = \
        url_for_other_page
    
    return photolog_app
Ejemplo n.º 4
0
def create_app(config_filepath='resource/config.cfg'):
    # 기본 설정은 PhotologConfig 객체에 정의되있고 운영 환경 또는 기본 설정을 변경을 하려면
    # 실행 환경변수인 PHOTOLOG_SETTINGS에 변경할 설정을 담고 있는 파일 경로를 설정 
    from photolog.photolog_config import PhotologConfig

    photolog_app = Flask(__name__)
    photolog_app.config.from_object(PhotologConfig)
    photolog_app.config.from_pyfile(config_filepath, slient=True)
    print_setting(photolog_app.config.items())

    # 로그 초기화
    from photolog.photolog_logger import Log

    log_filepath = os.path.join(photolog_app.root_path, 
                                photolog_app.config['LOG_FILE_PATH']))
    Log.init(log_filepath=log_filepath)

    # data base처리
    from photolog.database import DBManager
    db_filepath = os.path.join( photolog_app.root_path,
                                photolog_app.config['DB_FILE_PATH'])
Ejemplo n.º 5
0
def create_app(config_filepath="resource/config.cfg"):
    """hi."""
    photolog_app = Flask(__name__)

    from photolog.photolog_config import PhotologConfig
    from photolog.photolog_logger import Log
    from photolog.database import DBManager
    from photolog.controller import *
    from photolog.cache_session import SimpleCacheSessionInterface
    from photolog.photolog_blueprint import photolog

    photolog_app.config.from_object(PhotologConfig)
    photolog_app.config.from_pyfile(config_filepath, silent=True)
    print_settings(photolog_app.config.iteritems())

    log_filepath = os.path.join(photolog_app.root_path,
                                photolog_app.config["LOG_FILE_PATH"])
    Log.init(log_filepath=log_filepath)

    db_filepath = os.path.join(photolog_app.root_path,
                               photolog_app.config['DB_FILE_PATH'])
    db_url = photolog_app.config['DB_URL'] + db_filepath
    DBManager.init(db_url, eval(photolog_app.config['DB_LOG_FLAG']))
    DBManager.init_db()

    photolog_app.register_blueprint(photolog)

    photolog_app.session_interface = SimpleCacheSessionInterface()

    photolog_app.error_handler_spec[None][404] = not_found
    photolog_app.error_handler_spec[None][500] = server_error

    photolog_app.jinja_env.globals["url_for_other_page"] = \
        url_for_other_page

    return photolog_app