Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ep_formater_html.py
diff options
context:
space:
mode:
authorThomas Jourdan <b.vehikel@googlemail.com>2010-02-12 17:00:58 (GMT)
committer Thomas Jourdan <b.vehikel@googlemail.com>2010-02-12 17:00:58 (GMT)
commit389d08d48141e299774eb0be952999468747486b (patch)
tree3b4337b89f6bce40708eb2d1f578ffc8bb598dab /ep_formater_html.py
parentc81c18ddf83a97147e1025129a65fe538c34acb7 (diff)
An 'explain details' page is added to Kandid.
Try to fix po/de.po not uptodate.
Diffstat (limited to 'ep_formater_html.py')
-rw-r--r--ep_formater_html.py57
1 files changed, 35 insertions, 22 deletions
diff --git a/ep_formater_html.py b/ep_formater_html.py
index 306abb6..232f1a1 100644
--- a/ep_formater_html.py
+++ b/ep_formater_html.py
@@ -41,16 +41,18 @@ class HtmlFormater(object):
self._base_folder = base_folder.replace(' ', '_')
self._indent = 0
self._page = u''
+ self.produced_files_list = []
self.id_count = 0
self._header_occured = False # debugging only
self._footer_occured = False # debugging only
file_path = os.path.join(base_folder, unique_id)
- try:
- os.mkdir(file_path)
- except:
- ka_debug.err('creating directory [%s] [%s] [%s]' % \
- (file_path, sys.exc_info()[0], sys.exc_info()[1]))
- traceback.print_exc(file=sys.__stderr__)
+ if not os.path.exists(file_path):
+ try:
+ os.mkdir(file_path)
+ except:
+ ka_debug.err('creating directory [%s] [%s] [%s]' % \
+ (file_path, sys.exc_info()[0], sys.exc_info()[1]))
+ traceback.print_exc(file=sys.__stderr__)
def _escape(self, text):
@@ -91,12 +93,16 @@ class HtmlFormater(object):
self.id_count += 1
return u'id_' + unicode(self.id_count)
- def get_pathname(self, extension, postfix=None):
- """Returns path appended by filename of the generated HTML page."""
- return os.path.join(self._base_folder,
- self.unique_id,
+ def get_absolutename(self, extension, postfix=None):
+ """Returns absolute path appended by filename of the generated HTML page."""
+ return os.path.join(self.get_pathname(),
self.get_filename(extension, postfix))
+ def get_pathname(self):
+ """Returns absolute path."""
+ return os.path.join(self._base_folder,
+ self.unique_id)
+
def get_filename(self, extension, postfix=None):
"""Returns the filename only of the generated HTML page."""
postfix = '' if postfix is None else '_' + postfix
@@ -109,7 +115,7 @@ class HtmlFormater(object):
"""
self._append( (
u'<?xml version="1.0" encoding="UTF-8"?>',
- u'<?xml-stylesheet href="treestyles.css" type="text/css"?>',
+ u'<?xml-stylesheet href="../treestyles.css" type="text/css"?>',
u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"',
u' "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
u'',
@@ -118,8 +124,8 @@ class HtmlFormater(object):
u' <meta name="generator" content="' + HtmlFormater.generator +'" />',
u'',
u' <title>' + title + u'</title>',
- u' <link rel="stylesheet" href="marktree/treestyles.css" type="text/css" />',
- u' <script type="text/javascript" src="marktree/marktree.js">',
+ u' <link rel="stylesheet" href="../treestyles.css" type="text/css" />',
+ u' <script type="text/javascript" src="../marktree.js">',
u'//<![CDATA[',
u'',
u' //]]>',
@@ -158,8 +164,8 @@ class HtmlFormater(object):
pre: not self._footer_occured
"""
self._append( (
- u' <li class="basic" style="" id="id_' + identification + u'" >',
- u' <span style="">',
+ u' <li class="basic" id="id_' + identification + u'" >',
+ u' <span>',
) )
def _end_list_item(self):
@@ -199,7 +205,7 @@ class HtmlFormater(object):
"""
self._indent += 1
self._append( (
- u' <li class="col" style="" id="' + self._get_id() + u'">',
+ u' <li class="col" id="' + self._get_id() + u'">',
self._escape(text),
u' <ul class="subexp">',
) )
@@ -245,11 +251,12 @@ class HtmlFormater(object):
pre: text is not None
"""
identification = self._get_id()
- pathname = self.get_pathname('png', postfix=identification)
+ pathname = self.get_absolutename('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
surface = exon_color.Color.make_icon(color.rgba, alpha,
ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
+ self.produced_files_list.append(pathname)
description = color.explain(alpha)
self._begin_list_item(identification)
@@ -265,11 +272,12 @@ class HtmlFormater(object):
pre: text is not None
"""
identification = self._get_id()
- pathname = self.get_pathname('png', postfix=identification)
+ pathname = self.get_absolutename('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
surface = exon_color.Color.make_icon((1.0, 1.0, 1.0, alpha), True,
ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
+ self.produced_files_list.append(pathname)
description = '%d%% opaque' % (100*alpha)
self._begin_list_item(self._get_id())
@@ -289,11 +297,12 @@ class HtmlFormater(object):
self._append( (u' <br />',) )
for color in color_list:
identification = self._get_id()
- pathname = self.get_pathname('png', postfix=identification)
+ pathname = self.get_absolutename('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
surface = color.make_icon(color.rgba, alpha,
ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
+ self.produced_files_list.append(pathname)
description = color.explain(alpha)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, \
description, newline=False)
@@ -323,11 +332,12 @@ class HtmlFormater(object):
self._begin_list_item(self._get_id())
self._append_escaped(text + u' ' + description)
identification = self._get_id()
- pathname = self.get_pathname('png', postfix=identification)
+ pathname = self.get_absolutename('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
surface = exon_position.Position.make_icon(position_list,
ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
+ self.produced_files_list.append(pathname)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, description)
self._end_list_item()
@@ -355,11 +365,12 @@ class HtmlFormater(object):
self._begin_list_item(self._get_id())
self._append_escaped(text + u' ' + description)
identification = self._get_id()
- pathname = self.get_pathname('png', postfix=identification)
+ pathname = self.get_absolutename('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
surface = exon_direction.Direction.make_icon(direction_list,
ICON_WIDTH, ICON_HEIGHT)
surface.write_to_png(pathname)
+ self.produced_files_list.append(pathname)
self._image_item(filename, ICON_WIDTH, ICON_HEIGHT, description)
self._end_list_item()
@@ -372,9 +383,10 @@ class HtmlFormater(object):
pre: description is not None
"""
identification = self._get_id()
- pathname = self.get_pathname('png', postfix=identification)
+ pathname = self.get_absolutename('png', postfix=identification)
filename = self.get_filename('png', postfix=identification)
surface.write_to_png(pathname)
+ self.produced_files_list.append(pathname)
width = surface.get_width()
height = surface.get_height()
@@ -394,6 +406,7 @@ class HtmlFormater(object):
try:
out_file = open(file_path, 'w')
out_file.write(self._page.encode('utf-8'))
+ self.produced_files_list.append(file_path)
except:
ka_debug.err('failed writing [%s] [%s] [%s]' % \
(file_path, sys.exc_info()[0], sys.exc_info()[1]))