Commits

andrea_crotti committed 3040f8a

setup_blog was overwriting the three files without checking if they
are already present.
This might easily lead to lose changes in case by mistake the blog
setup is run twice.

Comments (0)

Files changed (2)

tinkerer/cmdline.py

     '''
     Sets up a new blog in the current directory.
     '''
-    writer.setup_blog()
-
-    if filename_only:
-        print("conf.py")
-    elif not quiet:
-        print("Your new blog is almost ready!")
-        print("You just need to edit a couple of lines in %s" % (os.path.relpath(paths.conf_file), ))
+    if writer.setup_blog():
+        if filename_only:
+            print("conf.py")
+        elif not quiet:
+            print("Your new blog is almost ready!")
+            print("You just need to edit a couple of lines in %s" % (os.path.relpath(paths.conf_file), ))
 
 
 

tinkerer/writer.py

     CONTRIBUTORS file)
     :license: FreeBSD, see LICENSE file
 '''
+from os import path
+
 from jinja2 import Environment, PackageLoader
 from tinkerer import paths, utils
 
     '''
     Renders the given template at the given destination with the given context.
     '''
-    with open(destination, "w") as f:
-        f.write(env.get_template(template).render(context))
+    if path.exists(destination):
+        print("%s already exists, remove it first and run it again" % destination)
+        return False
+    else:
+        with open(destination, "w") as dest:
+            dest.write(env.get_template(template).render(context))
 
+        return True
 
 
 def write_master_file():