summaryrefslogtreecommitdiffstats
path: root/lps_gen.py
diff options
context:
space:
mode:
authorrsiddharth <rsd@gnu.org>2019-07-13 19:27:18 -0400
committerrsiddharth <rsd@gnu.org>2019-07-13 19:27:18 -0400
commit73ccb20703f86d968cbcf617eb0eafa3e89c6b92 (patch)
tree2a35c08ef1a7c41e6878c9562ddbad817491d5ec /lps_gen.py
parentb202aa341ff1427c668985754e5f87e76aab8591 (diff)
lps_gen: Remove `lp_t` command line argument.
* docs/install/index.rst: Update usage command output. * docs/schedule/index.rst: Update lps_gen command example. * docs/speakers/index.rst: Update lps_gen command example. * lps_gen.py (RenderHTML): Change argument template -> template_name. Read template from package. (main): Remove `lp_t` command line argument. * tests/test_lps_gen.py (TestLPS.test_RenderHTML) (TestLPS.test_RenderHTML_sessions_only) (TestLPS.test_RenderHTML_nonexistent_template) (TestLPSTBA.setup, TestLPSpeakers.test_RenderHTML): Update RenderHTML call; pass template name instead of template path.
Diffstat (limited to 'lps_gen.py')
-rw-r--r--lps_gen.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/lps_gen.py b/lps_gen.py
index 82d20df..48a82a8 100644
--- a/lps_gen.py
+++ b/lps_gen.py
@@ -604,22 +604,19 @@ class LPSpeakersMarkdown(Markdown):
return lpspeakers_dict
-def RenderHTML(lp_dict, template):
+def RenderHTML(lp_dict, template_name):
"""Renders LP schedule/speakers in HTML from a python dictionary.
Returns the HTML as a string.
"""
- env = Environment(loader=FileSystemLoader(path.dirname(template)),
- trim_blocks=True, lstrip_blocks=True)
+ template_content = template_read(template_name)
+ if not template_content:
+ exit('Unable to read {} template'.format(template_name))
- template_name = path.basename(template)
- template = None
-
- try:
- template = env.get_template(template_name)
- except TemplateNotFound as e:
- print('Template {} not found.'.format(template_name))
- exit(1)
+ template = Environment(
+ trim_blocks=True,
+ lstrip_blocks=True
+ ).from_string(template_content)
lp_html = template.render(lp_dict=lp_dict)
@@ -642,26 +639,26 @@ def main():
version='lpschedule-generator version {}'
.format(__version__),
help="Show version number and exit.")
- 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()
- lp_template = args.lp_t
lp_md_content = read_file(path.abspath(args.lp_md))
- if path.exists(lp_template) and lp_md_content:
+ if lp_md_content:
+ template_name = ''
if args.schedule:
markdown = LPSMarkdown()
+ template_name = 'schedule'
elif args.speakers:
markdown = LPSpeakersMarkdown()
+ template_name = 'speakers'
else:
parser.error('No action requested, add -s or -sp switch')
lp_dict = markdown(lp_md_content)
- lp_html = RenderHTML(lp_dict, lp_template)
+ lp_html = RenderHTML(lp_dict, template_name)
if args.ical and args.schedule:
LPiCal(lp_dict, args.ical).to_ical()