diff --git a/docs/settings.rst b/docs/settings.rst index 365eb24f..e2876f96 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -52,6 +52,8 @@ Setting name what it does ? the default one ('main.css') `REVERSE_ARCHIVE_ORDER` Reverse the archives order. (True makes it in descending order: the newer first) +`KEEP_OUTPUT_DIRECTORY` Keep the output directory and just update all the generated files. + Default is to delete the output directory. ======================= ======================================================= Themes diff --git a/pelican/__init__.py b/pelican/__init__.py index 7f37f46c..a26ba8ff 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -9,7 +9,7 @@ from pelican.generators import (ArticlesGenerator, PagesGenerator, def init_params(settings=None, path=None, theme=None, output_path=None, - markup=None): + markup=None, keep=False): """Read the settings, and performs some checks on the environment before doing anything else. """ @@ -25,6 +25,7 @@ def init_params(settings=None, path=None, theme=None, output_path=None, output_path = output_path or settings['OUTPUT_PATH'] output_path = os.path.realpath(output_path) markup = markup or settings['MARKUP'] + keep = keep or settings['KEEP_OUTPUT_DIRECTORY'] # find the theme in pelican.theme if the given one does not exists if not os.path.exists(theme): @@ -42,14 +43,14 @@ def init_params(settings=None, path=None, theme=None, output_path=None, if not path: raise Exception('you need to specify a path to search the docs on !') - return settings, path, theme, output_path, markup + return settings, path, theme, output_path, markup, keep -def run_generators(generators, settings, path, theme, output_path, markup): +def run_generators(generators, settings, path, theme, output_path, markup, keep): """Run the generators and return""" context = settings.copy() - generators = [p(context, settings, path, theme, output_path, markup) + generators = [p(context, settings, path, theme, output_path, markup, keep) for p in generators] for p in generators: @@ -57,7 +58,7 @@ def run_generators(generators, settings, path, theme, output_path, markup): p.generate_context() # erase the directory if it is not the source - if output_path not in os.path.realpath(path): + if output_path not in os.path.realpath(path) and not keep: clean_output_dir(output_path) writer = Writer(output_path) @@ -67,10 +68,10 @@ def run_generators(generators, settings, path, theme, output_path, markup): p.generate_output(writer) -def run_pelican(settings, path, theme, output_path, markup): +def run_pelican(settings, path, theme, output_path, markup, delete): """Run pelican with the given parameters""" - params = init_params(settings, path, theme, output_path, markup) + params = init_params(settings, path, theme, output_path, markup, delete) generators = [ArticlesGenerator, PagesGenerator, StaticGenerator] if params[0]['PDF_GENERATOR']: # param[0] is settings processors.append(PdfGenerator) @@ -94,10 +95,12 @@ def main(): ' available.') parser.add_argument('-s', '--settings', dest='settings', help='the settings of the application. Default to None.') + parser.add_argument('-k', '--keep', action='store_true', + help='Keep the output directory and just update all the generated files. Default is to delete the output directory.') args = parser.parse_args() markup = [a.split()[0] for a in args.markup.split(',')] - run_pelican(args.settings, args.path, args.theme, args.output, markup) + run_pelican(args.settings, args.path, args.theme, args.output, markup, args.keep) if __name__ == '__main__': diff --git a/pelican/settings.py b/pelican/settings.py index bf5afacd..e3c511d3 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -17,6 +17,7 @@ _DEFAULT_CONFIG = {'PATH': None, 'FALLBACK_ON_FS_DATE': True, 'CSS_FILE': 'main.css', 'REVERSE_ARCHIVE_ORDER': False, + 'KEEP_OUTPUT_DIRECTORY': False, } def read_settings(filename):