1
0
Fork 0

errori un po piu chiari

This commit is contained in:
boyska 2017-05-22 11:13:25 +02:00
parent 01827360bc
commit b859aa8d8f
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9

View file

@ -103,50 +103,54 @@ def get_talk_data(talkname):
return None return None
if data is None: if data is None:
return None return None
if 'title' not in data: try:
logging.warn("Talk <{}> has no `title` field".format(talkname)) if 'title' not in data:
data['title'] = talkname logging.warn("Talk <{}> has no `title` field".format(talkname))
if 'text' not in data: data['title'] = talkname
logging.warn("Talk <{}> has no `text` field".format(talkname)) if 'text' not in data:
data['text'] = '' logging.warn("Talk <{}> has no `text` field".format(talkname))
if 'duration' not in data: data['text'] = ''
logging.info("Talk <{}> has no `duration` field (50min used)" if 'duration' not in data:
.format(talkname)) logging.info("Talk <{}> has no `duration` field (50min used)"
data['duration'] = 50 .format(talkname))
data['duration'] = int(data['duration']) data['duration'] = 50
if data['duration'] < GRID_STEP: data['duration'] = int(data['duration'])
logging.info("Talk <{}> lasts only {} minutes; changing to {}" if data['duration'] < GRID_STEP:
.format(talkname, data['duration'], GRID_STEP)) logging.info("Talk <{}> lasts only {} minutes; changing to {}"
data['duration'] = GRID_STEP .format(talkname, data['duration'], GRID_STEP))
if 'links' not in data or not data['links']: data['duration'] = GRID_STEP
data['links'] = [] if 'links' not in data or not data['links']:
if 'contacts' not in data or not data['contacts']: data['links'] = []
data['contacts'] = [] if 'contacts' not in data or not data['contacts']:
if 'needs' not in data or not data['needs']: data['contacts'] = []
data['needs'] = [] if 'needs' not in data or not data['needs']:
if 'room' not in data: data['needs'] = []
logging.warn("Talk <{}> has no `room` field".format(talkname)) if 'room' not in data:
if 'time' not in data or 'day' not in data: logging.warn("Talk <{}> has no `room` field".format(talkname))
logging.warn("Talk <{}> has no `time` or `day`".format(talkname)) if 'time' not in data or 'day' not in data:
if 'time' in data: logging.warn("Talk <{}> has no `time` or `day`".format(talkname))
del data['time'] if 'time' in data:
del data['time']
if 'day' in data:
del data['day']
if 'day' in data: if 'day' in data:
del data['day'] data['day'] = get_global_data()['startdate'] + datetime.timedelta(days=data['day'])
if 'day' in data: if 'time' in data and 'day' in data:
data['day'] = get_global_data()['startdate'] + datetime.timedelta(days=data['day']) timeparts = re.findall(r'\d+', str(data['time']))
if 'time' in data and 'day' in data: if 4 > len(timeparts) > 0:
timeparts = re.findall(r'\d+', str(data['time'])) timeparts = [int(p) for p in timeparts]
if 4 > len(timeparts) > 0: data['time'] = datetime.datetime.combine(data['day'],
timeparts = [int(p) for p in timeparts] datetime.time(*timeparts))
data['time'] = datetime.datetime.combine(data['day'], else:
datetime.time(*timeparts)) logging.error("Talk <{}> has malformed `time`".format(talkname))
else: data['id'] = talkname
logging.error("Talk <{}> has malformed `time`".format(talkname)) resdir = os.path.join(TALKS_PATH, talkname, TALK_ATTACHMENT_PATH)
data['id'] = talkname if os.path.isdir(resdir) and os.listdir(resdir):
resdir = os.path.join(TALKS_PATH, talkname, TALK_ATTACHMENT_PATH) data['resources'] = resdir
if os.path.isdir(resdir) and os.listdir(resdir): return data
data['resources'] = resdir except:
return data logging.exception("Error on talk %s", talkname)
raise
jinja_env = jinja2.Environment( jinja_env = jinja2.Environment(
@ -264,13 +268,16 @@ class TalkGridDirective(Directive):
def talks_to_ics(): def talks_to_ics():
content = u'BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:pelican\n' content = u'BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:pelican\n'
for t in all_talks(): 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' content += 'END:VCALENDAR\n'
return content return content
def talk_to_ics(talk): 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 '' return ''
start = talk['time'] start = talk['time']
end = start + datetime.timedelta(minutes=talk['duration']) end = start + datetime.timedelta(minutes=talk['duration'])