clean some code
This commit is contained in:
parent
5a6e68909a
commit
a3913c7553
1 changed files with 16 additions and 12 deletions
|
@ -11,7 +11,6 @@ import logging
|
|||
import re
|
||||
import datetime
|
||||
import shutil
|
||||
import time
|
||||
from copy import copy
|
||||
import locale
|
||||
from contextlib import contextmanager
|
||||
|
@ -37,8 +36,6 @@ import dateutil
|
|||
pelican = None # This will be set during register()
|
||||
|
||||
|
||||
|
||||
|
||||
def memoize(function):
|
||||
'''decorators to cache'''
|
||||
memo = {}
|
||||
|
@ -111,7 +108,7 @@ def get_talk_data(talkname):
|
|||
with io.open(fname, encoding='utf8') as buf:
|
||||
try:
|
||||
data = yaml.load(buf)
|
||||
except:
|
||||
except Exception:
|
||||
logging.exception("Syntax error reading %s; skipping", fname)
|
||||
return None
|
||||
if data is None:
|
||||
|
@ -173,7 +170,7 @@ def get_talk_data(talkname):
|
|||
if os.path.isdir(resdir) and os.listdir(resdir):
|
||||
data['resources'] = resdir
|
||||
return data
|
||||
except:
|
||||
except Exception:
|
||||
logging.exception("Error on talk %s", talkname)
|
||||
raise
|
||||
|
||||
|
@ -221,7 +218,9 @@ def check_overlaps():
|
|||
@memoize
|
||||
def jinja_env():
|
||||
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,
|
||||
)
|
||||
env.filters['markdown'] = lambda text: jinja2.Markup(markdown(text))
|
||||
|
@ -312,7 +311,9 @@ class TalkGridDirective(Directive):
|
|||
rooms.add(r)
|
||||
else:
|
||||
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.
|
||||
# Remove it unless that day only has special rooms
|
||||
if '*' in rooms and len(rooms) > 1:
|
||||
|
@ -420,17 +421,19 @@ class TalksGenerator(generators.Generator):
|
|||
if 'resources' in self.talks[talkname]:
|
||||
outdir = os.path.join(self.output_path,
|
||||
pelican.settings['TALKS_PATH'], talkname,
|
||||
pelican.settings['TALKS_ATTACHMENT_PATH'])
|
||||
pelican.settings['TALKS_ATTACHMENT_PATH']
|
||||
)
|
||||
if os.path.isdir(outdir):
|
||||
shutil.rmtree(outdir)
|
||||
shutil.copytree(self.talks[talkname]['resources'], outdir)
|
||||
if ICS_ENABLED:
|
||||
with io.open(os.path.join(self.output_path, pelican.settings.get('TALKS_ICS')),
|
||||
'w',
|
||||
encoding='utf8') as buf:
|
||||
with io.open(os.path.join(self.output_path,
|
||||
pelican.settings.get('TALKS_ICS')),
|
||||
'w', encoding='utf8') as buf:
|
||||
buf.write(talks_to_ics())
|
||||
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):
|
||||
|
@ -448,6 +451,7 @@ def pelican_init(pelicanobj):
|
|||
global pelican
|
||||
pelican = pelicanobj
|
||||
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
|
|
Loading…
Reference in a new issue