aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiming Wang <zmwangx@gmail.com>2015-10-15 01:31:31 -0700
committerZhiming Wang <zmwangx@gmail.com>2015-10-15 01:31:31 -0700
commit5b7fc88b9b8ece62a1ee5fa32164780abb442a3e (patch)
tree31420a639e3c328a1be00d020a5f128d91e8f476
parent0da991d0ab6693e7a42f7f14d4ab63685f50dff0 (diff)
downloadmy_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 '')
-rwxr-xr-xpyblog4
1 files changed, 4 insertions, 0 deletions
diff --git a/pyblog b/pyblog
index c32464e2..593dd678 100755
--- a/pyblog
+++ b/pyblog
@@ -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)