Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Update update title tag script
Browse files Browse the repository at this point in the history
Now it doesn't totally die on missing exercise files.

Auditors: eater
  • Loading branch information
sophiebits committed Aug 27, 2013
1 parent 67f96b1 commit d2cc400
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions build/update_title_tags.py
Expand Up @@ -3,6 +3,7 @@
"""

import codecs
import errno
import os

import requests
Expand All @@ -22,13 +23,20 @@ def fix_title(filename, title):
lines = []
title_lines = 0

with codecs.open(full_filename, 'r', encoding='utf-8') as f:
for line in f.readlines():
if '<title>' in line:
line = u"%s<title>%s</title>\n" % (
line.split('<title>', 1)[0], title)
title_lines += 1
lines.append(line)
try:
with codecs.open(full_filename, 'r', encoding='utf-8') as f:
for line in f.readlines():
if '<title>' in line:
line = u"%s<title>%s</title>\n" % (
line.split('<title>', 1)[0], title)
title_lines += 1
lines.append(line)
except IOError, e:
# If the file's missing, the exercise probably isn't live, so skip it.
if e.errno == errno.ENOENT:
return
else:
raise

assert title_lines == 1

Expand Down

0 comments on commit d2cc400

Please sign in to comment.