Переглянути джерело

Merge branch 'master' of https://git.lattuga.net/boyska/sito-hackit-18

dan 6 роки тому
батько
коміт
bbffdf9bb6
1 змінених файлів з 26 додано та 15 видалено
  1. 26 15
      plugins/talks.py

+ 26 - 15
plugins/talks.py

@@ -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,14 +170,15 @@ 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
 
 
 def overlap(interval_a, interval_b):
     '''how many minutes do they overlap?'''
-    return max(0, min(interval_a[1], interval_b[1]) - max(interval_a[0], interval_b[0]))
+    return max(0, min(interval_a[1], interval_b[1]) -
+               max(interval_a[0], interval_b[0]))
 
 
 def get_talk_overlaps(name):
@@ -220,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))
@@ -311,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:
@@ -376,12 +378,18 @@ def talks_to_ics():
 
 
 def talk_to_ics(talk):
+    def _decode(s):
+        if six.PY2:
+            return unidecode.unidecode(s)
+        else:
+            return s
+
     if 'time' not in talk or 'duration' not in talk:
         return None
     e = ics.Event(
         uid="%s@%d.hackmeeting.org" % (talk['id'],
                                        get_global_data()['startdate'].year),
-        name=unidecode.unidecode(talk['title']),
+        name=_decode(talk['title']),
         begin=talk['time'],
         duration=datetime.timedelta(minutes=talk['duration']),
         transparent=True,
@@ -390,7 +398,7 @@ def talk_to_ics(talk):
     # unidecode replaces letters with their most similar ASCII counterparts
     # (ie: accents get stripped)
     if 'text' in talk:
-        e.description = unidecode.unidecode(talk['text'])
+        e.description = _decode(talk['text'])
     e.url = pelican.settings['SCHEDULEURL'] + '#talk-' + talk['id']
     if 'room' in talk:
         e.location = talk['room']
@@ -413,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):
@@ -441,6 +451,7 @@ def pelican_init(pelicanobj):
     global pelican
     pelican = pelicanobj
 
+
 try:
     import yaml
 except ImportError: