Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Mahn committed Sep 28, 2016
1 parent 333908f commit 68389d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
22 changes: 11 additions & 11 deletions functions/convert/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@


def log_message(log, message):
print('{0}: {1}'.format('tx-md2html_convert', message))
log.append('{0}: {1}'.format('tx-md2html_convert', message))
print(message)
log.append(message)


def error_message(errors, message):
print('{0}: {1}'.format('tx-md2html_convert', message))
errors.append('{0}: {1}'.format('tx-md2html_convert', message))
print(message)
errors.append(message)


def warning_message(warnings, message):
print('{0}: {1}'.format('tx-md2html_convert', message))
warnings.append('{0}: {1}'.format('tx-md2html_convert', message))
print(message)
warnings.append(message)


def handle(event, context):
Expand Down Expand Up @@ -74,15 +74,15 @@ def handle(event, context):
try:
if resource == 'obs':
# call with closing to be sure the temp files get cleaned up
obs = transform_obs.TransformOBS(source, output_dir, options)
converter = transform_obs.TransformOBS(source, output_dir, options)
try:
obs.run()
converter.run()
except Exception as e:
error_message(errors, e.message)
finally:
log.extend(obs.log)
errors.extend(obs.errors)
warnings.extend(obs.warnings)
log.extend(converter.log)
errors.extend(converter.errors)
warnings.extend(converter.warnings)
# --- Add other resources here when implemented ---
else:
raise Exception('Resource "{0}" not currently supported'.format(resource))
Expand Down
15 changes: 7 additions & 8 deletions functions/convert/transform_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ def run(self):
# read the markdown file
with codecs.open(filename, 'r', 'utf-8-sig') as md_file:
md = md_file.read()
html = markdown.markdown(md)
complete_html += html
html = html_template.safe_substitute(content=html)
html_filename = os.path.splitext(os.path.basename(filename))[0] + ".html"
output_file = os.path.join(self.output_dir, html_filename)
write_file(output_file, html)
self.log_message(
'Converted {0} to {1}.'.format(os.path.basename(filename), os.path.basename(html_filename)))
html = markdown.markdown(md)
complete_html += html
html = html_template.safe_substitute(content=html)
html_filename = os.path.splitext(os.path.basename(filename))[0] + ".html"
output_file = os.path.join(self.output_dir, html_filename)
write_file(output_file, html)
self.log_message('Converted {0} to {1}.'.format(os.path.basename(filename), os.path.basename(html_filename)))
else:
output_file = os.path.join(self.output_dir, os.path.basename(filename))
copyfile(filename, output_file)
Expand Down

0 comments on commit 68389d7

Please sign in to comment.