From 01293dedaa0c676bd98efed202d486f60c7cbb0d Mon Sep 17 00:00:00 2001 From: "Brian St. Pierre" Date: Mon, 1 Oct 2012 20:32:18 -0400 Subject: [PATCH 1/2] Fix #530: FILES_TO_COPY error when dest dir missing If the destination directory specified by FILES_TO_COPY does not exist, site generation crashes with a CRITICAL error. This creates the destination if it does not exist. --- pelican/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pelican/utils.py b/pelican/utils.py index 60ecee34..a95b9c7d 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -90,6 +90,12 @@ def copy(path, source, destination, destination_path=None, overwrite=False): logger.info('replacement of %s with %s' % (source_, destination_)) elif os.path.isfile(source_): + try: + dest_dir = os.path.dirname(destination_) + if not os.path.exists(dest_dir): + os.makedirs(dest_dir) + except OSError, e: + logger.error("copying: %s -> %s: %r" % (source_, dest_dir, e)) shutil.copy(source_, destination_) logger.info('copying %s to %s' % (source_, destination_)) From b6cc6bd2d4c2842c0856726caee649acaf3642f0 Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Thu, 25 Oct 2012 14:24:13 +0200 Subject: [PATCH 2/2] remove useless try/except clause exception will be caught and logged later in Pelican stack --- pelican/utils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index a95b9c7d..94de9344 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -87,15 +87,13 @@ def copy(path, source, destination, destination_path=None, overwrite=False): if overwrite: shutil.rmtree(destination_) shutil.copytree(source_, destination_) - logger.info('replacement of %s with %s' % (source_, destination_)) + logger.info('replacement of %s with %s' % (source_, + destination_)) elif os.path.isfile(source_): - try: - dest_dir = os.path.dirname(destination_) - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - except OSError, e: - logger.error("copying: %s -> %s: %r" % (source_, dest_dir, e)) + dest_dir = os.path.dirname(destination_) + if not os.path.exists(dest_dir): + os.makedirs(dest_dir) shutil.copy(source_, destination_) logger.info('copying %s to %s' % (source_, destination_))