buildframework/helium/sf/python/pythoncore/lib/helium/logger.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        : logger.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 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
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    26
# pylint: disable=E1101,E1103
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import codecs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import xml.dom.minidom
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import datetime
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import traceback
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
class _CustomizePrint(object):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    34
    """ This is an Internal helper call. """
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
    def __init__(self, logger, name):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    37
        """Initialise the instance content 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    38
        @param logger a Logger instance
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    39
        @param name method name (e.g. Print, Error), could be any strings"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        self.__logger = logger
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        self.__name = name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
    def __call__(self, *args):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    44
        """Make this object callable. Call _print from the logger instance.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    45
        @params *args a list of arguments"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    46
        # pylint: disable=W0212
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    47
        self.__logger._print(self.__name, args)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    48
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    49
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
class Logger(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
    """ Logger class used to create xml logging in python """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    def __init__(self):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    53
        """Constructor of the Logger."""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        self.__step = 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        self.__doc = xml.dom.minidom.Document()
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    56
        self.__lognode = self.__doc.createElementNS("", "__log")
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        self.__header = self.__doc.createElementNS("", "__header")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        self.__footer = self.__doc.createElementNS("", "__footer")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        self.__summary = self.__doc.createElementNS("", "__summary")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        self.__lognode.appendChild(self.__header)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        self.__lognode.appendChild(self.__summary)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    62
        self.__lognode.appendChild(self.__footer)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        self.__lognode.setAttributeNS("", "date", "%s" % datetime.datetime.now().ctime())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        self.__footer.setAttributeNS("", "title", "")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        self.__footer.setAttributeNS("", "subtitle", "")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        self.__doc.appendChild(self.__lognode)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        self.__build = self.__doc.createElementNS("", "build")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        self.__lognode.appendChild(self.__build)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        self.__current_node = self.__build
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        self.__stack = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        self.__verbose = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        #<__log date="Wed Dec  6 03:07:25 2006">
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
    def SetInterface(self, url):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    75
        """Set the url of interface to use."""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        self.__lognode.setAttributeNS("", "interface", url)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
    def SetVerbose(self, v):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    79
        """Enable/Disable shell output
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    80
        @param v boolean to set the logger output"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        self.__verbose = v
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
    
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    83
    def SetTitle(self, title):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    84
        """Set the title of the document
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    85
        @param title the title to set"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        self.__header.setAttributeNS("", "title", title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    88
    def SetSubTitle(self, title):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    89
        """Set the subtitle of the document
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    90
        @param subtitle the subtitle to set"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        self.__header.setAttributeNS("", "subtitle", title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
    def SetSummaryTitle(self, title):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    94
        """Set the sumamry title
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    95
        @param title the title to set"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        self.__summary.setAttributeNS("", "title", title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
    def AddSummaryElement(self, tag, value):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    99
        """Creates a summary couple.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   100
        @param tag the description
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   101
        @param value the value"""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   102
        elem = self.__doc.createElementNS("", "__elmt")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   103
        elem.setAttributeNS("", "tag", tag)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   104
        elem.setAttributeNS("", "val", value)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   105
        self.__summary.appendChild(elem)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
    def OpenMainContent(self, title=""):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   109
        """Open a MainContent section.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   110
        @param title title of the MainContent section"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
        self.__stack.append(self.__current_node)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   112
        node = self.__doc.createElementNS("", "task")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   113
        node.setAttributeNS("", "name", title)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   114
        node.setAttributeNS("", "type", "maincontent")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   115
        node.setAttributeNS("", "time", datetime.datetime.now().ctime())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   116
        self.__current_node.appendChild(node)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   117
        self.__current_node = node
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        if self.__verbose:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
            print ("---------------------------------------------------------------------")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
            print ("  %s" % title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
            print ("---------------------------------------------------------------------")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
    def CloseMainContent(self):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   125
        """ Close the current main content section.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   126
        Make sure you have closed other Event/Section first"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
        if self.__current_node.nodeName != "task" and not (self.__current_node.attributes.has_key('type') and self.__current_node.attributes['type']=="maincontent"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
            raise Exception("not closing a 'maincontent' typed node")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
        self.__current_node = self.__stack.pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
    def OpenEvent(self, title=""):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   133
        """Create an Event section (can be opened/closed)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   134
        @param title title of the MainContent section"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        self.__stack.append(self.__current_node)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   136
        node = self.__doc.createElementNS("", "task")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   137
        node.setAttributeNS("", "name", title)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   138
        node.setAttributeNS("", "type", "event")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   139
        node.setAttributeNS("", "time", datetime.datetime.now().ctime())
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   140
        self.__current_node.appendChild(node)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   141
        self.__current_node = node
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
        if self.__verbose:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
            print ("---------------------------------------------------------------------")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
            print (" + %s" % title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   146
    def SetCustomOutputer(self, type_, classname, config = None):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   147
        """set custom out puter"""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   148
        node = self.__doc.createElementNS("", "__customoutputer")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   149
        node.setAttributeNS("", "type", type_)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   150
        node.setAttributeNS("", "module", classname)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        if config != None:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   152
            node.appendChild(config)
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   153
        self.__lognode.appendChild(node)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
    def CloseEvent(self):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   156
        """# Close the current Event
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   157
        Make sure you have closed other Event/Section first"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
        if self.__current_node.nodeName != "task" and (self.__current_node.attributes.has_key('type') and self.__current_node.attributes['type']=="event"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            raise Exception("not closing a 'event' typed node")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
        self.__current_node = self.__stack.pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
    def __getattribute__(self, attr):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   163
        """__getattribute__ has been overrided to enable dynamic messaging.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   164
        @param attr the name of the method (or attribute...)"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
            return object.__getattribute__(self, attr)  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
        except AttributeError:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
            return _CustomizePrint(self, attr)        
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   169
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
    def _print(self, kind, *args):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   171
        """Generic method that handle the print in the XML document
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   172
            @param kind type of output
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   173
            @param *args a list of arguments (must be strings)"""
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   174
        output = u"".join([u"%s" % x for x in list(*args)])
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
        nodetype = kind.lower()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
        msgtype = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
        if nodetype != "print" and nodetype != "info" and nodetype != "debug":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
            msgtype = "%s:" % nodetype.upper()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
        if self.__verbose:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
            print "%s %s" % (msgtype, output.encode('utf-8'))
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   181
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   182
        node = self.__doc.createElementNS("", "message")
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   183
        node.setAttributeNS("", "priority", nodetype)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
        #n.setAttributeNS("", "time", datetime.datetime.now().ctime())
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   185
        node.appendChild(self.__doc.createCDATASection(output))
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   186
        self.__current_node.appendChild(node)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
#        nodetype = kind.lower()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
#        if kind.lower() != "print" and kind.lower() != "printraw":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
#            nodename = kind.lower()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
#        if nodename=="__print" and self.__current_node.lastChild!=None and self.__current_node.lastChild.nodeName  == nodename:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
#            self.__current_node.lastChild.appendChild(self.__doc.createTextNode("".join(*args).decode('iso-8859-1')))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
#        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
#            n = self.__doc.createElementNS("", nodename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
#            n.setAttributeNS("", "step", "%d" % self.__step)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
#            self.__step += 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
#            n.setAttributeNS("", "time", datetime.datetime.now().ctime())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
#            text_content = "".join(map(lambda x: str(x), list(*args))).decode('iso-8859-1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
#            n.appendChild(self.__doc.createTextNode(text_content))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
#            self.__current_node.appendChild(n)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
    def SetFooterTitle(self, title):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   204
        """set footer title"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
        self.__footer.attributes['title'] = title
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
    def SetFooterSubTitle(self, subtitle):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   208
        """set footer sub title"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
        self.__footer.attributes['subtitle'] = subtitle
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
    def Die(self, title, subtitle, exception):
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   212
        """Die - kill it off?"""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
        self.SetFooterTitle(title)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
        self.SetFooterSubTitle("%s\nException raised: %s\n%s" % (subtitle, exception, traceback.format_exc()))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   216
    def WriteToFile(self, filename):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   217
        """Write the DOM tree into a file.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   218
         @param filename the file to write in."""
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        file_object = open(filename, "w")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
        file_object.write(codecs.BOM_UTF8)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        file_object.write(self.__doc.toprettyxml(encoding = "utf-8"))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
        file_object.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
    ##
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
    # Write the DOM tree into a file.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
    # @param filename the file to write in.
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   228
    def __str__(self):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
        return self.__doc.toprettyxml(encoding="utf-8")