Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Run site.output.post only once, better error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Feb 24, 2012
1 parent 43f11de commit be1c6f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions wok/contrib/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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')
Expand Down
39 changes: 20 additions & 19 deletions wok/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit be1c6f3

Please sign in to comment.