创建标准化工程目录脚本

# 创建工程目录脚本

import os
import sys

__author__ = 'LH'
path = os.path.dirname(os.path.abspath(__file__))


def start_project():
    '从命令行建立新的工程名,默认是lh'
    project_name = 'lh_demo'
    if len(sys.argv) > 1:
        project_name = sys.argv[1]

    # 创建标准化目录 与 __init__文件
    folders = ['bin', 'conf', 'core', 'db', 'log', 'utils']
    for folder in folders:
        folder_path = os.path.join(path, project_name, folder)
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)

        with open(os.path.join(path, project_name, folder, '__init__.py'), 'w'):
            pass

    # 创建readme
    with open(os.path.join(path, project_name, 'readme.md'), 'w') as f:
        f.write('#'+project_name + '\n\n')
        f.write('> Author:' + __author__ + '\n')


def main():
    start_project()

if __name__ == '__main__':
    main()

 

使用方法: 在命令行终端 输入 python startproject.py 工程名

程序的入口bin-》main.py中需要定义当前的环境

import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)


from core import memo


def main():
    m = memo.Memo()
    m.test()

if __name__ == '__main__':
    main()

 

posted @ 2018-05-26 13:25  娄先生  阅读(270)  评论(0编辑  收藏  举报
levels of contents