buildframework/helium/sf/python/pythoncore/lib/log2xml.py
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0-a7879c935424
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        : log2xml.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
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
""" Symbian log converter.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import xml.dom.minidom
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import sys
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import codecs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import time
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import datetime
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
from xml.sax import make_parser 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
from xml.sax.handler import ContentHandler 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
from xml.sax.saxutils import escape
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
DEFAULT_CONFIGURATION = {"FATAL": [r"mingw_make.exe"],
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
                         "ERROR": [r'^(?:(?:\s*\d+\)\s*)|(?:\s*\*\*\*\s*))ERROR:',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
                                   r"^MISSING:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
                                   r"Error:\s+",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
                                   r"^Error:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
                                   r"'.+' is not recognized as an internal or external command",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
                                   r"FLEXlm error:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
                                   r"(ABLD|BLDMAKE) ERROR:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
                                   r"FATAL ERROR\(S\):",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
                                   r"fatal error U1077",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
                                   r"warning U4010",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
                                   r"^make(?:\[\d+\])?\: \*\*\*",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
                                   r"^make(?:\[\d+\])?:\s+.*\s+not\s+remade",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
                                   r"\"(.*)\", line (\d+): (Error: +(.\d+.*?):.*)$",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
                                   r"error: ((Internal fault):.*)$",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
                                   r"Exception: [A-Z0-9_]+",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
                                   r"target .* given more than once in the same rule",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
                                   r"^ERROR:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
                                   r"^ERROR EC\d+:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
                                   r"^ERROR\t",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
                                   r"syntax error at line",],
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
                         "CRITICAL": [r"[Ww]arning:?\s+(#111-D|#1166-D|#117-D|#128-D|#1293-D|#1441-D|#170-D|#174-D|#175-D|#185-D|#186-D|#223-D|#231-D|#257-D|#284-D|#368-D|#414-D|#430-D|#47-D|#514-D|#546-D|#68-D|#69-D|#830-D|#940-D|#836-D|A1495E|L6318W|C2874W|C4127|C4355|C4530|C4702|C4786|LNK4049)"],
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
                         "WARNING": [r'\): Missing file:',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
                                      r'^(\d+\))?\s*WARNING:', r'^MAKEDEF WARNING:',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
                                      r'line \d+: Warning:', r':\s+warning\s+\w+:',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
                                      r"\\\\(.*?)\(\d+\)\s:\sWarning:\s\(\d+\)",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
                                      r"^(BLDMAKE |MAKEDEF )?WARNING:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
                                      r"WARNING\(S\)",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
                                      r"\(\d+\) : warning C",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
                                      r"LINK : warning",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
                                      r":\d+: warning:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
                                      r"\"(.*)\", line (\d+): (Warning: +(?!A1495E)(.\d+.*?):.*)$",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
                                      r"Usage Warning:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
                                      r"mwld.exe:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
                                      r"^Command line warning",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
                                      r"ERROR: bad relocation:",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
                                      r"^(\d+) warning",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
                                      r"EventType:\s+Error\s+Source:\s+SweepNT",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
                                      r"^WARN\t",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
                                      ],
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
                        "REMARK": [r"Command line warning D4025 : ",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
                                   r"^REMARK: ",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
                                   r"^EventType:\s+Error\s+Source:\s+GNU\s+Make",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
                                   r":\d+: warning: cannot find matching deallocation function",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
                                   r"((:\d+)*: note: )",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
                                   ],
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
                        "INFO": [r"^INFO:"]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
                        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
def find_priority(line, config):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
    keys = config.keys()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
    keys.reverse()    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
    for category in keys:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        for rule in config[category]:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
            if rule.search(line) != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
                return category.lower()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
    return "stdout"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
class Stack:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
    """ Bottomless stack. If empty just pop a default element. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
    def __init__(self, default):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        self.__default = default
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        self.__stack = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
    def pop(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        result = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
            result = self.__stack.pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        except IndexError, e:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
            result = self.__default
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        return result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
    def push(self, item):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        self.__stack.append(item)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
    def __len__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
        return len(self.__stack)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
def to_cdata(text):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
    """ Cleanup string to match CDATA requiements.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
        These are the only allowed characters: #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF].
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
    result = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
    for c in list(text):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        v = ord(c)        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        if v == 0x9 or v == 0xa or v == 0xd:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
            result += c
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
        elif v>=0x20 and v <= 0xd7ff:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
            result += c
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        elif v>=0xe000 and v <= 0xfffd:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
            result += c
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
        elif v>=0x10000 and v <= 0x10ffff:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
            result += c
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
            result += " " 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
    return result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
class LogWriter(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
    """ XML Log writer. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
    def __init__(self, stream, filename):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        self.__stream = stream
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        self.__stream.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
        self.__stream.write("<log filename=\"%s\">\n" % filename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
        self.__stream.write("\t<build>\n")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
        self.__indent = "\t"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
        self.__intask = 0
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
    def close(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        # closing open tasks...
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
        while self.__intask > 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
            self.close_task()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
        self.__stream.write("\t</build>\n")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
        self.__stream.write("</log>\n")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
        self.__stream.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
    def open_task(self, name):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
        self.__indent += "\t"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
        self.__intask += 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
        self.__stream.write("%s<task name=\"%s\">\n" % (self.__indent, name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
    def close_task(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
        if self.__intask > 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            self.__intask -= 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
            self.__stream.write("%s</task>\n" % (self.__indent))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
            self.__indent = self.__indent[:-1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
    def message(self, priority, msg):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
            acdata = to_cdata(msg.decode('utf-8', 'ignore'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
            self.__stream.write("%s<message priority=\"%s\"><![CDATA[%s]]></message>\n" % (self.__indent+"\t", priority, acdata))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
        except UnicodeDecodeError, e:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
            print e
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
def convert(inputfile, outputfile, fulllogging=True, configuration=DEFAULT_CONFIGURATION):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
    """ Convert an input log into an XML log and write an outputfile. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
    # Compiling the regexp  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
    built_config = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
    for category in configuration.keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
        built_config[category] = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
        for rule in configuration[category]:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
            built_config[category].append(re.compile(rule))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
    # Generating the XML log
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
    log = open(inputfile, 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
    olog = codecs.open(outputfile, 'w+', 'utf-8', errors='ignore')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
    xmllog = LogWriter(olog, inputfile)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
    match_finnished = re.compile(r"^===\s+.+\s+finished") 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
    match_started = re.compile(r"^===\s+(.+)\s+started") 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    match_component = re.compile(r"^===\s+(.+?)\s+==\s+(.+)")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
    match_logger_component = re.compile(r'^\s*\[.+?\]\s*')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
    #match_ant_target_start = re.compile(r'.*INFO\s+-\s+Target\s+####\s+(.+)\s+####\s+has\s+started')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
    #match_ant_target_end = re.compile(r'.*INFO\s+-\s+Target\s+####\s+(.+)\s+####\s+has\s+finnished')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
    match_ant_target_start = re.compile(r'^([^\s=\[\]]+):$')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
    match_ant_target_end = re.compile(r'^([^\s=]+):\s+duration')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
    symbian = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
    ant_has_open_task = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
    # looping
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
    for line in log:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
        # matching Ant logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
        if not symbian and match_ant_target_end.match(line):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
            xmllog.close_task()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
            ant_has_open_task = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
            continue
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
        elif not symbian and match_ant_target_start.match(line):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
            result = match_ant_target_start.match(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
            if result != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
                if ant_has_open_task:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
                    xmllog.close_task()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
                    ant_has_open_task = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
                xmllog.open_task(result.group(1))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
                ant_has_open_task = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
            continue
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
        # matching Symbian logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
        line = match_logger_component.sub(r'', line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
        line = line.strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
        if line.startswith("++ Finished at"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
            xmllog.close_task()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
        elif line.startswith("=== "):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
            if match_finnished.match(line):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
                xmllog.close_task()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
                # This is a symbian log
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
                symbian = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
                result = match_component.match(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
                if result != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
                    xmllog.open_task(result.group(2))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
                # === cenrep_s60_32 started
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
                result = match_started.match(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
                if result != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
                    xmllog.open_task(result.group(1))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
            # Type?
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
            priority = find_priority(line, built_config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
            if (fulllogging or priority != 'stdout'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
                xmllog.message(priority, line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
    # end file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
    xmllog.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
def convert_old(inputfile, outputfile, fulllogging=True, configuration=DEFAULT_CONFIGURATION):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
    """ Convert an input log into an XML log and write an outputfile. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
    # Compiling the regexp  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
    built_config = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
    for category in configuration.keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
        built_config[category] = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
        for rule in configuration[category]:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
            built_config[category].append(re.compile(rule))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
    # Generating the XML log
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
    log = open (inputfile, 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
    doc = xml.dom.minidom.Document()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
    root = doc.createElementNS("", "log")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
    root.setAttributeNS("", "name", inputfile)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   256
    doc.appendChild(root)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
    build = doc.createElementNS("", "build")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
    root.appendChild(build)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
    # current group/task
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
    current = build
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
    # bottomless stask, if losing sync all message will be at top level.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
    stack = Stack(build)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
    match_finnished = re.compile(r"^===\s+.+\s+finished") 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
    match_started = re.compile(r"===\s+(.+)\s+started") 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   266
    match_component = re.compile(r"^===\s+(.+?)\s+==\s+(.+)")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   267
    match_logger_component = re.compile(r'^\s*\[.+?\]\s*')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
    #match_ant_target_start = re.compile(r'.*INFO\s+-\s+Target\s+####\s+(.+)\s+####\s+has\s+started')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
    #match_ant_target_end = re.compile(r'.*INFO\s+-\s+Target\s+####\s+(.+)\s+####\s+has\s+finnished')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
    match_ant_target_start = re.compile(r'^([^\s=]+):$')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
    match_ant_target_end = re.compile(r'^([^\s=]+):\s+duration')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   272
    # looping
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
    for line in log:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   274
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
        # matching Ant logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   276
        if match_ant_target_end.match(line):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
            current = stack.pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
            continue
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   279
        elif match_ant_target_start.match(line):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   280
            result = match_ant_target_start.match(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   281
            if result != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   282
                stack.push(current)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   283
                task = doc.createElementNS("", "task")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   284
                task.setAttributeNS("", "name", result.group(1))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   285
                current.appendChild(task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   286
                current = task
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   287
            continue
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
        # matching Symbian logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
        line = match_logger_component.sub(r'', line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   290
        line = line.strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   291
        if line.startswith("++ Finished at"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   292
            current = stack.pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   293
        elif line.startswith("==="):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   294
            if match_finnished.match(line):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   295
                current = stack.pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   296
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   297
                result = match_component.match(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   298
                if result != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   299
                    stack.push(current)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   300
                    task = doc.createElementNS("", "task")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   301
                    task.setAttributeNS("", "name", result.group(2))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   302
                    current.appendChild(task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   303
                    current = task
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   304
                # === cenrep_s60_32 started
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   305
                result = match_started.match(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   306
                if result != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   307
                    task = doc.createElementNS("", "task")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   308
                    task.setAttributeNS("", "name", result.group(1))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   309
                    stack.push(current)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   310
                    current.appendChild(task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   311
                    current = task
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   312
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   313
            msg = doc.createElementNS("", "message")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   314
            # Type?
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   315
            priority = find_priority(line, built_config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   316
            if (fulllogging or priority != 'stdout'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   317
                msg.setAttributeNS("", "priority", priority)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   318
                msg.appendChild(doc.createCDATASection(to_cdata(line.decode("utf-8"))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   319
                current.appendChild(msg)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   320
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   321
    file_object = codecs.open(outputfile, 'w', "utf_8")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   322
    file_object.write(doc.toprettyxml())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   323
    file_object.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   324
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   325
class ContentWriter(ContentHandler):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   326
    """ SAX Content writer. Parse and write an XML file. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   327
    def __init__(self, os, indent=""):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   328
        self.os = os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   329
        self.indent = indent
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   330
        self.__content = u""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   331
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   332
    def startElement(self, name, attrs):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   333
        self.os.write(self.indent + "<" + name)        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   334
        if attrs.getLength() > 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   335
            self.os.write(" ")        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   336
        self.os.write(" ".join(map(lambda x: "%s=\"%s\"" % (x, attrs.getValue(x)), attrs.getNames())))            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   337
        self.os.write(">\n")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   338
        self.indent += "\t"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   339
        self.__content = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   340
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   341
    def endElement(self, name):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   342
        if len(self.__content) > 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   343
            self.os.write(self.indent + self.__content + "\n")                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   344
        self.indent = self.indent[:-1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   345
        self.os.write("%s</%s>\n" % (self.indent, name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   346
        self.__content = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   347
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   348
    def characters(self, content):        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   349
        self.__content += unicode(escape(content.strip()))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   350
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   351
class AppendSummary(ContentWriter):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   352
    """ SAX content handler to add an XML log to the summary. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   353
    def __init__(self, output, xmllog):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   354
        ContentWriter.__init__(self, output)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   355
        self.xmllog = xmllog
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   356
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   357
    def startDocument(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   358
        self.os.write('<?xml version="1.0" encoding="utf-8"?>\n')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   359
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   360
    def startElement(self, name, attrs):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   361
        ContentWriter.startElement(self, name, attrs)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   362
        if name == "logSummary":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   363
            parser = make_parser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   364
            parser.setContentHandler(ContentWriter(self.os, self.indent))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   365
            parser.parse(open(self.xmllog, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   366
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   367
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   368
def append_summary(summary, xmllog, maxmb=80):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   369
    """ Append content to the summary xml file. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   370
    if os.path.getsize(summary) + os.path.getsize(xmllog) > (maxmb*1024*1024):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   371
        print 'Error: ' + summary + ' larger than ' + str(maxmb) + 'MB, not appending'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   372
        return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   373
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   374
    outfile = codecs.open(summary + ".tmp", 'w', "utf8")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   375
    parser = make_parser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   376
    parser.setContentHandler(AppendSummary(outfile, xmllog))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   377
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   378
    input = open(summary, 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   379
    parser.parse(input)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   380
    input.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   381
    outfile.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   382
    # Updating the summary file.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   383
    os.unlink(summary)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   384
    os.rename(summary + ".tmp", summary)    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   385
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   386
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   387
def symbian_log_header(output, config, command, dir):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   388
    output.log("===-------------------------------------------------")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   389
    output.log("=== %s" % config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   390
    output.log("===-------------------------------------------------")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   391
    output.log("=== %s started %s" % (config, datetime.datetime.now().ctime()))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   392
    output.log("=== %s == %s" % (config, dir))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   393
    output.log("-- %s" % command)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   394
    output.log("++ Started at %s" % datetime.datetime.now().ctime())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   395
    output.log("+++ HiRes Start %f" % time.time())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   396
    output.log("Chdir %s" % dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   397
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   398
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   399
def symbian_log_footer(output):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   400
    output.log("+++ HiRes End %f" % time.time())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   401
    output.log("++ Finished at %s" % datetime.datetime.now().ctime())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   402
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   403
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   404
if __name__ == "__main__":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   405
    convert(sys.argv[1], "%s.xml" % sys.argv[1], fulllogging=False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   406
    """ An empty summary:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   407
        <?xml version=\"1.0\" encoding=\"UTF-8\"?><logSummary/>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   408
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   409
    #s = open(r"z:\summary.xml", "w")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   410
    #s.write("""<?xml version=\"1.0\" encoding=\"UTF-8\"?><logSummary/>""")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   411
    #s.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   412
    #append_summary(r'Z:\summary.xml', r'Z:\output\logs\test_0.0.1.mc_5132_2_build.log2.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   413
    #append_summary(r'Z:\summary.xml', r'Z:\output\logs\test_0.0.1_BOM.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   414
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   415