From 6de17acfc06e7196dd100cd2410223f3a2ef0c07 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 3 May 2017 02:15:17 +0200 Subject: [PATCH] each talk can have a resource directory --- plugins/talks.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/talks.py b/plugins/talks.py index 17e6b9e..e8719b4 100644 --- a/plugins/talks.py +++ b/plugins/talks.py @@ -9,6 +9,7 @@ from functools import wraps import logging import re import datetime +import shutil from docutils import nodes from docutils.parsers.rst import directives, Directive @@ -43,10 +44,6 @@ def get_talk_names(): ] -def warn(s): - print('WARN:', s) - - @memoize def get_talk_data(talkname): fname = os.path.join(TALKS_PATH, talkname, 'meta.yaml') @@ -63,7 +60,7 @@ def get_talk_data(talkname): logging.warn("Talk <{}> has no `text` field".format(talkname)) data['text'] = '' if 'duration' not in data: - logging.warn("Talk <{}> has no `duration` field".format(talkname)) + logging.info("Talk <{}> has no `duration` field".format(talkname)) data['duration'] = 50 data['duration'] = int(data['duration']) if 'room' not in data: @@ -78,6 +75,9 @@ def get_talk_data(talkname): else: logging.error("Talk <{}> has malformed `time`".format(talkname)) data['id'] = talkname + resdir = os.path.join(TALKS_PATH, talkname, 'res') + if os.path.isdir(resdir) and os.listdir(resdir): + data['resources'] = resdir return data @@ -93,12 +93,6 @@ class TalkListDirective(Directive): final_argument_whitespace = True has_content = True - # TODO: use a jinja template - tmpl = u'''
-

{t[title]}

-
{t[text]}
-
''' - def run(self): tmpl = jinja_env.get_template('talk.html') return [ @@ -114,11 +108,17 @@ class TalksGenerator(generators.Generator): super(TalksGenerator, self).__init__(*args, **kwargs) def generate_context(self): - self.talks.append('sblindola') - self.talks.append('tapioco') - if os.path.isdir(self.settings['TALKS_PATH']): - self.talks += os.listdir(self.settings['TALKS_PATH']) - self._update_context(('talks', )) + self.talks = {n: get_talk_data(n) for n in get_talk_names()} + self._update_context(('talks',)) + + def generate_output(self, writer=None): + for talkname in self.talks: + if 'resources' in self.talks[talkname]: + outdir = os.path.join(self.output_path, 'talks', talkname, + 'res') + if os.path.isdir(outdir): + shutil.rmtree(outdir) + shutil.copytree(self.talks[talkname]['resources'], outdir) def add_talks_option_defaults(pelican): @@ -139,6 +139,6 @@ except ImportError: else: def register(): - #signals.get_generators.connect(get_generators) + signals.get_generators.connect(get_generators) signals.initialized.connect(add_talks_option_defaults) directives.register_directive('talklist', TalkListDirective)