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()
评论列表
文章目录