startproject.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:noopy 作者: acuros 项目源码 文件源码
def handle(self, *options):
        if not options:
            self.show_usage('You must provide a project name')
        project_name = options[0]
        template_dir = os.path.join(noopy.__path__[0], 'project_template')

        os.mkdir(project_name)
        shutil.copytree(os.path.join(template_dir, 'src'), '{}/src'.format(project_name))

        context = dict(
            project_name=project_name,
            lambda_prefix=to_pascal_case(project_name),
        )
        context['account_id'] = raw_input('Input aws account id > ').strip()
        context['role_arn'] = raw_input('Input role arn to be granted to lambda function > ').strip()
        for file_path in glob.glob('{}/*.py'.format(template_dir)):
            with open(file_path, 'r') as f:
                content = f.read()
            filename = os.path.split(file_path)[1]
            with open(os.path.join(project_name, filename), 'w') as f:
                f.write(Template(content).substitute(**context))

        print 'Project "{}" created'.format(project_name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号