Permalink
Browse files

Run site.output.post only once, better error handling.

  • Loading branch information...
1 parent 43f11de commit be1c6f3793eb8c201b2e4b0e94e91ae78fe74c60 @mythmon committed Feb 24, 2012
Showing with 22 additions and 21 deletions.
  1. +2 −2 wok/contrib/hooks.py
  2. +20 −19 wok/engine.py
View
@@ -25,7 +25,7 @@ def __init__(self, max_heading=3):
raise DependencyException('To use the HeadingAnchors hook, you must '
'install the library lxml.')
self.max_heading = max_heading
- logging.debug('Loaded hook HeadingAnchors')
+ logging.info('Loaded hook HeadingAnchors')
def __call__(self, page):
logging.debug('Called hook HeadingAnchors on {0}'.format(page))
@@ -38,7 +38,7 @@ def __call__(self, page):
for heading in headings:
if not heading.text:
continue
- logging.debug('[HeadingAnchors] {0} {1}'.format(heading, heading.text))
+ logging.debug('[hook/HeadingAnchors] {0} {1}'.format(heading, heading.text))
name = 'heading-{0}'.format(slugify(heading.text))
anchor = etree.Element('a')
View
@@ -188,25 +188,26 @@ def prepare_output(self):
self.run_hook('site.output.pre', self.options['output_dir'])
# Copy the media directory to the output folder
- try:
- for name in os.listdir(self.options['media_dir']):
- path = os.path.join(self.options['media_dir'], name)
- if os.path.isdir(path):
- shutil.copytree(
- path,
- os.path.join(self.options['output_dir'], name),
- symlinks=True
- )
- else:
- shutil.copy(path, self.options['output_dir'])
-
- self.run_hook('site.output.post', self.options['output_dir'])
-
- # Do nothing if the media directory doesn't exist
- except OSError:
- # XXX: We should verify that the problem was the media dir
- logging.info('There was a problem copying the media files to the '
- 'output directory.')
+ if os.path.isdir(self.options['media_dir']):
+ try:
+ for name in os.listdir(self.options['media_dir']):
+ path = os.path.join(self.options['media_dir'], name)
+ if os.path.isdir(path):
+ shutil.copytree(
+ path,
+ os.path.join(self.options['output_dir'], name),
+ symlinks=True
+ )
+ else:
+ shutil.copy(path, self.options['output_dir'])
+
+
+ # Do nothing if the media directory doesn't exist
+ except OSError:
+ logging.warning('There was a problem copying the media files '
+ 'to the output directory.')
+
+ self.run_hook('site.output.post', self.options['output_dir'])
def load_pages(self):
"""Load all the content files."""

0 comments on commit be1c6f3

Please sign in to comment.