Verified Commit 0ac6243b authored by George Kiagiadakis's avatar George Kiagiadakis Committed by Alexandr Akulich

tools: port all python tools to python3 and replace Cheetah with jinja2 templates

Fixes #17Signed-off-by: George Kiagiadakis's avatarGeorge Kiagiadakis <gkiagia@tolabaki.gr>
Signed-off-by: Alexandr Akulich's avatarAlexandr Akulich <akulichalexander@gmail.com>
parent c1a2aaf6
......@@ -3,7 +3,7 @@ all:
GIT = git
GZIP = gzip
TAR = tar
PYTHON = python
PYTHON = python3
DOC_RSYNC_FLAGS=-rvzPp --chmod=Dg+s,ug+rwX,o=rX --delete
......
<?xml version="1.0"?>
<book xmlns="http://www.devhelp.net/book" title="$spec.title" name="$name" link="index.html">
<book xmlns="http://www.devhelp.net/book" title="{{ spec.title }}" name="{{ name }}" link="index.html">
<chapters>
#for $interface in $spec.interfaces
<sub name="$interface.name" link="$interface.get_url()"/>
#end for
#if len($spec.generic_types) > 0
{% for interface in spec.interfaces %}
<sub name="{{ interface.name }}" link="{{ interface.get_url() }}"/>
{% endfor %}
{% if spec.generic_types|length > 0 %}
<sub name="Generic Types" link="generic-types.html"/>
#end if
#if len($spec.errors) > 0
{% endif %}
{% if spec.errors|length > 0 %}
<sub name="Errors" link="errors.html"/>
#end if
{% endif %}
<sub name="Full Index" link="fullindex.html"/>
</chapters>
<functions>
#for $obj in $spec.everything.values() + $spec.types.values() + $spec.errors.values()
#for $entry in $obj.get_index_entries()
<keyword type="$obj.devhelp_name" name="$entry" link="$obj.get_url()" #slurp
#if $obj.is_deprecated: deprecated="true" #slurp
/>
#end for
#end for
{% for obj in all_values %}
{% for entry in obj.get_index_entries() %}
<keyword type="{{ obj.devhelp_name }}" name="{{ entry }}" link="{{ obj.get_url() }}" {% if obj.is_deprecated %} deprecated="true" {% endif %} />
{% endfor %}
{% endfor %}
</functions>
</book>
......@@ -3,6 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Errors</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="shortcut icon" type="image/png" media="all" href="favicon.png" />
</head>
......@@ -19,45 +20,45 @@
<a name="summary"></a>
<h3>Errors</h3>
<table class="summary">
#for $error in $spec.sorted_errors
#if $error.is_deprecated
{% for error in spec.sorted_errors %}
{% if error.is_deprecated %}
<tr class="deprecated">
#else
{% else %}
<tr>
#end if
<td><a href="$error.get_url()">$error.short_name</a></td>
{% endif %}
<td><a href="{{ error.get_url() }}">{{ error.short_name }}</a></td>
<td>
#if $error.is_deprecated: (deprecated)
{% if error.is_deprecated %} (deprecated) {% endif %}
</td>
</tr>
#end for
{% endfor %}
</table>
</div>
#if $spec.errors_section
$spec.errors_section.get_docstring()
#end if
{% if spec.errors_section %}
{{ spec.errors_section.get_docstring() }}
{% endif %}
<div class="outset errors error">
<a name="errors"></a>
<h1>Errors</h1>
#for $error in $spec.sorted_errors
{% for error in spec.sorted_errors %}
<div class="inset error">
<a name="$error.get_anchor()"></a>
<span class="permalink">(<a href="$error.get_url()">Permalink</a>)</span>
<a name="{{ error.get_anchor() }}"></a>
<span class="permalink">(<a href="{{ error.get_url() }}">Permalink</a>)</span>
<h2>
$error.short_name
{{ error.short_name }}
</h2>
<div class="indent">
<code>$error.name</code>
<code>{{ error.name }}</code>
</div>
$error.get_added()
$error.get_deprecated()
$error.get_docstring()
{{ error.get_added() }}
{{ error.get_deprecated() }}
{{ error.get_docstring() }}
</div>
#end for
{% endfor %}
</div>
</div>
......
......@@ -4,56 +4,45 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Full Index</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="shortcut icon" type="image/png" media="all" href="favicon.png" />
</head>
#set $star = []
#for $item in $spec.everything.values() + $spec.errors.values() + $spec.types.values()
#echo $star.append(($item.short_name, $item))
#slurp
#end for
#echo $star.sort(key = lambda t: t[0].title())
#slurp
## one use iterators...
#set $groups = [ (l, list(g)) for l, g in (groupby($star, key = lambda t: t[0][0].upper())) ]
#set $letters = set(map(lambda t: t[0], groups))
<body>
<div class="header">
<h1>Full Index</h1>
<a href="index.html">Interface Index</a>
(<a href="interfaces.html">Compact</a>)
#for $a in map(chr, xrange(ord('A'), ord('Z')+1))
#if $a in $letters
| <a href="#$a">$a</a>
#else
| $a
#end if
#end for
{% for a in all_letters %}
{% if a in letters %}
| <a href="#{{ a }}">{{ a }}</a>
{% else %}
| {{ a }}
{% endif %}
{% endfor %}
</div>
<div class="main">
<table class="summary">
#for l, g in $groups
<tr><th colspan="3"><a name="$l"></a>$l</th></tr>
#for $n in $g
#if $n[1].is_deprecated
{% for l, g in groups %}
<tr><th colspan="3"><a name="{{ l }}"></a>{{ l }}</th></tr>
{% for n in g %}
{% if n[1].is_deprecated %}
<tr class="deprecated">
#else
{% else %}
<tr>
#end if
{% endif %}
<td>
<a href="$n[1].get_url()" title="$n[1].get_title()">$n[0]</a>
#if $n[1].is_deprecated: (deprecated)
<a href="{{ n[1].get_url() }}" title="{{ n[1].get_title() }}">{{ n[0] }}</a>
{% if n[1].is_deprecated %} (deprecated) {% endif %}
</td>
<td>$n[1].get_type_name()</td>
<td>{{ n[1].get_type_name() }}</td>
<td>
#if $n[1].parent.__class__.__name__ == 'Interface': $n[1].parent.name
{% if n[1].parent.__class__.__name__ == 'Interface' %}{{ n[1].parent.name }}{% endif %}
</td>
</tr>
#end for
#end for
{% endfor %}
{% endfor %}
<table>
</div>
......
......@@ -3,6 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Generic Types</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="shortcut icon" type="image/png" media="all" href="favicon.png" />
</head>
......@@ -19,40 +20,40 @@
<a name="summary"></a>
<h3>Generic Types</h3>
<table class="summary">
#for $type in $spec.generic_types
#if $type.is_deprecated
{% for type in spec.generic_types %}
{% if type.is_deprecated %}
<tr class="deprecated">
#else
{% else %}
<tr>
#end if
<td><a href="$type.get_url()">$type.short_name</a></td>
<td>$type.get_type_name()</td>
<td>$type.dbus_type</td>
{% endif %}
<td><a href="{{ type.get_url() }}">{{ type.short_name }}</a></td>
<td>{{ type.get_type_name() }}</td>
<td>{{ type.dbus_type }}</td>
<td>
#if $type.is_deprecated: (deprecated)
{% if type.is_deprecated %} (deprecated) {% endif %}
</td>
</tr>
#end for
{% endfor %}
</table>
</div>
<div class="outset types type">
<a name="types"></a>
<h1>Generic Types</h1>
#for $type in $spec.generic_types
{% for type in spec.generic_types %}
<div class="inset type">
<a name="$type.get_anchor()"></a>
<span class="permalink">$type.get_type_name() (<a href="$type.get_url()">Permalink</a>)</span>
<a name="{{ type.get_anchor() }}"></a>
<span class="permalink">{{ type.get_type_name() }} (<a href="{{ type.get_url() }}">Permalink</a>)</span>
<h2>
$type.short_name &mdash; $type.dbus_type
{{ type.short_name }} &mdash; {{ type.dbus_type }}
</h2>
$type.get_added()
$type.get_deprecated()
$type.get_docstring()
$type.get_breakdown()
{{ type.get_added() }}
{{ type.get_deprecated() }}
{{ type.get_docstring() }}
{{ type.get_breakdown() }}
</div>
#end for
{% endfor %}
</div>
</div>
......
......@@ -2,87 +2,88 @@
<!DOCTYPE html PUBLIC "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" "">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>$spec.title &mdash; v$spec.version</title>
<title>{{ spec.title }} &mdash; v{{ spec.version }}</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="shortcut icon" type="image/png" media="all" href="favicon.png" />
</head>
<body>
<div class="header">
<h1>$spec.title</h1>
<h1>{{ spec.title }}</h1>
<a href="#interfaces">Interfaces</a>
(<a href="interfaces.html">Compact</a>)
#if len($spec.generic_types) > 0
{% if spec.generic_types|length > 0 %}
| <a href="generic-types.html">Generic Types</a>
#end if
#if len($spec.errors) > 0
{% endif %}
{% if spec.errors|length > 0 %}
| <a href="errors.html">Errors</a>
#end if
{% endif %}
| <a href="fullindex.html">Full Index</a>
</div>
<div class="main">
<h3 class="version">Version $spec.version</h3>
<h3 class="version">Version {{ spec.version }}</h3>
<div class="legal">
<ul class="copyrights">
#for c in $spec.copyrights
<li>$c</li>
#end for
{% for c in spec.copyrights %}
<li>{{ c }}</li>
{% endfor %}
</ul>
#for $para in $spec.license
<p>$para</p>
#end for
{% for l in spec.license %}
<p>{{ l }}</p>
{% endfor %}
</div>
<a name="interfaces"></a>
<h3>Interfaces</h3>
<ul>
#def output($items)
#for $item in $items
#if $item.__class__.__name__ == 'Section'
#set $anchor = $item.short_name.replace(' ', '-')
{% macro output(items) -%}
{% for item in items %}
{% if item.__class__.__name__ == 'Section' %}
{% set anchor = item.short_name.replace(' ', '-') %}
<li class="chapter">
<a name="$anchor"></a>
$item.short_name
<span class="permalink">(<a href="#$anchor">Permalink</a>)</span>
<a name="{{ anchor }}"></a>
{{ item.short_name }}
<span class="permalink">(<a href="#{{ anchor }}">Permalink</a>)</span>
</li>
$item.get_docstring()
{{ item.get_docstring() }}
<ul>
$output($item.items)
{{ output(item.items) }}
</ul>
#else
#if $item.causes_havoc
{% else %}
{% if item.causes_havoc %}
<li class="causes-havoc">
#elif $item.is_deprecated
{% elif item.is_deprecated %}
<li class="deprecated">
#else
{% else %}
<li>
#end if
<a href="$item.get_url()">$item.name</a>
#if $item.causes_havoc
{% endif %}
<a href="{{ item.get_url() }}">{{ item.name }}</a>
{% if item.causes_havoc %}
(unstable)
#elif $item.is_deprecated
{% elif item.is_deprecated %}
(deprecated)
#end if
{% endif %}
</li>
#end if
#end for
#end def
$output($spec.items)
{% endif %}
{% endfor %}
{%- endmacro %}
{{ output(spec.items) }}
</ul>
#if len($spec.generic_types) > 0 or len($spec.errors) > 0
{% if spec.generic_types|length > 0 or spec.errors|length > 0 %}
<a name="other"></a>
<h3>Other</h3>
<ul>
#if len($spec.generic_types) > 0
{% if spec.generic_types|length > 0 %}
<li><a href="generic-types.html">Generic Types</a></li>
#end if
#if len($spec.errors) > 0
{% endif %}
{% if spec.errors|length > 0 %}
<li><a href="errors.html">Errors</a></li>
#end if
{% endif %}
</ul>
#end if
{% endif %}
</div>
</body>
......
This diff is collapsed.
......@@ -2,59 +2,60 @@
<!DOCTYPE html PUBLIC "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" "">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>$spec.title &mdash; v$spec.version</title>
<title>{{ spec.title }} &mdash; v{{ spec.version }}</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="shortcut icon" type="image/png" media="all" href="favicon.png" />
</head>
<body>
<div class="header">
<h1>$spec.title</h1>
<h1>{{ spec.title }}</h1>
<a href="index.html">Full</a>
#if len($spec.generic_types) > 0
{% if spec.generic_types|length > 0 %}
| <a href="generic-types.html">Generic Types</a>
#end if
#if len($spec.errors) > 0
{% endif %}
{% if spec.errors|length > 0 %}
| <a href="errors.html">Errors</a>
#end if
{% endif %}
| <a href="fullindex.html">Full Index</a>
</div>
<div class="main">
<b>Version $spec.version</b>
<b>Version {{ spec.version }}</b>
<a name="interfaces"></a>
<h3>Interfaces</h3>
<ul>
#for $interface in $spec.interfaces
#if $interface.causes_havoc
{% for interface in spec.interfaces %}
{% if interface.causes_havoc %}
<li class="causes-havoc">
#elif $interface.is_deprecated
{% elif interface.is_deprecated %}
<li class="deprecated">
#else
{% else %}
<li>
#end if
<a href="$interface.get_url()">$interface.name</a>
#if $interface.causes_havoc
{% endif %}
<a href="{{ interface.get_url() }}">{{ interface.name }}</a>
{% if interface.causes_havoc %}
(unstable)
#elif $interface.is_deprecated
{% elif interface.is_deprecated %}
(deprecated)
#end if
{% endif %}
</li>
#end for
{% endfor %}
</ul>
#if len($spec.generic_types) > 0 or len($spec.errors) > 0
{% if spec.generic_types|length > 0 or spec.errors|length > 0 %}
<a name="other"></a>
<h3>Other</h3>
<ul>
#if len($spec.generic_types) > 0
{% if spec.generic_types|length > 0 %}
<li><a href="generic-types.html">Generic Types</a></li>
#end if
#if len($spec.errors) > 0
{% endif %}
{% if spec.errors|length > 0 %}
<li><a href="errors.html">Errors</a></li>
#end if
{% endif %}
</ul>
#end if
{% endif %}
</div>
</body>
......
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
import os.path
......@@ -19,19 +19,21 @@ Spec(telepathy-spec tools test case)
>>> spec.interfaces
[Interface(org.freedesktop.Telepathy.SpecAutoGenTest)]
>>> spec.errors
{u'org.freedesktop.Telepathy.SpecAutoGenTest.OtherError': Error(org.freedesktop.Telepathy.SpecAutoGenTest.OtherError), u'org.freedesktop.Telepathy.SpecAutoGenTest.MiscError': Error(org.freedesktop.Telepathy.SpecAutoGenTest.MiscError)}
>>> sorted(spec.errors.items())
[('org.freedesktop.Telepathy.SpecAutoGenTest.MiscError', Error(org.freedesktop.Telepathy.SpecAutoGenTest.MiscError)), ('org.freedesktop.Telepathy.SpecAutoGenTest.OtherError', Error(org.freedesktop.Telepathy.SpecAutoGenTest.OtherError))]
>>> spec.generic_types
[]
>>> spec.types
{u'Adjective': Enum(Adjective), u'Test_Flags': Flags(Test_Flags), u'UV': Struct(UV)}
>>> sorted(spec.types)
['Adjective', 'Test_Flags', 'UV']
>>> [ spec.types[x] for x in sorted(spec.types) ]
[Enum(Adjective), Flags(Test_Flags), Struct(UV)]
>>> i = spec.interfaces[0]
>>> i
Interface(org.freedesktop.Telepathy.SpecAutoGenTest)
>>> print i.causes_havoc
>>> print(i.causes_havoc)
None
>>> i.methods
......@@ -48,7 +50,7 @@ AttributeError: 'Method' object has no attribute 'args'
>>> i.methods[0].possible_errors
[PossibleError(org.freedesktop.Telepathy.SpecAutoGenTest.MiscError), PossibleError(org.freedesktop.Telepathy.SpecAutoGenTest.OtherError)]
>>> map (lambda e: e.get_error (), i.methods[0].possible_errors)
>>> list(map (lambda e: e.get_error (), i.methods[0].possible_errors))
[Error(org.freedesktop.Telepathy.SpecAutoGenTest.MiscError), Error(org.freedesktop.Telepathy.SpecAutoGenTest.OtherError)]
>>> i.signals
......@@ -63,8 +65,8 @@ AttributeError: 'Method' object has no attribute 'args'
>>> i.properties[0].type
''
>>> i.properties[0].dbus_type
u'b'
>>> print i.properties[0].get_type ()
'b'
>>> print(i.properties[0].get_type())
None
>>> i.types
......@@ -72,21 +74,21 @@ None
>>> i.types[0].values
[EnumValue(Adjective.Leveraging), EnumValue(Adjective.Synergistic)]
>>> map (lambda v: (v.short_name, v.value), i.types[0].values)
[(u'Leveraging', u'0'), (u'Synergistic', u'1')]
>>> list(map (lambda v: (v.short_name, v.value), i.types[0].values))
[('Leveraging', '0'), ('Synergistic', '1')]
>>> i.types[1].values
[EnumValue(Test_Flags.LowBit), EnumValue(Test_Flags.HighBit)]
>>> map (lambda v: (v.short_name, v.value), i.types[1].values)
[(u'LowBit', u'1'), (u'HighBit', u'128')]
>>> list(map (lambda v: (v.short_name, v.value), i.types[1].values))
[('LowBit', '1'), ('HighBit', '128')]
>>> sorted(spec.everything.items())
[(u'org.freedesktop.Telepathy.SpecAutoGenTest', ClientInterest(org.freedesktop.Telepathy.SpecAutoGenTest)), (u'org.freedesktop.Telepathy.SpecAutoGenTest.DoStuff', Method(org.freedesktop.Telepathy.SpecAutoGenTest.DoStuff)), (u'org.freedesktop.Telepathy.SpecAutoGenTest.Introspective', Property(org.freedesktop.Telepathy.SpecAutoGenTest.Introspective:b)), (u'org.freedesktop.Telepathy.SpecAutoGenTest.StuffHappened', Signal(org.freedesktop.Telepathy.SpecAutoGenTest.StuffHappened)), (u'org.freedesktop.Telepathy.SpecAutoGenTest.wobbly', AwkwardTelepathyProperty(org.freedesktop.Telepathy.SpecAutoGenTest.wobbly:b)), (u'org.freedesktop.Telepathy.SpecAutoGenTest/badgers', ClientInterest(org.freedesktop.Telepathy.SpecAutoGenTest/badgers))]
[('org.freedesktop.Telepathy.SpecAutoGenTest', ClientInterest(org.freedesktop.Telepathy.SpecAutoGenTest)), ('org.freedesktop.Telepathy.SpecAutoGenTest.DoStuff', Method(org.freedesktop.Telepathy.SpecAutoGenTest.DoStuff)), ('org.freedesktop.Telepathy.SpecAutoGenTest.Introspective', Property(org.freedesktop.Telepathy.SpecAutoGenTest.Introspective:b)), ('org.freedesktop.Telepathy.SpecAutoGenTest.StuffHappened', Signal(org.freedesktop.Telepathy.SpecAutoGenTest.StuffHappened)), ('org.freedesktop.Telepathy.SpecAutoGenTest.wobbly', AwkwardTelepathyProperty(org.freedesktop.Telepathy.SpecAutoGenTest.wobbly:b)), ('org.freedesktop.Telepathy.SpecAutoGenTest/badgers', ClientInterest(org.freedesktop.Telepathy.SpecAutoGenTest/badgers))]
>>> map (lambda o: i.added, spec.everything.values ())
>>> list(map (lambda o: i.added, spec.everything.values ()))
[None, None, None, None, None, None]
>>> map (lambda o: i.deprecated, spec.everything.values ())
>>> list(map (lambda o: i.deprecated, spec.everything.values ()))
[None, None, None, None, None, None]
"""
......
#!/usr/bin/env python
#!/usr/bin/env python3
#
# doc-generator.py
#
# Generates HTML documentation from the parsed spec using Cheetah templates.
# Generates HTML documentation from the parsed spec
#
# Copyright (C) 2009 Collabora Ltd.
#
......@@ -27,12 +27,13 @@ import sys
import os
import os.path
import shutil
import itertools
try:
from Cheetah.Template import Template
except ImportError, e:
print >> sys.stderr, e
print >> sys.stderr, "Install `python-cheetah'?"
from jinja2 import Template
except ImportError as e:
print(e, file=sys.stderr)
print("Install `jinja2'?", file=sys.stderr)
sys.exit(-1)
import specparser
......@@ -68,54 +69,58 @@ def load_template(filename):
file = open(os.path.join(template_path, filename))
template_def = file.read()
file.close()
except IOError, e:
print >> sys.stderr, "Could not load template file `%s'" % filename
print >> sys.stderr, e
except IOError as e:
print("Could not load template file `%s'" % filename, file=sys.stderr)
print(e, file=sys.stderr)
sys.exit(-1)
return template_def
def render_template(name, context, target=None):
if target is None:
target = name
template_def = load_template(name)
t = Template(template_def).render(context)
with open(os.path.join(output_path, target), 'w') as out:
out.write(t)
spec = specparser.parse(spec_file, namespace, allow_externals=allow_externals)
# write out HTML files for each of the interfaces
# Not using render_template here to avoid recompiling it n times.
namespace = { 'spec': spec }
template_def = load_template('interface.html')
t = Template(template_def, namespaces = [namespace])
for interface in spec.interfaces:
namespace['interface'] = interface
all_values = list(spec.everything.values()) + list(spec.errors.values()) + list(spec.types.values())
# open the output file
out = open(os.path.join(output_path, '%s.html'
% interface.name_for_bindings), 'w')
print >> out, unicode(t).encode('utf-8')
out.close()
star = [ (item.short_name, item) for item in all_values ]
star.sort(key = lambda t: t[0].title())
groups = [ (l, list(g)) for l, g in (itertools.groupby(star, key = lambda t: t[0][0].upper())) ]
letters = set(map(lambda t: t[0], groups))
all_letters = list(map(chr, range(ord('A'), ord('Z')+1)))
def render_template(name, namespaces, target=None):
if target is None:
target = name
context = { 'spec': spec, 'star': star, 'groups': groups,
'letters': letters, 'all_letters': all_letters }
render_template('fullindex.html', context)
namespace = { 'spec': spec }
template_def = load_template(name)
t = Template(template_def, namespaces=namespaces)
out = open(os.path.join(output_path, target), 'w')
print >> out, unicode(t).encode('utf-8')
out.close()