clean some code

This commit is contained in:
boyska 2018-07-01 17:03:10 +02:00
parent 5a6e68909a
commit a3913c7553

View file

@ -11,7 +11,6 @@ import logging
import re import re
import datetime import datetime
import shutil import shutil
import time
from copy import copy from copy import copy
import locale import locale
from contextlib import contextmanager from contextlib import contextmanager
@ -37,8 +36,6 @@ import dateutil
pelican = None # This will be set during register() pelican = None # This will be set during register()
def memoize(function): def memoize(function):
'''decorators to cache''' '''decorators to cache'''
memo = {} memo = {}
@ -111,7 +108,7 @@ def get_talk_data(talkname):
with io.open(fname, encoding='utf8') as buf: with io.open(fname, encoding='utf8') as buf:
try: try:
data = yaml.load(buf) data = yaml.load(buf)
except: except Exception:
logging.exception("Syntax error reading %s; skipping", fname) logging.exception("Syntax error reading %s; skipping", fname)
return None return None
if data is None: if data is None:
@ -173,7 +170,7 @@ def get_talk_data(talkname):
if os.path.isdir(resdir) and os.listdir(resdir): if os.path.isdir(resdir) and os.listdir(resdir):
data['resources'] = resdir data['resources'] = resdir
return data return data
except: except Exception:
logging.exception("Error on talk %s", talkname) logging.exception("Error on talk %s", talkname)
raise raise
@ -221,7 +218,9 @@ def check_overlaps():
@memoize @memoize
def jinja_env(): def jinja_env():
env = jinja2.Environment( env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.join(pelican.settings['TALKS_PATH'], '_templates')), loader=jinja2.FileSystemLoader(os.path.join(
pelican.settings['TALKS_PATH'],
'_templates')),
autoescape=True, autoescape=True,
) )
env.filters['markdown'] = lambda text: jinja2.Markup(markdown(text)) env.filters['markdown'] = lambda text: jinja2.Markup(markdown(text))
@ -312,7 +311,9 @@ class TalkGridDirective(Directive):
rooms.add(r) rooms.add(r)
else: else:
rooms.add(t['room']) rooms.add(t['room'])
rooms = list(sorted(rooms)) # TODO: ordina in base a qualcosa nel meta.yaml globale # TODO: ordina in base a qualcosa nel meta.yaml globale
rooms = list(sorted(rooms))
# room=* is not a real room. # room=* is not a real room.
# Remove it unless that day only has special rooms # Remove it unless that day only has special rooms
if '*' in rooms and len(rooms) > 1: if '*' in rooms and len(rooms) > 1:
@ -420,17 +421,19 @@ class TalksGenerator(generators.Generator):
if 'resources' in self.talks[talkname]: if 'resources' in self.talks[talkname]:
outdir = os.path.join(self.output_path, outdir = os.path.join(self.output_path,
pelican.settings['TALKS_PATH'], talkname, pelican.settings['TALKS_PATH'], talkname,
pelican.settings['TALKS_ATTACHMENT_PATH']) pelican.settings['TALKS_ATTACHMENT_PATH']
)
if os.path.isdir(outdir): if os.path.isdir(outdir):
shutil.rmtree(outdir) shutil.rmtree(outdir)
shutil.copytree(self.talks[talkname]['resources'], outdir) shutil.copytree(self.talks[talkname]['resources'], outdir)
if ICS_ENABLED: if ICS_ENABLED:
with io.open(os.path.join(self.output_path, pelican.settings.get('TALKS_ICS')), with io.open(os.path.join(self.output_path,
'w', pelican.settings.get('TALKS_ICS')),
encoding='utf8') as buf: 'w', encoding='utf8') as buf:
buf.write(talks_to_ics()) buf.write(talks_to_ics())
else: else:
logging.warning('module `ics` not found. ICS calendar will not be generated') logging.warning('module `ics` not found. '
'ICS calendar will not be generated')
def add_talks_option_defaults(pelican): def add_talks_option_defaults(pelican):
@ -448,6 +451,7 @@ def pelican_init(pelicanobj):
global pelican global pelican
pelican = pelicanobj pelican = pelicanobj
try: try:
import yaml import yaml
except ImportError: except ImportError: