From b859aa8d8fd0d2e70906c978f2b333c2223d353d Mon Sep 17 00:00:00 2001 From: boyska Date: Mon, 22 May 2017 11:13:25 +0200 Subject: [PATCH] errori un po piu chiari --- plugins/talks.py | 97 ++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/plugins/talks.py b/plugins/talks.py index d3950e5..8593539 100644 --- a/plugins/talks.py +++ b/plugins/talks.py @@ -103,50 +103,54 @@ def get_talk_data(talkname): return None if data is None: return None - if 'title' not in data: - logging.warn("Talk <{}> has no `title` field".format(talkname)) - data['title'] = talkname - if 'text' not in data: - logging.warn("Talk <{}> has no `text` field".format(talkname)) - data['text'] = '' - if 'duration' not in data: - logging.info("Talk <{}> has no `duration` field (50min used)" - .format(talkname)) - data['duration'] = 50 - data['duration'] = int(data['duration']) - if data['duration'] < GRID_STEP: - logging.info("Talk <{}> lasts only {} minutes; changing to {}" - .format(talkname, data['duration'], GRID_STEP)) - data['duration'] = GRID_STEP - if 'links' not in data or not data['links']: - data['links'] = [] - if 'contacts' not in data or not data['contacts']: - data['contacts'] = [] - if 'needs' not in data or not data['needs']: - data['needs'] = [] - if 'room' not in data: - logging.warn("Talk <{}> has no `room` field".format(talkname)) - if 'time' not in data or 'day' not in data: - logging.warn("Talk <{}> has no `time` or `day`".format(talkname)) - if 'time' in data: - del data['time'] + try: + if 'title' not in data: + logging.warn("Talk <{}> has no `title` field".format(talkname)) + data['title'] = talkname + if 'text' not in data: + logging.warn("Talk <{}> has no `text` field".format(talkname)) + data['text'] = '' + if 'duration' not in data: + logging.info("Talk <{}> has no `duration` field (50min used)" + .format(talkname)) + data['duration'] = 50 + data['duration'] = int(data['duration']) + if data['duration'] < GRID_STEP: + logging.info("Talk <{}> lasts only {} minutes; changing to {}" + .format(talkname, data['duration'], GRID_STEP)) + data['duration'] = GRID_STEP + if 'links' not in data or not data['links']: + data['links'] = [] + if 'contacts' not in data or not data['contacts']: + data['contacts'] = [] + if 'needs' not in data or not data['needs']: + data['needs'] = [] + if 'room' not in data: + logging.warn("Talk <{}> has no `room` field".format(talkname)) + if 'time' not in data or 'day' not in data: + logging.warn("Talk <{}> has no `time` or `day`".format(talkname)) + if 'time' in data: + del data['time'] + if 'day' in data: + del data['day'] if 'day' in data: - del data['day'] - if 'day' in data: - data['day'] = get_global_data()['startdate'] + datetime.timedelta(days=data['day']) - if 'time' in data and 'day' in data: - timeparts = re.findall(r'\d+', str(data['time'])) - if 4 > len(timeparts) > 0: - timeparts = [int(p) for p in timeparts] - data['time'] = datetime.datetime.combine(data['day'], - datetime.time(*timeparts)) - else: - logging.error("Talk <{}> has malformed `time`".format(talkname)) - data['id'] = talkname - resdir = os.path.join(TALKS_PATH, talkname, TALK_ATTACHMENT_PATH) - if os.path.isdir(resdir) and os.listdir(resdir): - data['resources'] = resdir - return data + data['day'] = get_global_data()['startdate'] + datetime.timedelta(days=data['day']) + if 'time' in data and 'day' in data: + timeparts = re.findall(r'\d+', str(data['time'])) + if 4 > len(timeparts) > 0: + timeparts = [int(p) for p in timeparts] + data['time'] = datetime.datetime.combine(data['day'], + datetime.time(*timeparts)) + else: + logging.error("Talk <{}> has malformed `time`".format(talkname)) + data['id'] = talkname + resdir = os.path.join(TALKS_PATH, talkname, TALK_ATTACHMENT_PATH) + if os.path.isdir(resdir) and os.listdir(resdir): + data['resources'] = resdir + return data + except: + logging.exception("Error on talk %s", talkname) + raise jinja_env = jinja2.Environment( @@ -264,13 +268,16 @@ class TalkGridDirective(Directive): def talks_to_ics(): content = u'BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:pelican\n' for t in all_talks(): - content += talk_to_ics(t) + try: + content += talk_to_ics(t) + except: + logging.exception("Error producing calendar for talk %s", t['id']) content += 'END:VCALENDAR\n' return content def talk_to_ics(talk): - if 'time' not in talk or 'duration' not in talk: + if 'time' not in talk or 'duration' not in talk or 'room' not in talk: return '' start = talk['time'] end = start + datetime.timedelta(minutes=talk['duration'])