+ All Categories
Home > Documents > Python template engines and implementation in Indico

Python template engines and implementation in Indico

Date post: 23-Feb-2016
Category:
Upload: kelton
View: 28 times
Download: 0 times
Share this document with a friend
Description:
Python template engines and implementation in Indico. Marius Damarackas (Vilnius University). About me. Software engineering student Doing 3 months long internship in CERN Improving Indico template system. Outline. History of Indico templates Why change the current system ? Main tasks - PowerPoint PPT Presentation
21
Python template engines and implementation in Indico Marius Damarackas (Vilnius University)
Transcript
Page 1: Python template engines and implementation in Indico

Python template engines and implementation in IndicoMarius Damarackas (Vilnius University)

Page 2: Python template engines and implementation in Indico

2

About me•Software engineering student•Doing 3 months long internship in CERN•Improving Indico template system

Page 3: Python template engines and implementation in Indico

3

Outline1. History of Indico templates2. Why change the current system?3. Main tasks• Research about available template

systems• Integration of the new engine• Replacing XSLT with normal templates

4. Remaining work

Page 4: Python template engines and implementation in Indico

4

History of Indico templates•First generation>>> '<div width="100%%">%(param)s</div>' % {'param' : 'Value'} '<div width="100%>Value</div>'

Page 5: Python template engines and implementation in Indico

5

History of Indico templates•Second generation<% import some.module %><% foobarList = some.module.createList() %><table> <% for foo in foobarList: %>        <tr>        <% if foo == bar: %>            <td><%= foo %></td>        <% end %>        <% else: %>            <td>foobar</td>        <% end %> </tr>    <% end %></table>

Page 6: Python template engines and implementation in Indico

6

Why change the current system?•Maintenance costs•Slow when including other templates•No cache•No HTML escaping•Strange usage of the colon symbols:<% latestNews = newsList[:5] %><% end %>

Page 7: Python template engines and implementation in Indico

7

1. Research•Some of the candidates

▫Genshi▫Mako▫Cheetah▫Jinja2

Page 8: Python template engines and implementation in Indico

8

1. Research•Genshi

▫Claims to be the fastest XML template engine

▫Used by Trac▫XML and Text versions▫Features like caching, XSS protections

▫Slow▫Very difficult to translate Indico templates

Page 9: Python template engines and implementation in Indico

9

1. Research•Mako

▫Used by python.org and reddit.com▫Very fast: compiles to Python modules▫Allows to disable Unicode (a plus for

Indico)▫Template inheritance mechanism

▫Syntax could be better, more unified

Page 10: Python template engines and implementation in Indico

10

1. Research•Jinja2

▫Quite fast▫Template inheritance▫Strong separation of logic and presentation▫Difficult to adapt to Indico

•Cheetah▫Manual compilation to Python modules

Mako does it automatically▫Personally I did not like the syntax

Page 11: Python template engines and implementation in Indico

11

2. Integration•Replace old engine code with

TemplateLookup•Problem: more than 800 .tpl files to

translate

Page 12: Python template engines and implementation in Indico

12

2. Integration•Using a script to convert files•Mainly based on regexps•Some things needed to be changed by

hand

Page 13: Python template engines and implementation in Indico

13

2. Testing integration•Basic idea to test the integration:

▫use *both* old Indico and new Mako templates

•Generate outputs and do diff•If there are significant differences, save

them•Analyze differences and fix the script

Page 14: Python template engines and implementation in Indico

14

2. Testing integration•Coverage: 450+ out of 800 templates•56%, but higher if we count only active

files•Allowed to catch some bugs in the script

Page 15: Python template engines and implementation in Indico

15

3. Replacing XSLT

Page 16: Python template engines and implementation in Indico

16

3. Replacing XSLT•Generates XML, then applies

transformations•Slow•Different from other parts of the system•Lots of code duplication•Difficult to maintain

Page 17: Python template engines and implementation in Indico

17

3. Replacing XSLT•Maintenance problems…if (chatInfoState]]></xsl:text> <xsl:value-of select="./id" disable-output-escaping="yes"/> <xsl:text disable-output-escaping="yes"><![CDATA[) { IndicoUI.Effect.slide('collaborationInfoLine]]></xsl:text> <xsl:value-of select="./id" disable-output-escaping="yes"/> <xsl:text disable-output-escaping="yes"><![CDATA[', height]]></xsl:text> <xsl:value-of select="./id" disable-output-escaping="yes"/> <xsl:text disable-output-escaping="yes"><![CDATA[); $E('CRMoreInfo]]></xsl:text> <xsl:value-of select="./id" disable-output-escaping="yes"/> <xsl:text disable-output-escaping="yes"><![CDATA[').set('More info'); $E('CRMoreInfo]]></xsl:text> <xsl:value-of select="./id" disable-output-escaping="yes"/> <xsl:text disable-output-escaping="yes"><![CDATA[').dom.className = "CRDisplayMoreInfo";…

Page 18: Python template engines and implementation in Indico

18

3. Replacing XSLT•Same code in human language…if (chatInfoState${id}) { IndicoUI.Effect.slide('collaborationInfoLine${id}', height${id}); $E('CRMoreInfo${id}').set('More info'); $E('CRMoreInfo${id}').dom.className = "CRDisplayMoreInfo";…

Page 19: Python template engines and implementation in Indico

19

3. Replacing XSLT•Performance:

▫Changing the way parameters are passed▫No XML

•Maintenance:▫Most of the styles are similar▫Using Mako template inheritance

Page 20: Python template engines and implementation in Indico

20

Remaining work•Think of a smart way to restructure event

styles•Fix the i18n script to support the new

syntax

Page 21: Python template engines and implementation in Indico

21

Thank you


Recommended