__init__.py 文件源码

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

项目:kobo 作者: release-engineering 项目源码 文件源码
def _copy_file(path_old, path_new, name):
    # HACK: use .template suffix to prevent .py file byte compiling
    if path_new.endswith(".template"):
        path_new = path_new[:-9]

    fp_old = open(path_old, 'r')
    fp_new = open(path_new, 'w')

    # following django template sysntax
    fp_new.write(fp_old.read()\
        .replace('{{ project_name }}', name)\
        .replace('{{ project_name|upper }}', name.upper())\
        .replace('{{ project_name|camel }}', _camelize(name))\
        .replace('{{ project_name|camel_cmd }}', _camelize(name, fill_char="_"))
    )
    fp_old.close()
    fp_new.close()

    # copy permissions
    try:
        shutil.copymode(path_old, path_new)
    except OSError:
        sys.stderr.write("Notice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.\n" % path_new)


# based on django.core.management.base.copy_helper()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号