Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Log a warning when a file is overwritten.

  • Loading branch information...
commit e819e8dc787a6f43d70d265d2b73cc7a3e0118c2 1 parent 94eb28b
Ryan McGuire authored
Showing with 6 additions and 1 deletion.
  1. +2 −1  blogofile/site_init/_config.py
  2. +4 −0 blogofile/writer.py
3  blogofile/site_init/_config.py
View
@@ -40,7 +40,8 @@
# This is turned off by default though, because hard links are not
# necessarily what every user wants.
site.use_hard_links = False
-
+#Warn when we're overwriting a file?
+site.overwrite_warning = True
# These are the default ignore patterns for excluding files and dirs
# from the _site directory
# These can be strings or compiled patterns.
4 blogofile/writer.py
View
@@ -115,6 +115,8 @@ def __write_files(self):
#Copy this non-template file
f_path = util.path_join(root, t_fn)
logger.debug("Copying file: " + f_path)
+ if self.config.site.overwrite_warning and os.path.exists(path):
+ logger.warn("Location is used more than once: {0}".format(f_path))
out_path = util.path_join(self.output_dir, f_path)
if self.bf.config.site.use_hard_links:
# Try hardlinking first, and if that fails copy
@@ -168,6 +170,8 @@ def materialize_template(self, template_name, location, attrs={}, lookup=None):
path = util.path_join(self.output_dir, location)
#Create the path if it doesn't exist:
util.mkdir(os.path.split(path)[0])
+ if self.config.site.overwrite_warning and os.path.exists(path):
+ logger.warn("Location is used more than once: {0}".format(location))
f = open(path, "w")
f.write(rendered)
f.close()

4 comments on commit e819e8d

Dougal Matthews

Would this be backwards incompatible? i.e. if overwrite_warning doesn't exist in the _config. Would this be better?

if getattr(self.config.site, 'overwrite_warning', False) and os.path.exists(path):
     # ...

Unless I've missed somewhere that sets default values for missing configs?

Ryan McGuire
Owner

Yep, thanks!

Ryan McGuire
Owner

Actually I take that back, it will be compatible. the configuration is distributed with Blogofile and this change is in the writer, which is part of Blogofile.

Paolo Corti

Thanks!

Please sign in to comment.
Something went wrong with that request. Please try again.