Skip to content

Commit

Permalink
Catch error wphen file doesn't exist and report generation of files.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaverde committed Mar 10, 2017
1 parent 71f0b19 commit 09943e5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lektor_tipue_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from collections import defaultdict

from lektor.reporter import reporter
from lektor.pluginsystem import Plugin
from lektor.db import Page

Expand Down Expand Up @@ -53,14 +54,21 @@ def on_before_build(self, source, prog, **extra):

self.tipue_search[source.alt].append(item)

@check_enabled
def on_after_build_all(self, builder, **extra):
for alt, pages in self.tipue_search.items():
filename = os.path.join(builder.env.root_path, self.output_path,
'tipue_search_{}.json'.format(alt))

with open(filename, 'r') as f:
contents = f.read()
try:
with open(filename, 'r') as f:
contents = f.read()
except IOError:
contents = ""

if contents != json.dumps(pages):
with open(filename, 'w') as f:
f.write(json.dumps(pages))

reporter.report_generic('generated tipue search file{}'.format(
filename))

0 comments on commit 09943e5

Please sign in to comment.