From e09444fa89ba6d809ae900448892d6ee6e62ea89 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sat, 7 May 2011 19:27:33 +0100 Subject: [PATCH] Don't delete the output dir as a default behaviour. Fixes #107 --- docs/settings.rst | 2 +- pelican/__init__.py | 23 ++++++++++++----------- pelican/settings.py | 2 +- pelican/utils.py | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 363ffc87..0b3b7034 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -46,7 +46,7 @@ Setting name (default value) what does it do? `FEED` (``'feeds/all.atom.xml'``) relative url to output the atom feed. `FEED_RSS` (``None``, i.e. no RSS) relative url to output the rss feed. `JINJA_EXTENSIONS` (``[]``) A list of any Jinja2 extensions you want to use. -`KEEP_OUTPUT_DIRECTORY` (``False``) Keep the output directory and just update all +`DELETE_OUTPUT_DIRECTORY` (``False``) Delete the output directory instead of just updating all the generated files. `LOCALE` (''[2]_) Change the locale. `MARKUP` (``('rst', 'md')``) A list of available markup languages you want diff --git a/pelican/__init__.py b/pelican/__init__.py index 52775f94..74bb1058 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -14,7 +14,7 @@ VERSION = "2.6.0" class Pelican(object): def __init__(self, settings=None, path=None, theme=None, output_path=None, - markup=None, keep=False): + markup=None, delete_outputdir=False): """Read the settings, and performs some checks on the environment before doing anything else. """ @@ -32,7 +32,7 @@ class Pelican(object): output_path = output_path or settings['OUTPUT_PATH'] self.output_path = os.path.realpath(output_path) self.markup = markup or settings['MARKUP'] - self.keep = keep or settings['KEEP_OUTPUT_DIRECTORY'] + self.delete_outputdir = delete_outputdir or settings['DELETE_OUTPUT_DIRECTORY'] # find the theme in pelican.theme if the given one does not exists if not os.path.exists(self.theme): @@ -55,7 +55,7 @@ class Pelican(object): self.theme, self.output_path, self.markup, - self.keep + self.delete_outputdir ) for cls in self.get_generator_classes() ] @@ -63,8 +63,10 @@ class Pelican(object): if hasattr(p, 'generate_context'): p.generate_context() - # erase the directory if it is not the source - if os.path.realpath(self.path).startswith(self.output_path) and not self.keep: + # erase the directory if it is not the source and if that's + # explicitely asked + if (self.delete_outputdir and + os.path.realpath(self.path).startswith(self.output_path)): clean_output_dir(self.output_path) writer = self.get_writer() @@ -101,11 +103,9 @@ def main(): help='the list of markup language to use (rst or md). Please indicate ' 'them separated by commas') parser.add_argument('-s', '--settings', dest='settings', - help='the settings of the application. Default to None.') - parser.add_argument('-k', '--keep-output-directory', dest='keep', - action='store_true', - help='Keep the output directory and just update all the generated files.' - 'Default is to delete the output directory.') + help='the settings of the application. Default to False.') + parser.add_argument('-d', '--delete-output-directory', dest='delete_outputdir', + action='store_true', help='Delete the output directory.') parser.add_argument('-v', '--verbose', action='store_const', const=log.INFO, dest='verbosity', help='Show all messages') parser.add_argument('-q', '--quiet', action='store_const', const=log.CRITICAL, dest='verbosity', @@ -135,7 +135,8 @@ def main(): cls = getattr(module, cls_name) try: - pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep) + pelican = cls(settings, args.path, args.theme, args.output, markup, + args.delete_outputdir) if args.autoreload: while True: try: diff --git a/pelican/settings.py b/pelican/settings.py index 6c0918a0..76a2d3e9 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -21,7 +21,7 @@ _DEFAULT_CONFIG = {'PATH': None, 'CSS_FILE': 'main.css', 'REVERSE_ARCHIVE_ORDER': False, 'REVERSE_CATEGORY_ORDER': False, - 'KEEP_OUTPUT_DIRECTORY': False, + 'DELETE_OUTPUT_DIRECTORY': False, 'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls 'RELATIVE_URLS': True, 'DEFAULT_LANG': 'en', diff --git a/pelican/utils.py b/pelican/utils.py index 42a4fc0c..6b456e17 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -62,7 +62,7 @@ def clean_output_dir(path): # remove all the existing content from the output folder try: - pass # WEEEEE dont kill + shutil.rmtree(path) except Exception: pass