コード例 #1
0
def init(project_name):
    """
    mana init <project_name>
    -- build a tiny flask project

    """
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    warning_path_exist(dst_path)

    # start init
    logger.info("[Info] start init your flask project!")

    # create dst path
    _mkdir_p(dst_path)

    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_basic_code)
    init_code('requirement.txt', _requirement_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    os.chdir(app_path)
    # create files
    init_code('views.py', _views_basic_code)
    init_code('forms.py', _forms_basic_code)
    init_code('__init__.py', _init_basic_code)

    create_templates_static_files()

    logger.info("[Info] init flask project <%s> done! " % project_name)
コード例 #2
0
ファイル: mana.py プロジェクト: ljb-2000/mana
def init(project_name):
    """
    mana init <project_name>
    """
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    start_init_info(dst_path)

     # create dst path
    _mkdir_p(dst_path)

    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_basic_code)
    init_code('requirement.txt', _requirement_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    os.chdir(app_path)
    # create files
    init_code('views.py', _views_basic_code)
    init_code('forms.py', _forms_basic_code)
    init_code('__init__.py', _init_basic_code)

    create_templates_static_files(app_path)

    init_done_info()
コード例 #3
0
ファイル: cat.py プロジェクト: neo1218/cat
def new(post):
    """
    add a new blog post
    """
    run_in_root(os.getcwd())
    pages_path = os.path.join(os.getcwd(), 'pages')
    warning_post_exist(post, pages_path)

    title = click.prompt('\_title ')
    date = click.prompt('\_date[YYYY-MM-DD] ')
    tags = click.prompt('\_tags[tag1 tag2] ')
    tags_format = tags.encode('utf-8').split()

    os.chdir(pages_path)
    init_new_code = '''title: %s
date: %s
tags: %s

'''% (title.encode('utf-8'), date.encode('utf-8'), tags_format)
    init_code('%s.md' % post, init_new_code)

    logger.info('''
        \033[33m{info}\033[0m
        ==> add new blog in pages!
        '''
    )
コード例 #4
0
def init(project_name):
    """
    build a minimal flask project
    """
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    start_init_info(dst_path)

    # create dst path
    _mkdir_p(dst_path)

    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_basic_code)
    init_code('requirement.txt', _requirement_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    os.chdir(app_path)
    # create files
    init_code('views.py', _views_basic_code)
    init_code('forms.py', _forms_basic_code)
    init_code('__init__.py', _init_basic_code)

    create_templates_static_files(app_path)

    init_done_info()
コード例 #5
0
ファイル: mana.py プロジェクト: Muxi-Studio/mana
def init(project_name):
    """
    mana init <project_name>
    -- build a tiny flask project

    """
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    warning_path_exist(dst_path)

    # start init
    logger.info("[Info] start init your flask project!")

    # create dst path
    _mkdir_p(dst_path)

    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_basic_code)
    init_code('requirement.txt', _requirement_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    os.chdir(app_path)
    # create files
    init_code('views.py', _views_basic_code)
    init_code('forms.py', _forms_basic_code)
    init_code('__init__.py', _init_basic_code)

    create_templates_static_files()

    logger.info("[Info] init flask project <%s> done! " % project_name)
コード例 #6
0
def init(project_name):
    """
    mana init <project_name>
    """

    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    # dst path exist
    if os.path.isdir(dst_path):
        logger.warning("path: %s exist,\nplease change the project name\n \
                and try again!" % dst_path)
        return

    # start init
    logger.info("start init your flask project!")

    # create dst path
    _mkdir_p(dst_path)

    # create project tree
    os.chdir(dst_path)

    # create files
    init_code('manage.py', _manage_basic_code)
    init_code('requirement.txt', _requirement_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    os.chdir(app_path)
    # create files
    init_code('views.py', _views_basic_code)
    init_code('forms.py', _forms_basic_code)
    init_code('__init__.py', _init_basic_code)

    # create templates and static
    templates_path = os.path.join(app_path, 'templates')
    static_path = os.path.join(app_path, 'static')
    _mkdir_p(templates_path)
    _mkdir_p(static_path)

    # create {img, css, js}
    os.chdir(static_path)
    img_path = os.path.join(static_path, 'img')
    css_path = os.path.join(static_path, 'css')
    js_path = os.path.join(static_path, 'js')
    _mkdir_p(img_path)
    _mkdir_p(css_path)
    _mkdir_p(js_path)

    logger.info("init flask project <%s> done! " % project_name)
コード例 #7
0
ファイル: mana.py プロジェクト: zxc0328/mana
def init(project_name):
    """
    mana init <project_name>
    """

    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    # dst path exist
    if os.path.isdir(dst_path):
        logger.warning("path: %s exist,\nplease change the project name\n \
                and try again!" % dst_path)
        return

    # start init
    logger.info("start init your flask project!")

    # create dst path
    _mkdir_p(dst_path)

    # create project tree
    os.chdir(dst_path)

    # create files
    init_code('manage.py', _manage_basic_code)
    init_code('requirement.txt', _requirement_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    os.chdir(app_path)
    # create files
    init_code('views.py', _views_basic_code)
    init_code('forms.py', _forms_basic_code)
    init_code('__init__.py', _init_basic_code)

    # create templates and static
    templates_path = os.path.join(app_path, 'templates')
    static_path = os.path.join(app_path, 'static')
    _mkdir_p(templates_path)
    _mkdir_p(static_path)

    # create {img, css, js}
    os.chdir(static_path)
    img_path = os.path.join(static_path, 'img')
    css_path = os.path.join(static_path, 'css')
    js_path = os.path.join(static_path, 'js')
    _mkdir_p(img_path)
    _mkdir_p(css_path)
    _mkdir_p(js_path)

    logger.info("init flask project <%s> done! " % project_name)
コード例 #8
0
ファイル: mana.py プロジェクト: neo1218/mana
def blueprint(blueprint_name):
    """
    create and register a blueprint
    """
    app = os.getcwd().split('/')[-1]
    if app != 'app':
        logger.warning('''\033[31m{Warning}\033[0m
==> your current path is \033[32m%s\033[0m\n
==> please create your blueprint under app folder!''' % os.getcwd())
        exit(1)

    # destination path
    dst_path = os.path.join(os.getcwd(), blueprint_name)
    if os.path.isdir(dst_path):
        logger.warning('''\033[31m{Warning}\033[0m
==> bluprint \033[32m%s\033[0m\n exist
==> please try again !''' % dst_path)
        exit(1)

    # create dst_path
    _mkdir_p(dst_path)

    # change dir
    os.chdir(dst_path)
    # create files
    init_code('__init__.py', _init_blueprint_code %
        (blueprint_name, blueprint_name))
    init_code('views.py', _views_blueprint_code %
        (blueprint_name, blueprint_name))
    init_code('forms.py', _forms_basic_code)

    # register auth in app
    os.chdir(os.path.join(dst_path, '..'))
    with open('__init__.py', 'r+') as f:
        prev = pos = 0
        while f.readline():
            prev, pos = pos, f.tell()
        f.seek(prev)
        f.write(
            '\nfrom %s import %s\napp.register_blueprint(%s, url_prefix="/%s")\n\n'
            % (
                blueprint_name, blueprint_name,
                blueprint_name, blueprint_name
            )
        )

    # create blueprint templates
    templates_path = os.path.join(os.getcwd(), 'templates')
    os.chdir(templates_path)
    blueprint_templates_path = os.path.join(templates_path, blueprint_name)
    _mkdir_p(blueprint_templates_path)

    logger.info('''\033[33m{Info}\033[0m: create blueprint done!''')
コード例 #9
0
def blueprint(blueprint_name):
    """
    create and register a blueprint
    """
    app = os.getcwd().split('/')[-1]
    if app != 'app':
        logger.warning('''\033[31m{Warning}\033[0m
==> your current path is \033[32m%s\033[0m\n
==> please create your blueprint under app folder!''' % os.getcwd())
        exit(1)

    # destination path
    dst_path = os.path.join(os.getcwd(), blueprint_name)
    if os.path.isdir(dst_path):
        logger.warning('''\033[31m{Warning}\033[0m
==> bluprint \033[32m%s\033[0m\n exist
==> please try again !''' % dst_path)
        exit(1)

    # create dst_path
    _mkdir_p(dst_path)

    # change dir
    os.chdir(dst_path)
    # create files
    init_code('__init__.py', _init_blueprint_code % (blueprint_name, blueprint_name))
    init_code('views.py', _views_blueprint_code % (blueprint_name, blueprint_name))
    init_code('forms.py', _forms_basic_code)

    # register auth in app
    os.chdir(os.path.join(dst_path, '..'))
    with open('__init__.py', 'r+') as f:
        prev = pos = 0
        while f.readline():
            prev, pos = pos, f.tell()
        f.seek(prev)
        f.write(
            '\nfrom %s import %s\napp.register_blueprint(%s, url_prefix="/%s")\n\n'
            % (
                blueprint_name, blueprint_name,
                blueprint_name, blueprint_name
            )
        )

    # create blueprint templates
    templates_path = os.path.join(os.getcwd(), 'templates')
    os.chdir(templates_path)
    blueprint_templates_path = os.path.join(templates_path, blueprint_name)
    _mkdir_p(blueprint_templates_path)

    logger.info('''\033[33m{Info}\033[0m: create blueprint done!''')
コード例 #10
0
ファイル: mana.py プロジェクト: ljb-2000/mana
def create_blueprint(app_path, blueprint, views_code, forms_code, templates_path):
    """
    create blueprint
    """
    blueprint_path = os.path.join(app_path, blueprint)
    _mkdir_p(blueprint_path)
    # create  blueprint files
    os.chdir(blueprint_path)
    init_code('__init__.py', _init_blueprint_code % (blueprint, blueprint))
    init_code('views.py', views_code)
    init_code('forms.py', forms_code)
    # main blueprint templates
    os.chdir(templates_path)
    blueprint_templates_path = os.path.join(templates_path, blueprint)
    _mkdir_p(blueprint_templates_path)

    return blueprint_templates_path
コード例 #11
0
def create_blueprint(app_path, blueprint, views_code, forms_code, templates_path):
    """
    create blueprint
    """
    blueprint_path = os.path.join(app_path, blueprint)
    _mkdir_p(blueprint_path)
    # create  blueprint files
    os.chdir(blueprint_path)
    init_code('__init__.py', _init_blueprint_code % (blueprint, blueprint))
    init_code('views.py', views_code)
    init_code('forms.py', forms_code)
    # main blueprint templates
    os.chdir(templates_path)
    blueprint_templates_path = os.path.join(templates_path, blueprint)
    _mkdir_p(blueprint_templates_path)

    return blueprint_templates_path
コード例 #12
0
ファイル: mana.py プロジェクト: zxc0328/mana
def blueprint(blueprint_name):
    """
    mana blueprint <blueprint_name>
    """

    # destination path
    dst_path = os.path.join(os.getcwd(), blueprint_name)

    # dst path exist
    if os.path.isdir(dst_path):
        logger.warning("path: %s exist,\nplease change the project name\n \
                and try again!" % dst_path)
        return

    # create dst_path
    _mkdir_p(dst_path)

    # change dir
    os.chdir(dst_path)
    # create files
    init_code('__init__.py', _init_blueprint_code % (blueprint_name, blueprint_name))
    init_code('views.py', _views_blueprint_code % (blueprint_name, blueprint_name))
    init_code('forms.py', _forms_basic_code)

    # register auth in app
    os.chdir(os.path.join(dst_path, '..'))
    with open('__init__.py', 'r+') as f:
        prev = pos = 0
        while f.readline():
            prev, pos = pos, f.tell()
        f.seek(prev)
        f.write(
            '\nfrom %s import %s\napp.register_blueprint(%s, url_prefix="/%s")\n\n'
            % (
                blueprint_name, blueprint_name,
                blueprint_name, blueprint_name
            )
        )

    # create blueprint templates
    templates_path = os.path.join(os.getcwd(), 'templates')
    os.chdir(templates_path)
    blueprint_templates_path = os.path.join(templates_path, blueprint_name)
    _mkdir_p(blueprint_templates_path)

    logger.info("init flask blueprint <%s> done! " % blueprint_name)
コード例 #13
0
def blueprint(blueprint_name):
    """
    mana blueprint <blueprint_name>
    """

    # destination path
    dst_path = os.path.join(os.getcwd(), blueprint_name)

    # dst path exist
    if os.path.isdir(dst_path):
        logger.warning("path: %s exist,\nplease change the project name\n \
                and try again!" % dst_path)
        return

    # create dst_path
    _mkdir_p(dst_path)

    # change dir
    os.chdir(dst_path)
    # create files
    init_code('__init__.py',
              _init_blueprint_code % (blueprint_name, blueprint_name))
    init_code('views.py',
              _views_blueprint_code % (blueprint_name, blueprint_name))
    init_code('forms.py', _forms_basic_code)

    # register auth in app
    os.chdir(os.path.join(dst_path, '..'))
    with open('__init__.py', 'r+') as f:
        prev = pos = 0
        while f.readline():
            prev, pos = pos, f.tell()
        f.seek(prev)
        f.write(
            '\nfrom %s import %s\napp.register_blueprint(%s, url_prefix="/%s")\n\n'
            % (blueprint_name, blueprint_name, blueprint_name, blueprint_name))

    # create blueprint templates
    templates_path = os.path.join(os.getcwd(), 'templates')
    os.chdir(templates_path)
    blueprint_templates_path = os.path.join(templates_path, blueprint_name)
    _mkdir_p(blueprint_templates_path)

    logger.info("init flask blueprint <%s> done! " % blueprint_name)
コード例 #14
0
ファイル: cat.py プロジェクト: neo1218/cat
def init():
    """
    ca init: generate a cat blog
    """
    project_path = os.path.join(os.getcwd(), 'blog')

    start_init(project_path)
    _mkdir_p(project_path)

    # init server
    os.chdir(project_path)
    init_code('blog.py', init_blog_code)
    init_code('config.py', init_config_code)

    # init pages
    pages_path = os.path.join(project_path, 'pages')
    _mkdir_p(pages_path)
    os.chdir(pages_path)
    init_code('hello-cat.md', init_hello_code)

    # init src
    src_path = os.path.join(project_path, 'src')
    _mkdir_p(src_path)

    # init theme(default theme is cat)
    theme_path = os.path.join(project_path, 'theme')
    _mkdir_p(theme_path)
    os.chdir(theme_path)
    # clone theme(default is cat)
    os.popen('git clone https://github.com/neo1218/cat-theme-cat.git cat')
    cat_path = os.path.join(theme_path, 'cat')
    templates_path = os.path.join(cat_path, 'templates')
    static_path = os.path.join(cat_path, 'static')
    templates_target_path = os.path.join(project_path, 'templates')
    static_target_path = os.path.join(project_path, 'static')
    # copy tree
    shutil.copytree(templates_path, templates_target_path)
    shutil.copytree(static_path, static_target_path)

    init_done()
コード例 #15
0
ファイル: mana.py プロジェクト: ljb-2000/mana
def startproject(project_name):
    """
    mana startproject <project_name>
    """
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)
    start_init_info(dst_path)

    # create dst path
    _mkdir_p(dst_path)

    # create project tree
    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_admin_code)
    init_code('requirement.txt', _requirement_admin_code)
    init_code('config.py', _config_sql_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    # create files
    os.chdir(app_path)
    init_code('models.py', _models_admin_code)
    init_code('__init__.py', _init_admin_code)

    # create templates and static
    css_path, templates_path = create_templates_static_files(app_path)
    # create css files
    os.chdir(css_path)
    init_code('sign.css', _auth_login_css_code)

    # create main blueprint
    create_blueprint(
        app_path,
        'main',
        _views_blueprint_code % ('main', 'main'),
        _forms_basic_code,
        templates_path
    )

    # create auth blueprint
    auth_templates_path = create_blueprint(
        app_path,
        'auth',
        _auth_views_code,
        _auth_forms_code,
        templates_path
    )
    # create auth templates files
    os.chdir(auth_templates_path)
    init_code('login.html', _auth_login_html_code)

    # create admin site
    admin_path = os.path.join(app_path, 'admin')
    _mkdir_p(admin_path)

    # create admin files
    os.chdir(admin_path)
    init_code('__init__.py', '')
    init_code('views.py', _admin_views_code)

    # create admin templates
    os.chdir(templates_path)
    admin_templates_path = os.path.join(templates_path, 'admin')
    _mkdir_p(admin_templates_path)

    # create admin templates files
    os.chdir(admin_templates_path)
    init_code('index.html', _admin_index_html_code)
    init_code('logout.html', _admin_logout_html_code)

    init_done_info()
コード例 #16
0
ファイル: mana.py プロジェクト: zxc0328/mana
def startproject(project_name):
    """
    mana startproject <project_name>
    """

    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    # dst path exist
    if os.path.isdir(dst_path):
        logger.warning("path: %s exist,\nplease change the project name\n \
                and try again!" % dst_path)
        return

    # start init
    logger.info("start init your flask project!")

    # create dst path
    _mkdir_p(dst_path)

    # create project tree
    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_admin_code)
    init_code('requirement.txt', _requirement_admin_code)
    init_code('config.py', _config_sql_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    # create files
    os.chdir(app_path)
    init_code('models.py', _models_admin_code)
    init_code('__init__.py', _init_admin_code)

    # create templates and static
    templates_path = os.path.join(app_path, 'templates')
    static_path = os.path.join(app_path, 'static')
    _mkdir_p(templates_path)
    _mkdir_p(static_path)

    # create {img, css, js}
    os.chdir(static_path)
    img_path = os.path.join(static_path, 'img')
    css_path = os.path.join(static_path, 'css')
    js_path = os.path.join(static_path, 'js')
    _mkdir_p(img_path)
    _mkdir_p(css_path)
    _mkdir_p(js_path)

    # create css files
    os.chdir(css_path)
    init_code('sign.css', _auth_login_css_code)

    # create main blueprint
    main_path = os.path.join(app_path, 'main')
    _mkdir_p(main_path)

    # create main files
    os.chdir(main_path)
    init_code('__init__.py', _init_blueprint_code % ('main', 'main'))
    init_code('views.py', _views_blueprint_code % ('main', 'main'))
    init_code('forms.py', _forms_basic_code)

    # main blueprint templates
    os.chdir(templates_path)
    main_templates_path = os.path.join(templates_path, 'main')
    _mkdir_p(main_templates_path)

    # create auth blueprint
    auth_path = os.path.join(app_path, 'auth')
    _mkdir_p(auth_path)

    # create auth files
    os.chdir(auth_path)
    init_code('__init__.py', _init_blueprint_code % ('auth', 'auth'))
    init_code('views.py', _auth_views_code)
    init_code('forms.py', _auth_forms_code)

    # auth blueprint templates
    os.chdir(templates_path)
    auth_templates_path = os.path.join(templates_path, 'auth')
    _mkdir_p(auth_templates_path)

    # create auth templates files
    os.chdir(auth_templates_path)
    init_code('login.html', _auth_login_html_code)

    # create admin site
    admin_path = os.path.join(app_path, 'admin')
    _mkdir_p(admin_path)

    # create admin files
    os.chdir(admin_path)
    init_code('__init__.py', '')
    init_code('views.py', _admin_views_code)

    # create admin templates
    os.chdir(templates_path)
    admin_templates_path = os.path.join(templates_path, 'admin')
    _mkdir_p(admin_templates_path)

    # create admin templates files
    os.chdir(admin_templates_path)
    init_code('index.html', _admin_index_html_code)
    init_code('logout.html', _admin_logout_html_code)

    logger.info("init flask project <%s> done! " % project_name)
コード例 #17
0
def rest_startproject(project_name):
    """start a restful flask project"""
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    start_init_info(dst_path)

    # create dst path
    _mkdir_p(dst_path)

    os.chdir(dst_path)

    # create files under dst_path
    init_code('manage.py', _manage_rest_code)
    init_code('requirement.txt', _rest_requirement_code)
    init_code('config.py', _config_sql_code)

    # create app/ dic under dst_path
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    os.chdir(app_path)
    # create files under app path
    init_code('models.py', _rest_models_code)
    init_code('decorators.py', _rest_decorators_code)
    init_code('__init__.py', _rest_main_init_code)

    # create api/ dir under app_path
    api_path = os.path.join(app_path, "api")
    _mkdir_p(api_path)

    os.chdir(api_path)
    # create files under api_v1.0/ dir
    init_code("auth.py", _rest_auth_code)
    init_code('user.py', _rest_user_handler_code)
    init_code('__init__.py', _rest_init_blueprint_code % ("api", "api"))

    # create test dir under dst path
    test_path = os.path.join(dst_path, 'test')
    _mkdir_p(test_path)

    os.chdir(test_path)
    # create files under test/ dir
    init_code('__init__.py', '''"the unittest package"''')
    init_code('test.py', _rest_test_code)

    # create utils/ dir under dst path
    utils_path = os.path.join(dst_path, 'utils')
    _mkdir_p(utils_path)

    os.chdir(utils_path)
    # create files under utils/ dir
    init_code('__init__.py', _rest_util_init_code)
    init_code('pagenation.py', _util_pagenation_code)

    init_done_info()
コード例 #18
0
def startproject(project_name):
    """
    build a full status project
    """
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)
    start_init_info(dst_path)

    # create dst path
    _mkdir_p(dst_path)

    # create project tree
    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_admin_code)
    init_code('requirement.txt', _requirement_admin_code)
    init_code('config.py', _config_sql_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    # create files
    os.chdir(app_path)
    init_code('models.py', _models_admin_code)
    init_code('__init__.py', _init_admin_code)

    # create templates and static
    css_path, templates_path = create_templates_static_files(app_path)
    # create css files
    os.chdir(css_path)
    init_code('sign.css', _auth_login_css_code)

    # create main blueprint
    create_blueprint(app_path, 'main',
                     _views_blueprint_code % ('main', 'main'),
                     _forms_basic_code, templates_path)

    # create auth blueprint
    auth_templates_path = create_blueprint(app_path, 'auth', _auth_views_code,
                                           _auth_forms_code, templates_path)
    # create auth templates files
    os.chdir(auth_templates_path)
    init_code('login.html', _auth_login_html_code)

    # create admin site
    admin_path = os.path.join(app_path, 'admin')
    _mkdir_p(admin_path)

    # create admin files
    os.chdir(admin_path)
    init_code('__init__.py', '')
    init_code('views.py', _admin_views_code)

    # create admin templates
    os.chdir(templates_path)
    admin_templates_path = os.path.join(templates_path, 'admin')
    _mkdir_p(admin_templates_path)

    # create admin templates files
    os.chdir(admin_templates_path)
    init_code('index.html', _admin_index_html_code)
    init_code('logout.html', _admin_logout_html_code)

    init_done_info()
コード例 #19
0
def startproject(project_name):
    """
    mana startproject <project_name>
    """
    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)
    warning_path_exist(dst_path)

    # start init
    logger.info("[Info] start init your flask project!")

    # create dst path
    _mkdir_p(dst_path)

    # create project tree
    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_admin_code)
    init_code('requirement.txt', _requirement_admin_code)
    init_code('config.py', _config_sql_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    # create files
    os.chdir(app_path)
    init_code('models.py', _models_admin_code)
    init_code('__init__.py', _init_admin_code)

    # create templates and static
    css_path, templates_path = create_templates_static_files(app_path)
    # create css files
    os.chdir(css_path)
    init_code('sign.css', _auth_login_css_code)

    # create main blueprint
    create_blueprint(app_path, 'main',
                     _views_blueprint_code % ('main', 'main'),
                     _forms_basic_code, templates_path)

    # create auth blueprint
    auth_templates_path = create_blueprint(app_path, 'auth', _auth_views_code,
                                           _auth_forms_code, templates_path)
    # create auth templates files
    os.chdir(auth_templates_path)
    init_code('login.html', _auth_login_html_code)

    # create admin site
    admin_path = os.path.join(app_path, 'admin')
    _mkdir_p(admin_path)

    # create admin files
    os.chdir(admin_path)
    init_code('__init__.py', '')
    init_code('views.py', _admin_views_code)

    # create admin templates
    os.chdir(templates_path)
    admin_templates_path = os.path.join(templates_path, 'admin')
    _mkdir_p(admin_templates_path)

    # create admin templates files
    os.chdir(admin_templates_path)
    init_code('index.html', _admin_index_html_code)
    init_code('logout.html', _admin_logout_html_code)

    logger.info("[Info] init flask project <%s> done! " % project_name)
コード例 #20
0
def startproject(project_name):
    """
    mana startproject <project_name>
    """

    # the destination path
    dst_path = os.path.join(os.getcwd(), project_name)

    # dst path exist
    if os.path.isdir(dst_path):
        logger.warning("path: %s exist,\nplease change the project name\n \
                and try again!" % dst_path)
        return

    # start init
    logger.info("start init your flask project!")

    # create dst path
    _mkdir_p(dst_path)

    # create project tree
    os.chdir(dst_path)
    # create files
    init_code('manage.py', _manage_admin_code)
    init_code('requirement.txt', _requirement_admin_code)
    init_code('config.py', _config_sql_code)

    # create app/
    app_path = os.path.join(dst_path, 'app')
    _mkdir_p(app_path)

    # create files
    os.chdir(app_path)
    init_code('models.py', _models_admin_code)
    init_code('__init__.py', _init_admin_code)

    # create templates and static
    templates_path = os.path.join(app_path, 'templates')
    static_path = os.path.join(app_path, 'static')
    _mkdir_p(templates_path)
    _mkdir_p(static_path)

    # create {img, css, js}
    os.chdir(static_path)
    img_path = os.path.join(static_path, 'img')
    css_path = os.path.join(static_path, 'css')
    js_path = os.path.join(static_path, 'js')
    _mkdir_p(img_path)
    _mkdir_p(css_path)
    _mkdir_p(js_path)

    # create css files
    os.chdir(css_path)
    init_code('sign.css', _auth_login_css_code)

    # create main blueprint
    main_path = os.path.join(app_path, 'main')
    _mkdir_p(main_path)

    # create main files
    os.chdir(main_path)
    init_code('__init__.py', _init_blueprint_code % ('main', 'main'))
    init_code('views.py', _views_blueprint_code % ('main', 'main'))
    init_code('forms.py', _forms_basic_code)

    # main blueprint templates
    os.chdir(templates_path)
    main_templates_path = os.path.join(templates_path, 'main')
    _mkdir_p(main_templates_path)

    # create auth blueprint
    auth_path = os.path.join(app_path, 'auth')
    _mkdir_p(auth_path)

    # create auth files
    os.chdir(auth_path)
    init_code('__init__.py', _init_blueprint_code % ('auth', 'auth'))
    init_code('views.py', _auth_views_code)
    init_code('forms.py', _auth_forms_code)

    # auth blueprint templates
    os.chdir(templates_path)
    auth_templates_path = os.path.join(templates_path, 'auth')
    _mkdir_p(auth_templates_path)

    # create auth templates files
    os.chdir(auth_templates_path)
    init_code('login.html', _auth_login_html_code)

    # create admin site
    admin_path = os.path.join(app_path, 'admin')
    _mkdir_p(admin_path)

    # create admin files
    os.chdir(admin_path)
    init_code('__init__.py', '')
    init_code('views.py', _admin_views_code)

    # create admin templates
    os.chdir(templates_path)
    admin_templates_path = os.path.join(templates_path, 'admin')
    _mkdir_p(admin_templates_path)

    # create admin templates files
    os.chdir(admin_templates_path)
    init_code('index.html', _admin_index_html_code)
    init_code('logout.html', _admin_logout_html_code)

    logger.info("init flask project <%s> done! " % project_name)