Skip to content
This repository was archived by the owner on Jan 29, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
language: python

python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"

cache:
directories:
- $HOME/.cache/pip
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ help:
@echo ''

build:
python hooks/flat_schedule.py
python hooks/guidebook.py
python hooks/schedule_summary.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have these been added here? Does wok now not invoke the hooks?

The problem with this is that these hooks get run before the site gets built. Some of the hooks depend on the built HTML, so either they will work with old HTML, or will fail because there is not old HTML.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can be removed. I did that while trying to workaround the hooks not running. Fixing it.

wok

serve:
python hooks/flat_schedule.py
python hooks/guidebook.py
python hooks/schedule_summary.py
wok --serve

test:
Expand Down
21 changes: 5 additions & 16 deletions hooks/__hooks__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
''' __hooks__.py
from flat_schedule import create_flat_schedule
from guidebook import create_csv_schedule
from schedule_summary import create_summary_schedule

Attach Python functions to wok hooks.
'''

import flat_schedule
import guidebook
import schedule_summary

# The `hooks` dictionary that wok will import
# See http://wok.mythmon.com/docs/hooks/
hooks = {
'site.done': [
flat_schedule.create_flat_schedule,
guidebook.create_csv_schedule,
schedule_summary.create_summary_schedule,
],
}
'site.done': [create_flat_schedule, create_csv_schedule, create_summary_schedule],
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a cosmetic change -- am I correct? Unless there's a good reason to, I think it's worth avoiding making cosmetic changes in an unrelated pull request.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what the hell went on here. I must have deleted the file by mistake somehow because it wasn't on my repo, I'll reset it.

19 changes: 11 additions & 8 deletions hooks/flat_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import datetime
import errno
import io
import itertools
import os
import re

Expand All @@ -14,6 +13,10 @@
import vobject
#import yaml

try:
from itertools import chain, repeat, izip_longest as zip_longest
except ImportError: # python 3
from itertools import chain, repeat, zip_longest

def parse_date(s):
"""Returns a datetime.date, from a date in the tabular schedule
Expand Down Expand Up @@ -66,11 +69,11 @@ def collapse_whitespace(s):


def repeat_none(value, times):
for i in xrange(times):
for i in range(times):
yield None


def colspan_cells(cells, fillfunc=itertools.repeat):
def colspan_cells(cells, fillfunc=repeat):
"""Yields td or th elements, repeating them as necessary for colspan=n
"""
for cell in cells:
Expand All @@ -80,7 +83,7 @@ def colspan_cells(cells, fillfunc=itertools.repeat):
yield item


def rowspan_cells(cells, rowspans, fillfunc=itertools.repeat):
def rowspan_cells(cells, rowspans, fillfunc=repeat):
"""Yields td or th elements, repeating them as necessary for colspan=n
& rowspan=n.
"""
Expand Down Expand Up @@ -109,7 +112,7 @@ def parse_rooms(table):
"""
row1 = colspan_cells(table.xpath('./thead/tr[1]/th')[1:])
row2 = colspan_cells(table.xpath('./thead/tr[2]/th')[1:])
for th1, th2 in itertools.izip_longest(row1, row2):
for th1, th2 in zip_longest(row1, row2):
text1 = collapse_whitespace(th1.text)
text2 = collapse_whitespace(th2.text) if th2 is not None else ''
if text2:
Expand Down Expand Up @@ -200,12 +203,12 @@ def parse_event(td, default_room=None):
def stringify_children(node):
# http://stackoverflow.com/a/28173933/293340
parts = ([node.text]
+ list(itertools.chain(*([lxml.html.tostring(c, with_tail=False),
+ list(chain(*([lxml.html.tostring(c, with_tail=False),
c.tail] for c in node.getchildren())
))
+ [node.tail])
# filter removes possible Nones in texts and tails
return ''.join(part for part in parts if part is not None)
return ''.join(str(part) for part in parts if part is not None)


def events(table):
Expand Down Expand Up @@ -414,7 +417,7 @@ def add_tz(dt):

ics_path = os.path.join(config['output_dir'], 'schedule.ics')
with io.open(ics_path, 'w', encoding='utf-8') as f:
f.write(cal.serialize().decode('utf-8'))
f.write(cal.serialize())


def create_flat_schedule(config):
Expand Down
11 changes: 7 additions & 4 deletions hooks/guidebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

import codecs
import csv
import cStringIO
import io
import os

try:
from cStringIO import StringIO
except ImportError: # python 3
from io import StringIO

from flat_schedule import (mkdirs,
read_html_tabular_schedule)

Expand All @@ -23,15 +27,14 @@ class UnicodeWriter(object):
# https://docs.python.org/2.7/library/csv.html#writer-objects

def __init__(self, f, dialect=csv.excel, encoding='utf-8', **kwds):
self.queue = cStringIO.StringIO()
self.queue = StringIO()
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()

def writerow(self, row):
self.writer.writerow([s.encode('utf-8') for s in row])
data = self.queue.getvalue()
data = data.decode('utf-8')
data = self.encoder.encode(data)
self.stream.write(data)
self.queue.truncate(0)
Expand Down Expand Up @@ -78,7 +81,7 @@ def extract_description(talk, config):
if talk['type'] in EVENT_TYPES:
path = os.path.join(config['content_dir'], talk['href'].strip('/') + '.md')
with open(path) as f:
text = f.read().decode('utf-8')
text = f.read()
# Remove metadata if present.
idx = text.find('###')
if idx != -1:
Expand Down
11 changes: 7 additions & 4 deletions hooks/schedule_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

import codecs
import csv
import cStringIO
import io
import os

try:
from cStringIO import StringIO
except ImportError:
from io import StringIO


from flat_schedule import mkdirs, read_html_tabular_schedule


Expand All @@ -23,15 +28,14 @@ class UnicodeWriter(object):
# https://docs.python.org/2.7/library/csv.html#writer-objects

def __init__(self, f, dialect=csv.excel, encoding='utf-8', **kwds):
self.queue = cStringIO.StringIO()
self.queue = StringIO()
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()

def writerow(self, row):
self.writer.writerow([s.encode('utf-8') for s in row])
data = self.queue.getvalue()
data = data.decode('utf-8')
data = self.encoder.encode(data)
self.stream.write(data)
self.queue.truncate(0)
Expand Down Expand Up @@ -71,7 +75,6 @@ def extract_speaker(talk, config):
path = os.path.join(config['content_dir'], talk['href'].strip('/') + '.md')
with open(path) as f:
for line in f:
line = line.decode('utf-8')
if line[:4] == '### ':
return line[4:].strip()
return ''
Expand Down
14 changes: 3 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
awesome-slugify==1.4
docutils==0.8.1
Jinja2==2.7.3
LinkChecker==9.3
#LinkChecker==9.3 # waiting for py3 version
lxml==3.4.4
Markdown==2.1.1
MarkupSafe==0.23
py==1.4.27
Pygments==1.4
pytest==2.5.2
python-dateutil==2.4.2
pytz==2015.4
PyYAML==3.10
regex==2015.5.10
requests==2.7.0
six==1.9.0
Unidecode==0.4.17
vobject==0.6.6
wok==1.1.1
-e git+https://github.com/tBaxter/vobject.git@5bdf21751a6f443045e05db862e00be5bbd006f3#egg=vobject
-e git+https://github.com/jneves/wok.git@21ce6ea44483218b2380104b6ada8865122ddf2c#egg=wok