added a keep commandline switch (-k, --keep)

-keep output directory if keep commandline switch is provided
-added KEEP_OUTPUT_DIRECTORY to settings (default is to delete output
directory before processing)
-updated documentation
This commit is contained in:
Florian Preinstorfer 2010-12-14 23:45:45 +01:00
commit 1d2af7aa01
3 changed files with 14 additions and 8 deletions

View file

@ -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

View file

@ -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__':

View file

@ -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):