diff options
author | Zhiming Wang <zmwangx@gmail.com> | 2015-10-15 01:31:31 -0700 |
---|---|---|
committer | Zhiming Wang <zmwangx@gmail.com> | 2015-10-15 01:31:31 -0700 |
commit | 5b7fc88b9b8ece62a1ee5fa32164780abb442a3e (patch) | |
tree | 31420a639e3c328a1be00d020a5f128d91e8f476 /pyblog | |
parent | 0da991d0ab6693e7a42f7f14d4ab63685f50dff0 (diff) | |
download | my_new_personal_website-5b7fc88b9b8ece62a1ee5fa32164780abb442a3e.tar.xz my_new_personal_website-5b7fc88b9b8ece62a1ee5fa32164780abb442a3e.zip |
pyblog: do not overwrite existing file when creating new post
Fixes #7.
Diffstat (limited to 'pyblog')
-rwxr-xr-x | pyblog | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -833,6 +833,10 @@ def new_post(title): if os.path.exists(POSTSDIR): os.remove(POSTSDIR) os.mkdir(POSTSDIR, mode=0o755) + if os.path.exists(fullpath): + sys.stderr.write("%serror: '%s' already exists, please pick a different title%s\n" % + (RED, fullpath, RESET)) + return 1 with open(fullpath, 'w', encoding='utf-8') as newpost: newpost.write("---\n") newpost.write('title: "%s"\n' % title) |