cleanup and merge changes fro mthe eh14 project

This commit is contained in:
MaZderMind 2014-04-19 16:41:41 +02:00
parent ea846d3ea6
commit 4e6d5c5eeb

View file

@ -8,19 +8,25 @@ import re
import math import math
import shutil import shutil
import errno import errno
import unicodedata
import urllib2 import urllib2
#import xml.etree.ElementTree as etree
from lxml import etree from lxml import etree
from xml.sax.saxutils import escape as xmlescape
import cssutils import cssutils
import logging import logging
import textwrap
import tempfile import tempfile
import threading import threading
import multiprocessing import multiprocessing
from threading import Thread, Lock from threading import Thread, Lock
from Queue import Queue from Queue import Queue
# URL to Schedule-XML
scheduleUrl = 'http://www.fossgis.de/konferenz/2014/programm/schedule.de.xml'
# For (really) too long titles
titlemap = {
#708: "Neue WEB-Anwendungen des LGRB Baden-Württemberg im Überblick"
}
# Frames per second. Increasing this renders more frames, the avconf-statements would still need modifications # Frames per second. Increasing this renders more frames, the avconf-statements would still need modifications
fps = 25 fps = 25
@ -62,27 +68,6 @@ def ensureFilesRemoved(pattern):
for f in glob.glob(pattern): for f in glob.glob(pattern):
os.unlink(f) os.unlink(f)
# Normalizes string, converts to lowercase, removes non-alpha characters,
#and converts spaces to hyphens.
def slugify(value):
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
value = unicode(re.sub('[-\s]+', '-', value))
return value
# create a filename from the events' id and a slugified version of the title
def vorspannFilename(id, title):
return u'{0:04d}-{1}.dv'.format(id, slugify(unicode(title)))
# svg does not have a method for automatic line breaking, that rsvg is capable of
# so we do it in python as good as we can
def vorspannTitle(title):
return '</tspan><tspan x="120" dy="35">'.join(textwrap.wrap(title, 50))
def vorspannUrl(id):
return 'fossgis.de/konferenz/2014/programm/events/'+str(id)+'.de.html'
def abspannFrames(): def abspannFrames():
# 9 Sekunden # 9 Sekunden
@ -199,7 +184,7 @@ def render(infile, outfile, sequence, parameters={}, workdir='artwork'):
with open(os.path.join(workdir, infile), 'r') as fp: with open(os.path.join(workdir, infile), 'r') as fp:
svgstr = fp.read() svgstr = fp.read()
for key in parameters.keys(): for key in parameters.keys():
svgstr = svgstr.replace(key, str(parameters[key])) svgstr = svgstr.replace(key, xmlescape(str(parameters[key])))
svg = etree.fromstring(svgstr) svg = etree.fromstring(svgstr)
@ -208,7 +193,6 @@ def render(infile, outfile, sequence, parameters={}, workdir='artwork'):
for el in svg.findall(".//svg:image[@xlink:href]", namespaces=namespaces): for el in svg.findall(".//svg:image[@xlink:href]", namespaces=namespaces):
el.attrib['{http://www.w3.org/1999/xlink}href'] = 'file:///' + os.path.realpath(workdir) + '/' + el.attrib['{http://www.w3.org/1999/xlink}href'] el.attrib['{http://www.w3.org/1999/xlink}href'] = 'file:///' + os.path.realpath(workdir) + '/' + el.attrib['{http://www.w3.org/1999/xlink}href']
# frame-number counter # frame-number counter
frameNr = 0 frameNr = 0
@ -273,7 +257,7 @@ def events():
else: else:
# download the schedule # download the schedule
response = urllib2.urlopen('http://www.fossgis.de/konferenz/2014/programm/schedule.de.xml') response = urllib2.urlopen(scheduleUrl)
# read xml-source # read xml-source
xml = response.read() xml = response.read()
@ -293,22 +277,22 @@ def events():
personnames.append(person.text) personnames.append(person.text)
# yield a tupel with the event-id, event-title and person-names # yield a tupel with the event-id, event-title and person-names
yield ( int(event.get('id')), event.find('title').text, ', '.join(personnames) ) yield ( int(event.get('id')), event.find('title').text, event.find('subtitle').text or '', ', '.join(personnames) )
# debug-mode selected by --debug switch # debug-mode selected by --debug switch
if debug: if debug:
print "!!! DEBUG MODE !!!" print "!!! DEBUG MODE !!!"
title = 'OpenJUMP - Überblick, Neuigkeiten, Zusammenarbeit/Schnittstellen mit proprietärer Software'
render( render(
'vorspann.svg', 'vorspann.svg',
os.path.join('..', str(667)+".dv"), '../intro.dv',
vorspannFrames, vorspannFrames,
{ {
'$id': 667, '$id': 667,
'$title': vorspannTitle(title), '$title': 'OpenJUMP - Überblick, Neuigkeiten, Zusammenarbeit/Schnittstellen mit proprietärer Software',
'$personnames': 'Matthias Scholz' '$subtitle': 'Even more news about OpenJUMP',
'$personnames': 'Matthias S.'
} }
) )
@ -330,10 +314,6 @@ if debug:
# threaded task queue # threaded task queue
tasks = Queue() tasks = Queue()
titlemap = {
708: "Neue WEB-Anwendungen des LGRB Baden-Württemberg im Überblick"
}
# iterate over all events extracted from the schedule xml-export # iterate over all events extracted from the schedule xml-export
for (id, title, personnames) in events(): for (id, title, personnames) in events():
if id in titlemap: if id in titlemap:
@ -346,7 +326,8 @@ for (id, title, personnames) in events():
vorspannFrames, vorspannFrames,
{ {
'$id': id, '$id': id,
'$title': vorspannTitle(title), '$title': title,
'$subtitle': subtitle,
'$personnames': personnames '$personnames': personnames
} }
)) ))