buildframework/helium/sf/python/pythoncore/lib/helium/outputer.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : outputer.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    20
"""Port to python of the ISIS::Logger3::XML2HTML perl module
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    21
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    22
1.0.0 (13/12/2006)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    23
 - First version of the module."""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    24
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import codecs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import xml.dom.minidom
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
from helium.output.widgets import *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import urllib2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import amara
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import dataurl
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
class Configuration:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
    """ Class  for isis Configuration """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
    def __init__(self, url):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    36
        url_file = urllib2.urlopen(url)#
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    37
        data = url_file.read()
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    38
        url_file.close()
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        self.__xml = amara.parse(data)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    41
    def getClass(self, type_, default = None):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    42
        """get Class"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    43
        return self._getValue(type_, "class", default)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    45
    def getImg(self, type_, default = None):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    46
        """ get Image"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    47
        return self._getValue(type_, "img", default)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    49
    def getWidth(self, type_, default = None):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    50
        """get Width"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    51
        return self._getValue(type_, "width", default)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    53
    def getHeight(self, type_, default = None):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    54
        """get height"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    55
        return self._getValue(type_, "height", default)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    57
    def _getValue(self, type_, attr, default = None):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    58
        """get value"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    59
        r_attr = self.__xml.xml_xpath("/htmloutput/icons/icon[@type='%s']" % type_)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    60
        if len(r_attr) == 0:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
            if default == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
                raise Exception("Not found")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
                return default
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    65
        return r_attr[0][attr]
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
class XML2XHTML:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    """ This class is used to generate an html file from the given xml """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    def __init__(self, filename, url="http://fawww.europe.nokia.com/isis/isis_interface/configuration.xml", usedataurl=False):
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    70
        self.__title = None
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        self.__config = Configuration(url)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        self.__filename = filename
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        self.__srcdoc = xml.dom.minidom.parse(filename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        self.__srcdoc.normalize()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        self.__usedataurl = usedataurl
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        # xhtml output
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        dom = xml.dom.minidom.getDOMImplementation()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        doctype = dom.createDocumentType("html", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
              "-//W3C//DTD XHTML 1.0 Strict//EN", 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        self.__doc = dom.createDocument(None, "html", doctype)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        self.__xhtml = self.__doc.getElementsByTagName("html")[0]
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    84
        self.__xhtml.setAttributeNS("", "xmlns", "http://www.w3.org/1999/xhtml")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        self.__id = 0
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        self.__xhtml_summary = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        self.__tags = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        self.__css = ["http://fawww.europe.nokia.com/isis/isis_interface/css/logger2.css"]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        self.__javascript = ["http://fawww.europe.nokia.com/isis/isis_interface/javascript/expand2.js"]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        self.__factory = {'__header' : XML2XHTML.forname('helium.output.widgets.Header'),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
                          '__footer' : XML2XHTML.forname('helium.output.widgets.Footer'),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
                          '__maincontent' : XML2XHTML.forname('helium.output.widgets.Box'),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
                          '__summary' : XML2XHTML.forname('helium.output.widgets.Summary'),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
                          '__print' : XML2XHTML.forname('helium.output.widgets.Text'),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
                          '__printraw' : XML2XHTML.forname('helium.output.widgets.RawText'),
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
                          '__event' : XML2XHTML.forname('helium.output.widgets.Event')}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
    def _getId(self):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    99
        """get ID"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        self.__id += 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        return self.__id
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
    def addCSSLink(self, url):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   104
        """add CSS Link"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
        self.__css.append(url)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
    def addJScriptLink(self, url):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   108
        """add Script Link"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        self.__javascript.append(url)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
    def _generateCSSLinks(self, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   112
        """generate CSS Links"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
        for link in self.__css:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   114
            l_link = self.__doc.createElementNS("", "link")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
            if self.__usedataurl:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   116
                l_link.setAttributeNS("", "href", dataurl.from_url(link))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
            else:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   118
                l_link.setAttributeNS("", "href", link)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   119
            l_link.setAttributeNS("", "rel", "stylesheet")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   120
            l_link.setAttributeNS("", "type", "text/css")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   121
            container.appendChild(l_link)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   122
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
    def _generateJScriptLink(self, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   124
        """generate J Script Link"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        for link in self.__javascript:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   126
            l_link = self.__doc.createElementNS("", "script")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
            if self.__usedataurl:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   128
                l_link.setAttributeNS("", "src", dataurl.from_url(link))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
            else:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   130
                l_link.setAttributeNS("", "src", link)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   131
            l_link.setAttributeNS("", "type", "text/javascript")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   132
            l_link.appendChild(self.__doc.createTextNode(""))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   133
            container.appendChild(l_link)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   134
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
    def generate(self):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   136
        """generate"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        root = self.__srcdoc.documentElement
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        if root.tagName != "__log":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
            raise Exception("Invalid document must be __log.")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   141
        for cust_out in root.getElementsByTagName("__customoutputer"):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   142
            self.__factory[cust_out.attributes['type'].value] = XML2XHTML.forname(cust_out.attributes['module'].value)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        head = self.__doc.createElementNS("", "head")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        title = self.__doc.createElementNS("", "title")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
        self.__title = self.__doc.createTextNode("")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
        title.appendChild(self.__title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
        head.appendChild(title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
        self._generateCSSLinks(head)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        self._generateJScriptLink(head)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
        body = self.__doc.createElementNS("", "body") 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
        self.__xhtml.appendChild(head)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
        self.__xhtml.appendChild(body)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   156
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   157
        for child in root.childNodes:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   158
            if child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "__header":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   159
                self._handleHeader(child, body)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   160
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "__summary":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   161
                self._handleSummary(child, body)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   162
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "__maincontent":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   163
                self._handleMainContent(child, body)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   164
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "build":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   165
                self._handleBuild(child, body)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   166
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "task" and child.attributes.has_key('type') and child.attributes['type'] == "maincontent":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   167
                self._handleMainContent(child, body)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   169
        footer = root.getElementsByTagName("__footer")[0]
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   170
        f_foot = self.__factory["__footer"](self.__doc, body)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   171
        if footer.attributes.has_key("title"):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   172
            f_foot.setTitle(footer.attributes['title'].value)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   173
        if footer.attributes.has_key("subtitle"):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   174
            f_foot.setSubTitle(footer.attributes['subtitle'].value)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   175
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
        # Generate summary
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
        self._createSummary()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
    def _handleHeader(self, node, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   180
        """handle Header"""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   181
        header = self.__factory["__header"](self.__doc, container)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
        if node.attributes.has_key('title'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
            self.__title.data = node.attributes['title'].value
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   184
            header.setTitle(node.attributes['title'].value)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
        if node.attributes.has_key("subtitle"):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   186
            header.setSubTitle(node.attributes['subtitle'].value)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
    def _handleSummary(self, node, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   189
        """handle Summary"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
        box = self.__factory["__summary"](self.__doc, container)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
        if node.attributes.has_key('title'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
            box.setTitle(node.attributes["title"].value)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
        
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   194
        for c_tag in node.getElementsByTagName("__elmt"):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   195
            box.addElement(c_tag.attributes['tag'].value, c_tag.attributes['val'].value)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
        self.__xhtml_summary = box
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
    def _handleBuild(self, node, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   199
        """handle Build"""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   200
        for child in node.childNodes:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   201
            if child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "task" and child.attributes.has_key('type') and child.attributes['type'].value == 'maincontent':
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   202
                self._handleMainContent(child, container)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
    def _handleMainContent(self, node, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   206
        """handle Main Content"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
        box = self.__factory["__maincontent"](self.__doc, container)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
        if node.attributes.has_key("title"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
            box.setTitle(node.attributes["title"].value)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
        if node.attributes.has_key("name"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
            box.setTitle(node.attributes["name"].value)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   212
        for child in node.childNodes:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   213
            if child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "__event":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   214
                self._handleEvent(child, box.getDOMContainer())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   215
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "task" and child.attributes.has_key('type') and child.attributes['type'].value == 'event':
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   216
                self._handleEvent(child, box.getDOMContainer())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   217
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "message":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   218
                self._handleMessage(child, box.getDOMContainer())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   219
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   220
                self._handlePrint(child, box.getDOMContainer())
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
    def _handleEvent(self, node, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   223
        """hnadle Event"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
        tags = self.__tags
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
        self.__tags = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
        event = self.__factory["__event"](self.__doc, container, self._getId())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
        if node.attributes.has_key('title'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
            event.setTitle(node.attributes['title'].value)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
        elif node.attributes.has_key('name'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
            event.setTitle(node.attributes['name'].value)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   231
        for child in node.childNodes:            
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   232
            if child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "__event":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   233
                self._handleEvent(child, event.getDOMContainer())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   234
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "task" and child.attributes.has_key('type') and child.attributes['type'].value == 'event':
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   235
                self._handleEvent(child, event.getDOMContainer())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   236
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE and child.tagName == "message":
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   237
                self._handleMessage(child, event.getDOMContainer())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   238
            elif child.nodeType == xml.dom.Node.ELEMENT_NODE:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   239
                self._handlePrint(child, event.getDOMContainer())
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
        keys = self.__tags.keys()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
        keys.sort()
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   243
        for name in keys:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
            event.addStatistics(name.replace("__", ""), self.__tags[name])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
        self.__tags = self._mergeStatistics(tags, self.__tags)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
    def _handleMessage(self, node, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   248
        """ handle Message"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
        if node.attributes['priority'].value == "printraw":
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   250
            t_print = self.__factory["__printraw"](self.__doc, container)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   251
            for n_node in node.childNodes:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   252
                if n_node.nodeType == xml.dom.Node.CDATA_SECTION_NODE:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   253
                    t_print.appendText(n_node.data)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
        else:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   255
            t_print = self.__factory["__print"](self.__doc, container)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   256
            for n_node in node.childNodes:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   257
                if n_node.nodeType == xml.dom.Node.CDATA_SECTION_NODE:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   258
                    t_print.appendText(n_node.data)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
            if node.attributes['priority'].value != "print":
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   260
                t_print.setIcon(self.__config.getClass(node.attributes['priority'].value, "icn_dft"))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
                if self.__tags.has_key(node.attributes['priority'].value):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
                    self.__tags[node.attributes['priority'].value] += 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
                    self.__tags[node.attributes['priority'].value] = 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   266
    def _handlePrint(self, node, container):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   267
        """handle print"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
        if node.tagName == "__printraw":
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   269
            t_print = self.__factory["__printraw"](self.__doc, container)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   270
            for n_node in node.childNodes:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   271
                if n_node.nodeType == xml.dom.Node.CDATA_SECTION_NODE or n_node.nodeType == xml.dom.Node.TEXT_NODE:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   272
                    t_print.appendText(n_node.data)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
        else:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   274
            t_print = self.__factory["__print"](self.__doc, container)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   275
            for n_node in node.childNodes:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   276
                if n_node.nodeType == xml.dom.Node.CDATA_SECTION_NODE or n_node.nodeType == xml.dom.Node.TEXT_NODE:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   277
                    t_print.appendText(n_node.data)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
            if node.tagName != "__print":
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   279
                t_print.setIcon(self.__config.getClass(node.tagName, "icn_dft"))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   280
                if self.__tags.has_key(node.tagName):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   281
                    self.__tags[node.tagName] += 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   282
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   283
                    self.__tags[node.tagName] = 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   284
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   285
    def _createSummary(self):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   286
        """create Summary"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   287
        # pylint: disable=E1101
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
        if self.__xhtml_summary == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
            self.__xhtml_summary = Summary(self.__doc, self.__body)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   290
            self.__xhtml_summary.setTitle("Global Statistics")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   291
        keys = self.__tags.keys()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   292
        keys.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   293
        for name in keys:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   294
            self.__xhtml_summary.addStatistics(name.replace("__", ""), self.__tags[name])
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   295
        # pylint: enable-msg=E1101
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   296
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   297
    def _mergeStatistics(self, tags, newTags):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   298
        """merge Statistics"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   299
        for name in newTags.keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   300
            if tags.has_key(name):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   301
                tags[name] += newTags[name]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   302
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   303
                tags[name] = newTags[name]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   304
        return tags
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   305
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   306
    def WriteToFile(self, filename):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   307
        """write to file"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   308
        file_object = open(filename, "w")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   309
        file_object.write(codecs.BOM_UTF8)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   310
        file_object.write(self.__doc.toprettyxml(encoding="utf-8"))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   311
        file_object.close()
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   312
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   313
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   314
    @staticmethod
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   315
    def forname(classname):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   316
        """forname"""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   317
        result = re.match("^(?P<modname>(?:\w+\.?)*)\.(?P<classname>(\w+?))$", classname)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   318
        if result != None:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   319
            return getattr(__import__(result.groupdict()['modname'], [], [], result.groupdict()['classname']), result.groupdict()['classname'])
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   320
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   321
            raise Exception("Error retreiving module and classname for %s" % classname)