summaryrefslogtreecommitdiffstats
path: root/lps_gen.py
diff options
context:
space:
mode:
authorrsiddharth <rsd@gnu.org>2016-01-28 08:39:17 -0500
committerrsiddharth <rsd@gnu.org>2016-01-28 08:39:17 -0500
commit77aa5dad923f4efad2e271ca3f38a7585ab2680b (patch)
treedac4286016de8bc5a3a53cc546aa3b2feadca300 /lps_gen.py
parent7ca74c9b9470b8773358f22b011136e5579237f6 (diff)
lps_gen accepts template as arg.
As per Zak's request, the script now requires the user to pass the template as (the first) argument to the script. The script does not use the template that is part of the lpschedule-generator module; indeed the internal template will be deleted later.
Diffstat (limited to 'lps_gen.py')
-rw-r--r--lps_gen.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/lps_gen.py b/lps_gen.py
index 8f04af8..8cf566c 100644
--- a/lps_gen.py
+++ b/lps_gen.py
@@ -26,7 +26,7 @@ from collections import OrderedDict
from os import path
from bs4 import BeautifulSoup
-from jinja2 import Environment, PackageLoader
+from jinja2 import Environment, FileSystemLoader
from jinja2.exceptions import TemplateNotFound
from mistune import Renderer, Markdown
@@ -144,16 +144,15 @@ class LPSMarkdown(Markdown):
return lps_dict
-def RenderHTML(lps_dict, year):
+def RenderHTML(lps_dict, template):
"""Renders LP schedule in HTML from a python dictionary.
Returns the HTML as a string.
"""
- env = Environment(loader=PackageLoader('lpschedule_generator',
- 'templates'),
+ env = Environment(loader=FileSystemLoader(path.dirname(template)),
trim_blocks=True, lstrip_blocks=True)
- template_name = 'lp-sch-%s.jinja2' % year
+ template_name = path.basename(template)
template = None
try:
@@ -172,25 +171,25 @@ def main():
parser.add_argument("--version", action="version",
version='lpschedule-generator version %s' % __version__,
help="Show version number and exit.")
- parser.add_argument("year",
- help="LP Schedule year.")
- parser.add_argument("lps_md",
- help="Path to the markdown version of LP Schedule.")
+ parser.add_argument("lp_t",
+ help="Path to the LP template.")
+ parser.add_argument("lp_md",
+ help="Path to the LP markdown.")
args = parser.parse_args()
- lps_md_content = read_file(path.abspath(args.lps_md))
- lp_year = args.year
+ lp_template = args.lp_t
+ lp_md_content = read_file(path.abspath(args.lp_md))
- if lps_md_content:
+ if path.exists(lp_template) and lp_md_content:
markdown = LPSMarkdown()
- lps_dict = markdown(lps_md_content)
- lps_html = RenderHTML(lps_dict, lp_year)
+ lp_dict = markdown(lp_md_content)
+ lp_html = RenderHTML(lp_dict, lp_template)
else:
exit(1)
- if lps_html:
+ if lp_html:
# stdout lps html
- print lps_html
+ print lp_html
else:
print 'Error generating LP HTML.'