srcanamdw/codescanner/scripts/linescanner.py
author noe\swadi
Thu, 18 Feb 2010 12:29:02 +0530
changeset 1 22878952f6e2
permissions -rw-r--r--
Committing the CodeScanner Core tool This component has been moved from the StaticAnaApps package. BUG : 5889 (http://developer.symbian.org/webbugs/show_bug.cgi?id=5889).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     1
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     3
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     4
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     5
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     6
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     7
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     8
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     9
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    10
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    11
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    12
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    13
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    14
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    15
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    16
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    17
# linescanner.py - the main body of CodeScanner
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
import base64
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
import datetime
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
import encodings
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
import getopt
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
import os
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
import os.path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
import psyco
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
import re
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
import sys
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
import xml.dom.minidom
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
import zlib
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
# Ignore flags
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
KIgnoreNothing = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
KIgnoreComments = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
KIgnoreCommentsAndQuotes = 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
KIgnoreQuotes = 3
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
# Severities for the scripts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
KSeverityHigh = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
KSeverityMedium = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
KSeverityLow = 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
# The names used in the XML configuration file for severity element names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
KSeverityConfigMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
			KSeverityHigh		: "high",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
			KSeverityMedium		: "medium",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
			KSeverityLow		: "low"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    49
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    50
# The names used in the HTML summary file for severity element names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    51
KSeverityHTMLMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    52
			KSeverityHigh		: "High",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    53
			KSeverityMedium		: "Medium",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    54
			KSeverityLow		: "Low"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    55
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    56
# Categories for the scripts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    57
KCategoryLegal = "Legal Code" 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    58
KCategoryDefinitePanic = "Always Panic"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    59
KCategoryCanPanic = "Can Panic"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    60
KCategoryWrongFunctionality = "Wrong Functionality"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    61
KCategoryLocalisation = "Localisation"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    62
KCategoryPerformance = "Performance"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    63
KCategoryCodingStandards = "Coding Standard"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    64
KCategoryDocumentation = "Documentation"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    65
KCategoryCodeReviewGuides = "Code Review Guide"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    66
KCategoryOther = "Other"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    67
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    68
KCategoryHtmlDisplayOrder = [KCategoryLegal,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    69
	KCategoryDefinitePanic,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    70
	KCategoryCanPanic,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    71
	KCategoryWrongFunctionality,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    72
	KCategoryLocalisation,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    73
	KCategoryPerformance,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    74
	KCategoryCodingStandards,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    75
	KCategoryDocumentation,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    76
	KCategoryCodeReviewGuides,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    77
	KCategoryOther]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    78
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    79
# The names used in the XML configuration file for category element names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    80
KCategoryConfigMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    81
			KCategoryLegal				:	"legal", 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    82
			KCategoryDefinitePanic		:	"panic", 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    83
			KCategoryCanPanic			:	"canpanic", 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    84
			KCategoryWrongFunctionality	:	"functionality",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    85
			KCategoryLocalisation		:	"localisation",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    86
			KCategoryPerformance		:	"performance",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    87
			KCategoryCodingStandards	:	"codingstandards",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    88
			KCategoryDocumentation		:	"documentation",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    89
			KCategoryCodeReviewGuides	:	"codereview",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    90
			KCategoryOther				:	"other"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    91
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    92
#Custom rule keyword types
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    93
KKeywordBaseClass = "baseclass"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    94
KKeywordCall = "call"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    95
KKeywordClassName = "class"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    96
KKeywordComment = "comment"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    97
KKeywordGeneric = "generic"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    98
KKeywordLocal = "local"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    99
KKeywordMacro = "macro"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   100
KKeywordMember = "member"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   101
KKeywordMethod = "method"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   102
KKeywordParameter = "parameter"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   103
KKeywordUnknown = "unknown"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   104
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   105
#The names used in the XML configuration file for custom rule keyword types.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   106
KCustomRuleKeywordMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   107
			KKeywordBaseClass           :   "baseclass",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   108
			KKeywordCall                :   "call",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   109
			KKeywordClassName           :   "class",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   110
			KKeywordComment             :   "comment",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   111
			KKeywordGeneric             :   "generic",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   112
			KKeywordLocal               :   "local",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   113
			KKeywordMacro               :   "macro",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   114
			KKeywordMember              :   "member",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   115
			KKeywordMethod              :   "method",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   116
			KKeywordParameter           :   "parameter",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   117
			KKeywordUnknown             :   "unknown"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   118
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   119
KVersion = "Nokia CodeScanner version 2.1.4"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   120
KCopyrightLine1 = "Copyright (c) 2007-2009. Nokia Corporation. All rights reserved."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   121
KCopyrightLine1Html = "Copyright © 2007-2009. Nokia Corporation. All rights reserved."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   122
KCopyrightLine2 = "For product and support information, visit www.forum.nokia.com."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   123
KWww = "www.forum.nokia.com"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   124
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   125
stringPool = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   126
#!LOCALISEHERE
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   127
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   128
def Usage(code, msg=""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   129
	print msg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   130
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   131
	print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   132
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   133
	print "Usage: CodeScanner [options] <source dir> [<output dir>]"	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   134
	print "   or: CodeScanner [options] <source file> [<output dir>]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   135
	print 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   136
	print "options:"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   137
	print "    -h - display command help"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   138
	print "    -v - display verbose messages"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   139
	print "    -c <config file> - use specified configuration file"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   140
	print "    -i <source dir/file> - specify additional directory/file to scan"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   141
	print "    -l <log file> - create debug log with specified filename"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   142
	print "    -o html|xml|std - specify output format : HTML, XML or StdOut; default is HTML"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   143
	print "    -x url to lxr site"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   144
	print "    -r lxr version"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   145
	print "    -t on/off - create a time-stamped directory for results, default is on"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   146
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   147
	print "<source dir> is the directory containing the source code to scan"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   148
	print "<source file> is the single file containing the source code to scan"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   149
	print "<output dir> is the directory in which to produce the output"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   150
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   151
	print "Notes:"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   152
	print "<source dir> and <output dir> cannot be identical"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   153
	print "<output dir> cannot be the root of a drive"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   154
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   155
	print KCopyrightLine1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   156
	print KCopyrightLine2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   157
	if scanner.iLog <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   158
		scanner.iLog.Write("usage(): exiting with code " + str(code))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   159
		scanner.iLog.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   160
	sys.exit(code)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   161
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   162
def DefaultCompare(aLines, aCurrentline, aRematch, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   163
	if aRematch.search(aLines[aCurrentline]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   164
		return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   165
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   166
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   167
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   168
def DefaultFuncParamCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   169
	# distinguish local declaration from function parameter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   170
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   171
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   172
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   173
        isFuncParam = (line.find(")") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   174
        isLocal = (line.find(";") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   175
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   176
        while (not isFuncParam) and (not isLocal) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   177
            currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   178
            line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   179
            isFuncParam = (line.find(")") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   180
            isLocal = (line.find(";") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   181
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   182
        if isFuncParam:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   183
            return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   184
        elif isLocal:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   185
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   186
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   187
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   188
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   189
def ScanDirOrFile(argument):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   190
	if os.path.isdir(argument):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   191
		scanner.iComponentManager.SetRoot(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   192
		scanner.TraverseDirectory(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   193
	elif os.path.isfile(argument):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   194
		parentDir = os.path.dirname(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   195
		scanner.iComponentManager.SetRoot(parentDir)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   196
		scanner.iComponentManager.BeginDirectory(parentDir)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   197
		numberOfLinesScanned = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   198
		numberOfLinesScanned += scanner.ScanFile(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   199
		scanner.iComponentManager.EndDirectory(parentDir, numberOfLinesScanned)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   200
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   201
		print "Unable to open specified source file: " + argument
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   202
		sys.exit(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   203
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   204
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   205
class CScript:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   206
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   207
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   208
	# CScript - a test script
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   209
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   210
	def __init__(self, aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   211
		self.iScriptName = aScriptName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   212
		self.iCompare = DefaultCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   213
		self.iReString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   214
		self.iReMatch = re.compile("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   215
		self.iTitle = stringPool[aScriptName + "!title"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   216
		self.iIdeTitle = stringPool[aScriptName + "!ideTitle"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   217
		self.iFileExts = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   218
		self.iIgnore = KIgnoreNothing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   219
		self.iDescription = stringPool[aScriptName + "!description"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   220
		self.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   221
		self.iBaseClass = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   222
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   223
	def ScriptConfig(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   224
		if (scanner.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   225
			for scriptsNode in scanner.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   226
				for scriptNode in scriptsNode.getElementsByTagName(self.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   227
					return scriptNode
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   228
		return None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   229
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   230
	def DefaultInheritanceCompare(self, lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   231
		m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   232
		if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   233
			inheritanceString = m.group(3)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   234
			# check for inheritance list spanning multiple lines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   235
			i = currentline + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   236
			while (inheritanceString.find("{") == -1) and i < len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   237
				if (inheritanceString.find(";") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   238
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   239
				inheritanceString += lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   240
				i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   241
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   242
			# construct inheritance class list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   243
			inheritancelist = inheritanceString.split(",")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   244
			reclass = re.compile("[\s:]*(public|protected|private)?\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   245
			classlist = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   246
			for inheritance in inheritancelist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   247
				match = reclass.search(inheritance)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   248
				if match:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   249
					inheritclass = match.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   250
					colonpos = inheritclass.rfind(":")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   251
					if (colonpos <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   252
						inheritclass = inheritclass[colonpos + 1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   253
					classlist.append(inheritclass)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   254
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   255
			# search for inheritance class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   256
			for classname in classlist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   257
				if classname == self.iBaseClass:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   258
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   259
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   260
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   261
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   262
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   263
class CCustomScript(CScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   264
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   265
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   266
	# CScript - a test script based on a custom rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   267
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   268
	def __init__(self, aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   269
		self.iScriptName = aScriptName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   270
		self.iCompare = DefaultCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   271
		self.iReString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   272
		self.iTitle = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   273
		self.iIdeTitle = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   274
		self.iFileExts = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   275
		self.iIgnore = KIgnoreNothing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   276
		self.iDescription = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   277
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   278
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   279
class CCategorisedScripts:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   280
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   281
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   282
	# CCategorisedScripts - a collection of scripts sorted
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   283
	# by script category (panic, can panic, etc.)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   284
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   285
	def AddScript(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   286
		# do we have a category for this already?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   287
		category = aScript.iCategory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   288
		if (not self.iScripts.has_key(category)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   289
			# no, create a linear array here
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   290
			self.iScripts[category] = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   291
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   292
		# append to the correct category
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   293
		self.iScripts[category].append(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   294
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   295
		# compile the reg-ex otherwise will get continuous hits
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   296
		aScript.iReMatch = re.compile(aScript.iReString, re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   297
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   298
	def AllScripts(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   299
		result = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   300
		for scripts in self.iScripts.values():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   301
			result += scripts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   302
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   303
		return result
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   304
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   305
	def PrintListOfTestScripts(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   306
		for category in self.iScripts.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   307
			print(category + "\n----------------------------------")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   308
			for script in self.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   309
				print("\t" + script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   310
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   311
		print("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   312
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   313
	# iScripts is a 2D array, 1st level is a hash of categories
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   314
	#                         2nd level is linear array
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   315
	iScripts = {}        
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   316
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   317
class CLogger:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   318
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   319
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   320
	# CLogger
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   321
	# a simple log file interface
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   322
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   323
	def __init__(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   324
		if aFilename != None and len(aFilename) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   325
			self.iFile = file(aFilename, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   326
			self.iFile.write(KVersion + " started at " + datetime.datetime.now().ctime() + "\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   327
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   328
			self.iFile = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   329
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   330
	def Write(self, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   331
		if self.iFile <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   332
			self.iFile.write(str(datetime.datetime.now().time())+":"+aText+"\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   333
			self.iFile.flush()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   334
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   335
	def Close(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   336
		if self.iFile <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   337
			self.iFile.write(KVersion + " ended at " + datetime.datetime.now().ctime() + "\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   338
			self.iFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   339
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   340
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   341
class CRendererBase:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   342
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   343
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   344
	# CRendererBase - base class for renderers
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   345
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   346
	def RegisterSelf(self, aName, aDescription, aRendererManager):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   347
		self.iName = aName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   348
		self.iDescription = aDescription
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   349
		aRendererManager.AddRenderer(self)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   350
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   351
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   352
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   353
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   354
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   355
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   356
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   357
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   358
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   359
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   360
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   361
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   362
class CStdOutRenderer(CRendererBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   363
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   364
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   365
	# CStdOutRenderer - renderer for Standard Console Output
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   366
	# Output goes to standard output; when run in Carbide, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   367
	# this shows up in the output window. Correctly formatted 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   368
	# lines can then be selected, automatically selecting 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   369
	# the corresponding line of the associated source file. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   370
	# The format is:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   371
	#   <filename>(<line>) : <comment>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   372
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   373
	def __init__(self, aRendererManager):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   374
		self.RegisterSelf("stdout", "StdOut renderer", aRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   375
		print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   376
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   377
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   378
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   379
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   380
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   381
		self.iErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   382
		scanner.ReportAction("Scanning file " + aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   383
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   384
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   385
		self.iErrorCount += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   386
		if (aScript.iSeverity == KSeverityLow):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   387
			msgType = "info"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   388
		elif (aScript.iSeverity == KSeverityMedium):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   389
			msgType = "warning"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   390
		elif (aScript.iSeverity == KSeverityHigh):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   391
			msgType = "error"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   392
		print(aLineContext.iFileName + "(" + str(aLineContext.iLineNumber) + ") : " + msgType + ": " + aScript.iScriptName + ": " + KSeverityConfigMap[aScript.iSeverity] + ": " + KCategoryConfigMap[aScript.iCategory] + ": " + aScript.iIdeTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   393
		if len(scanner.iRendererManager.iAnnotation)>0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   394
			print scanner.iRendererManager.iAnnotation
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   395
			scanner.iRendererManager.iAnnotation = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   396
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   397
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   398
		scanner.ReportAction("Total problems found in file: " + str(self.iErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   399
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   400
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   401
		scanner.iEndTime = datetime.datetime.now().ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   402
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   403
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   404
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   405
class CXmlComponentSummaryFile:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   406
	# #########################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   407
	# CXmlComponentSummaryFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   408
	# Encapsulates the script (problem) summary for XML output.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   409
	# For each script, there is a listing for occurrences
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   410
	# of that script's problem and location of each occurrence.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   411
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   412
	def CreateSummary(self, aXmlRenderer):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   413
		try:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   414
			outputPath = os.path.normpath(os.path.join(aXmlRenderer.iOutputDirectory, "problemIndex.xml"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   415
			outputFile = file(outputPath, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   416
		except IOError:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   417
			scanner.ReportError("IOError : Unable to create output file " + outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   418
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   419
			errors = aXmlRenderer.iErrors
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   420
			level = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   421
			indent = "   "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   422
			outputFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   423
			outputFile.write(level * indent + "<problemIndex>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   424
			level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   425
			for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   426
				found = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   427
				if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   428
					for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   429
						if errors.has_key(script.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   430
							found = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   431
							break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   432
					if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   433
						outputFile.write(level * indent + "<category")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   434
						outputFile.write(" name=\"" + KCategoryConfigMap[category] + "\">\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   435
						level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   436
						for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   437
							if errors.has_key(script.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   438
								outputFile.write(level * indent + "<problem")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   439
								outputFile.write(" name=\"" + script.iScriptName + "\"")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   440
								outputFile.write(" severity=\"" + KSeverityConfigMap[script.iSeverity] + "\">\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   441
								level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   442
								for fileName, lines in errors[script.iScriptName].items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   443
									outputFile.write(level * indent + "<file")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   444
									outputFile.write(" path=\"" + fileName + "\">\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   445
									level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   446
									for lineNo in lines:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   447
										outputFile.write(level * indent + str(lineNo) + "\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   448
									level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   449
									outputFile.write(level * indent + "</file>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   450
								level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   451
								outputFile.write(level * indent + "</problem>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   452
						level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   453
						outputFile.write(level * indent + "</category>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   454
			level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   455
			outputFile.write(level * indent + "</problemIndex>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   456
			outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   457
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   458
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   459
class CXmlRenderer(CRendererBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   460
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   461
	# ########################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   462
	# CXmlRenderer - a renderer for XML output
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   463
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   464
	def __init__(self, aRendererManager, aOutputDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   465
		self.RegisterSelf("xml", "XML renderer", aRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   466
		self.iOutputDirectory = aOutputDirectory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   467
		if os.path.isdir(self.iOutputDirectory) != True :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   468
			os.makedirs(self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   469
		self.iErrors = {} 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   470
		print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   471
		print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   472
		print KCopyrightLine1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   473
		print KCopyrightLine2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   474
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   475
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   476
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   477
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   478
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   479
		self.iFilename = aFilename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   480
		scanner.ReportAction("Scanning file " + aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   481
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   482
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   483
		scriptName = aScript.iScriptName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   484
		fileName = aLineContext.iFileName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   485
		lineNumber = aLineContext.iLineNumber
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   486
		if (not self.iErrors.has_key(scriptName)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   487
			self.iErrors[scriptName] = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   488
		if (not self.iErrors[scriptName].has_key(fileName)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   489
			self.iErrors[scriptName][fileName] = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   490
		self.iErrors[scriptName][fileName].append(lineNumber)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   491
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   492
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   493
		#tbd
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   494
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   495
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   496
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   497
		relativeComponentName = scanner.iComponentManager.RelativeComponentName(aComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   498
		if len(relativeComponentName) < 1:	# root component - final component
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   499
			scanner.iEndTime = datetime.datetime.now().ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   500
			componentSummaryFile = CXmlComponentSummaryFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   501
			componentSummaryFile.CreateSummary(self)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   502
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   503
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   504
class CHtmlOutputFileBase:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   505
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   506
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   507
	# CHtmlOutputFileBase - base class for HTML output files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   508
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   509
	def WriteHeader(self, aOutputFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   510
		aOutputFile.write("<html><body>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   511
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   512
	def Write(self, aOutputFile, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   513
		aOutputFile.write(aText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   514
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   515
	def WriteLink(self, aOutputFile, aHref, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   516
		aHref = self.CleanupLink(aHref)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   517
		aOutputFile.write("<a href=\"" + aHref + "\">" + aText + "</a>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   518
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   519
	def WriteElement(self, aOutputFile, aElementName, aElementValue):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   520
		aOutputFile.write("<"+aElementName+">"+aElementValue+"</"+aElementName+">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   521
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   522
	def WriteBreak(self, aOutputFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   523
		aOutputFile.write("<br>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   524
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   525
	def WriteFooter(self, aOutputFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   526
		aOutputFile.write("<br><hr><center><h5>"+KCopyrightLine1Html+"</h5>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   527
		aOutputFile.write("<h5>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   528
		CHtmlOutputFileBase.WriteLink(self, aOutputFile, "http://"+KWww, KWww)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   529
		aOutputFile.write("</h5></center></body></html>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   530
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   531
	def CleanupLink(self, aHref):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   532
		# Mozilla Firefox does not handle link with the '#' character correctly, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   533
		# so we need to replace it with the equivalent URL encoding "%23"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   534
		aHref = aHref.replace("#", "%23")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   535
		# Mozilla Firefox sometimes does not handle link with '\' correctly,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   536
		# so we need to replace it with '/'
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   537
		aHref = aHref.replace('\\', '/')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   538
		return aHref
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   539
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   540
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   541
class CHtmlOutputFile(CHtmlOutputFileBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   542
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   543
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   544
	# CHtmlOutputFile - simplified access to HTML output file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   545
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   546
	def __init__(self, aOutputPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   547
		if not os.path.isdir(os.path.dirname(aOutputPath)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   548
			os.makedirs(os.path.dirname(aOutputPath))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   549
		self.iOutputFile = file(aOutputPath, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   550
		self.WriteHeader(self.iOutputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   551
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   552
	def Write(self, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   553
		CHtmlOutputFileBase.Write(self, self.iOutputFile, aText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   554
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   555
	def WriteLink(self, aHref, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   556
		CHtmlOutputFileBase.WriteLink(self, self.iOutputFile, aHref, aText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   557
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   558
	def WriteElement(self, aElementName, aElementValue):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   559
		CHtmlOutputFileBase.WriteElement(self, self.iOutputFile, aElementName, aElementValue)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   560
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   561
	def WriteBreak(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   562
		CHtmlOutputFileBase.WriteBreak(self, self.iOutputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   563
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   564
	def Close(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   565
		self.WriteFooter(self.iOutputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   566
		self.iOutputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   567
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   568
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   569
class CHtmlComponentSummaryFiles:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   570
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   571
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   572
	# CHtmlComponentSummaryFiles
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   573
	# Encapsulates the component summary files for HTML output.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   574
	# For each component, there is a component report file listing the number 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   575
	# of occurrences of each problem type. There is also a single index or 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   576
	# summary file with links to each of the component report files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   577
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   578
	def CreateSummaries(self, aHtmlRenderer, aOutputDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   579
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   580
		outputPath = os.path.normpath(os.path.join(aOutputDirectory, "componentIndex.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   581
		componentSummaryFile = CHtmlOutputFile(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   582
		componentSummaryFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   583
		componentSummaryFile.WriteElement("h2", "Component Summary")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   584
		componentSummaryFile.Write("Source: "+scanner.iSource)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   585
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   586
		componentSummaryFile.Write("Scan started at:   " + scanner.iStartTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   587
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   588
		componentSummaryFile.Write("Scan completed at: " + scanner.iEndTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   589
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   590
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   591
		componentSummaryFile.WriteLink("problemIndex.html", "View problems by type")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   592
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   593
		componentSummaryFile.Write("<hr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   594
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   595
		componentSummaryFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   596
		componentSummaryFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   597
		componentSummaryFile.WriteElement("th width=\"75%\"", "Component")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   598
		componentSummaryFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   599
		componentSummaryFile.WriteElement("th", "Lines of Code")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   600
		componentSummaryFile.WriteElement("th", "Possible Defects/KLOC")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   601
		componentSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   602
		for component in scanner.iComponentManager.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   603
			componentName = scanner.iComponentManager.ComponentName(component.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   604
			outputPath = os.path.normpath(os.path.join(aOutputDirectory, "byComponent"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   605
			outputPath = os.path.normpath(os.path.join(outputPath, componentName))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   606
			outputPath = os.path.normpath(os.path.join(outputPath, "componentSummary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   607
			errorCount = self.WriteComponentReport(aHtmlRenderer, outputPath, component.iFullPath, componentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   608
			if (errorCount > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   609
				totalErrorCount = totalErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   610
				numberOfLinesScanned = component.iNumberOfLinesScanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   611
				if (numberOfLinesScanned > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   612
					defectsPerKLOC = int((1000.0 / numberOfLinesScanned) * errorCount)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   613
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   614
					defectsPerKLOC = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   615
				componentSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   616
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   617
				relOutputPath = os.path.normpath(os.path.join("byComponent", componentName))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   618
				relOutputPath = os.path.normpath(os.path.join(relOutputPath, "componentSummary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   619
				componentSummaryFile.WriteLink(relOutputPath, component.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   620
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   621
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   622
				componentSummaryFile.WriteElement("center",str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   623
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   624
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   625
				componentSummaryFile.WriteElement("center",str(numberOfLinesScanned))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   626
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   627
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   628
				componentSummaryFile.WriteElement("center",str(defectsPerKLOC))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   629
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   630
				componentSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   631
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   632
		componentSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   633
		componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   634
		componentSummaryFile.WriteElement("b", "Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   635
		componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   636
		componentSummaryFile.Write("<td><center>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   637
		componentSummaryFile.WriteElement("b", str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   638
		componentSummaryFile.Write("</center></td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   639
		componentSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   640
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   641
		componentSummaryFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   642
		componentSummaryFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   643
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   644
	def WriteComponentReport(self, aHtmlRenderer, aOutputPath, aComponentFullPath, aComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   645
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   646
		componentReportFile = CHtmlOutputFile(aOutputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   647
		componentReportFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   648
		componentReportFile.WriteElement("h2", "Component Report")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   649
		componentReportFile.WriteElement("h3", "Component: "+aComponentFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   650
		componentReportFile.Write("<font face=verdana color=black>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   651
		found = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   652
		for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   653
			if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   654
				for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   655
					errorCount = scanner.iComponentManager.ScriptComponentErrorCount(aComponentFullPath, script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   656
					if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   657
						found = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   658
						break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   659
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   660
		if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   661
			componentReportFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   662
			componentReportFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   663
			componentReportFile.WriteElement("th width=\"75%\"", "Problem")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   664
			componentReportFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   665
			componentReportFile.WriteElement("th", "Severity")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   666
			componentReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   667
			for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   668
				if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   669
					for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   670
						errorCount = scanner.iComponentManager.ScriptComponentErrorCount(aComponentFullPath, script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   671
						if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   672
							componentReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   673
							componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   674
							#scriptComponentPath = aHtmlRenderer.ScriptComponentPath(aComponentFullPath, script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   675
							#componentReportFile.WriteLink(scriptComponentPath, script.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   676
							componentReportFile.WriteLink(script.iScriptName+".html", script.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   677
							componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   678
							componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   679
							componentReportFile.WriteElement("center", str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   680
							componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   681
							componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   682
							componentReportFile.WriteElement("center", KSeverityHTMLMap[script.iSeverity])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   683
							componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   684
							componentReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   685
							totalErrorCount = totalErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   686
			componentReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   687
			componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   688
			componentReportFile.WriteElement("b", "Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   689
			componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   690
			componentReportFile.Write("<td><center>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   691
			componentReportFile.WriteElement("b", str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   692
			componentReportFile.Write("</center></td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   693
			componentReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   694
			componentReportFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   695
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   696
			componentReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   697
			componentReportFile.WriteElement("i", "There are no items to report for this component.")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   698
			componentReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   699
		componentReportFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   700
		return totalErrorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   701
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   702
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   703
class CHtmlScriptSummaryFiles:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   704
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   705
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   706
	# CHtmlScriptSummaryFiles
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   707
	# Encapsulates the script (problem) summary files for HTML output.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   708
	# For each script, there is a file listing the number of occurrences
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   709
	# of that script's problem for each component. There is also a single
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   710
	# index or summary file with links to each of the problem report file.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   711
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   712
	def CreateSummaries(self, aHtmlRenderer, aOutputDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   713
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   714
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   715
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   716
		outputPath = os.path.normpath(os.path.join(aOutputDirectory, "problemIndex.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   717
		scriptSummaryFile = CHtmlOutputFile(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   718
		scriptSummaryFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   719
		scriptSummaryFile.WriteElement("h2", "Problem Summary")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   720
		scriptSummaryFile.Write("Source: "+scanner.iSource)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   721
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   722
		scriptSummaryFile.Write("Scan started at:   " + scanner.iStartTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   723
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   724
		scriptSummaryFile.Write("Scan completed at: " + scanner.iEndTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   725
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   726
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   727
		scriptSummaryFile.WriteLink("componentIndex.html", "View problems by component")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   728
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   729
		scriptSummaryFile.Write("<hr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   730
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   731
		for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   732
			if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   733
				scriptSummaryFile.WriteElement("h3", "Category: "+category)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   734
				scriptSummaryFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   735
				scriptSummaryFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   736
				scriptSummaryFile.WriteElement("th width=\"75%\"", "Problem")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   737
				scriptSummaryFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   738
				scriptSummaryFile.WriteElement("th", "Severity")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   739
				scriptSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   740
				categoryErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   741
				for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   742
					outputPath = os.path.normpath(os.path.join(aOutputDirectory, "byProblem"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   743
					outputPath = os.path.normpath(os.path.join(outputPath, script.iScriptName+"Summary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   744
					errorCount = self.WriteScriptReport(aHtmlRenderer, outputPath, script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   745
					categoryErrorCount = categoryErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   746
					scriptSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   747
					scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   748
					relOutputPath = os.path.normpath(os.path.join("byProblem", script.iScriptName+"Summary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   749
					scriptSummaryFile.WriteLink(relOutputPath, script.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   750
					scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   751
					scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   752
					scriptSummaryFile.WriteElement("center", str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   753
					scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   754
					scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   755
					scriptSummaryFile.WriteElement("center", KSeverityHTMLMap[script.iSeverity])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   756
					scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   757
					scriptSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   758
				totalErrorCount = totalErrorCount + categoryErrorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   759
				scriptSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   760
				scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   761
				scriptSummaryFile.WriteElement("b", "Category Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   762
				scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   763
				scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   764
				scriptSummaryFile.WriteElement("center", "<b>"+str(categoryErrorCount)+"</b>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   765
				scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   766
				scriptSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   767
				scriptSummaryFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   768
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   769
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   770
		scriptSummaryFile.WriteElement("b", "Total: " + str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   771
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   772
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   773
		scriptSummaryFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   774
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   775
	def WriteScriptReport(self, aHtmlRenderer, aOutputPath, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   776
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   777
		scriptReportFile = CHtmlOutputFile(aOutputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   778
		scriptReportFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   779
		scriptReportFile.WriteElement("h2", "Problem Report")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   780
		scriptReportFile.WriteElement("h3", "Problem: " + aScript.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   781
		scriptReportFile.Write(aScript.iDescription)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   782
		scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   783
		scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   784
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   785
		found = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   786
		for component in scanner.iComponentManager.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   787
			errorCount = scanner.iComponentManager.ScriptComponentErrorCount(component.iFullPath, aScript.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   788
			if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   789
				found = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   790
				break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   791
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   792
		if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   793
			scriptReportFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   794
			scriptReportFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   795
			scriptReportFile.WriteElement("th width=\"80%\"", "Component")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   796
			scriptReportFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   797
			scriptReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   798
			for component in scanner.iComponentManager.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   799
				errorCount = scanner.iComponentManager.ScriptComponentErrorCount(component.iFullPath, aScript.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   800
				if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   801
					scriptReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   802
					scriptReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   803
					scriptComponentPath = aHtmlRenderer.ScriptComponentPath(component.iFullPath, aScript.iScriptName, "..")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   804
					scriptReportFile.WriteLink(scriptComponentPath, component.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   805
					scriptReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   806
					scriptReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   807
					scriptReportFile.WriteElement("center", str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   808
					scriptReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   809
					scriptReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   810
					totalErrorCount = totalErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   811
			scriptReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   812
			scriptReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   813
			scriptReportFile.WriteElement("b", "Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   814
			scriptReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   815
			scriptReportFile.Write("<td><center>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   816
			scriptReportFile.WriteElement("b", str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   817
			scriptReportFile.Write("</center></td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   818
			scriptReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   819
			scriptReportFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   820
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   821
			scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   822
			scriptReportFile.WriteElement("i", "There are no items of this problem type to report.")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   823
			scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   824
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   825
		scriptReportFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   826
		return totalErrorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   827
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   828
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   829
class CHtmlScriptComponentFile:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   830
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   831
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   832
	# CHtmlScriptComponentFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   833
	# Encapsulates access to the HTML output files with the greatest amount of detail.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   834
	# Each of these files is for a specific problem (script) and for a specific component.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   835
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   836
	# The file handle is closed between each call to avoid exhausting the system
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   837
	# limit for open file handles. Many of these files may be open at one time,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   838
	# and the number of open files is dependent on both the directory structure
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   839
	# being traversed and the number of types of problems found.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   840
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   841
	def __init__(self, aLxrUrl, aLxrVersion):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   842
		self.iLxrUrl = aLxrUrl
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   843
		self.iLxrVersion = aLxrVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   844
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   845
	def BeginOutputFile(self, aOutputPath, aScript, aComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   846
		if not os.path.isdir(os.path.dirname(aOutputPath)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   847
			os.makedirs(os.path.dirname(aOutputPath))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   848
		outputFile = file(aOutputPath, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   849
		self.iScriptComponentFile = CHtmlOutputFileBase()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   850
		self.iScriptComponentFile.Write(outputFile, "<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   851
		self.iScriptComponentFile.WriteHeader(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   852
		self.iScriptComponentFile.WriteElement(outputFile, "h2", "Detailed Problem Report")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   853
		self.iScriptComponentFile.WriteElement(outputFile, "h3", "Component: "+aComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   854
		self.iScriptComponentFile.WriteElement(outputFile, "h3", "Problem: "+aScript.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   855
		self.iScriptComponentFile.Write(outputFile, aScript.iDescription)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   856
		self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   857
		self.iScriptComponentFile.Write(outputFile, "<hr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   858
		self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   859
		outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   860
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   861
	def ReportError(self, aOutputPath, aLineContext):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   862
		outputFile = file(aOutputPath, "a")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   863
		if self.iLxrUrl == None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   864
			# Mozilla Firefox cannot open links to local files, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   865
			# so it is necessary to convert local file path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   866
			filePath = "file:///" + aLineContext.iFileName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   867
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   868
			# generate link to LXR server instead of local file system
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   869
			filePath = self.iLxrUrl + aLineContext.iFileName[len(scanner.iComponentManager.iRootPath):]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   870
			if self.iLxrVersion <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   871
				filePath = filePath + "?v="+self.iLxrVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   872
			filePath = filePath + '#%03d'%aLineContext.iLineNumber
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   873
		self.iScriptComponentFile.WriteLink(outputFile, filePath, self.TrimFileName(aLineContext))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   874
		self.iScriptComponentFile.Write(outputFile, "(" + str(aLineContext.iLineNumber) + ") ")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   875
		self.iScriptComponentFile.Write(outputFile, aLineContext.iClassName+"::"+aLineContext.iMethodName+" ")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   876
		self.iScriptComponentFile.Write(outputFile, "<code><font color=red>"+self.CleanUpText(aLineContext.iLineText))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   877
		self.iScriptComponentFile.Write(outputFile, "</font></code>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   878
		self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   879
		if len(scanner.iRendererManager.iAnnotation)>0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   880
			self.iScriptComponentFile.Write(outputFile, scanner.iRendererManager.iAnnotation)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   881
			self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   882
			scanner.iRendererManager.iAnnotation = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   883
		outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   884
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   885
	def EndOutputFile(self, aOutputPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   886
		outputFile = file(aOutputPath, "a")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   887
		self.iScriptComponentFile.WriteFooter(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   888
		outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   889
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   890
	def TrimFileName(self, aLineContext):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   891
		filename = aLineContext.iFileName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   892
		componentNameLen = len(aLineContext.iComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   893
		if len(filename) > componentNameLen:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   894
			if filename[0:componentNameLen] == aLineContext.iComponentName:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   895
				filename = filename[componentNameLen:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   896
				if filename[0] == os.path.sep:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   897
					filename = filename[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   898
		return filename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   899
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   900
	def CleanUpText(self, aLineText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   901
		# check for sub-strings that look like HTML tags and preform clean up if needed
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   902
		reTag = re.compile(r"""(<.+>)""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   903
		foundTag = reTag.search(aLineText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   904
		if foundTag:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   905
			aNewLineText = aLineText.replace("<", "&lt;")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   906
			aNewLineText = aNewLineText.replace(">", "&gt;")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   907
			return aNewLineText
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   908
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   909
			return aLineText		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   910
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   911
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   912
def ComponentCompare(a, b):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   913
	return cmp(os.path.normcase(a.iFullPath), os.path.normcase(b.iFullPath))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   914
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   915
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   916
class CHtmlRenderer(CRendererBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   917
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   918
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   919
	# CHtmlRenderer - a renderer for HTML output
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   920
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   921
	# I have nothing to offer but blood, toil, tears and sweat. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   922
	#  - Winston Churchill, 1940 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   923
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   924
	def __init__(self, aRendererManager, aOutputDirectory, aLxrUrl, aLxrVersion):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   925
		self.RegisterSelf("html", "HTML renderer", aRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   926
		self.iOutputDirectory = aOutputDirectory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   927
		if os.path.isdir(self.iOutputDirectory) != True :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   928
			os.makedirs(self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   929
		self.iScriptComponentFile = CHtmlScriptComponentFile(aLxrUrl, aLxrVersion)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   930
		self.iScriptComponentFilePaths = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   931
		print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   932
		print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   933
		print KCopyrightLine1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   934
		print KCopyrightLine2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   935
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   936
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   937
		self.iFilename = aFilename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   938
		scanner.ReportAction("Scanning file " + aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   939
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   940
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   941
		outputPath = self.ScriptComponentPath(aLineContext.iComponentName, aScript.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   942
		if not os.path.isfile(outputPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   943
			self.iScriptComponentFilePaths[aLineContext.iComponentName].append(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   944
			self.iScriptComponentFile.BeginOutputFile(outputPath, aScript, aLineContext.iComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   945
		self.iScriptComponentFile.ReportError(outputPath, aLineContext)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   946
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   947
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   948
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   949
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   950
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   951
		self.iScriptComponentFilePaths[aComponent.iFullPath] = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   952
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   953
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   954
		if self.iScriptComponentFilePaths.has_key(aComponent.iFullPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   955
			for outputPath in self.iScriptComponentFilePaths[aComponent.iFullPath]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   956
				self.iScriptComponentFile.EndOutputFile(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   957
			del self.iScriptComponentFilePaths[aComponent.iFullPath]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   958
		relativeComponentName = scanner.iComponentManager.RelativeComponentName(aComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   959
		if len(relativeComponentName) < 1:	# root component - final component
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   960
			scanner.iEndTime = datetime.datetime.now().ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   961
			scanner.iComponentManager.iCompletedComponents.sort(ComponentCompare)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   962
			scriptSummaryFiles = CHtmlScriptSummaryFiles()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   963
			scriptSummaryFiles.CreateSummaries(self, self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   964
			componentSummaryFiles = CHtmlComponentSummaryFiles()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   965
			componentSummaryFiles.CreateSummaries(self, self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   966
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   967
	def ScriptComponentPath(self, aComponentName, aScriptName, aRel=None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   968
		componentName = scanner.iComponentManager.ComponentName(aComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   969
		if aRel==None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   970
			aRel = self.iOutputDirectory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   971
		outputPath = os.path.normpath(os.path.join(aRel, "byComponent"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   972
		outputPath = os.path.normpath(os.path.join(outputPath, componentName))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   973
		outputPath = os.path.normpath(os.path.join(outputPath, aScriptName+".html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   974
		return outputPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   975
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   976
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   977
class CRendererManager:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   978
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   979
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   980
	# CRendererManager
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   981
	# this class handles all the renderers 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   982
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   983
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   984
		# declare associative list of renderers: iRendererList[name]=renderer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   985
		self.iRendererList = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   986
		self.iAnnotation = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   987
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   988
	def AddRenderer(self, aRenderer):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   989
		self.iRendererList[aRenderer.iName.lower()] = aRenderer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   990
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   991
	def PrintListOfRenderers(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   992
		print("Renderers:")        
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   993
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   994
			print("\t" + name + "\t" + renderer.iDescription)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   995
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   996
		print("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   997
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   998
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   999
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1000
			renderer.BeginFile(aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1001
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1002
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1003
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1004
			renderer.ReportError(aLineContext, aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1005
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1006
	def ReportAnnotation(self, aAnnotation):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1007
		self.iAnnotation = aAnnotation
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1008
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1009
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1010
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1011
			renderer.EndFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1012
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1013
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1014
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1015
			renderer.BeginComponent(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1016
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1017
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1018
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1019
			renderer.EndComponent(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1020
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1021
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1022
class CComponent:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1023
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1024
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1025
	# CComponent - a single component, identified by the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1026
	# directory path to its source code
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1027
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1028
	def __init__(self, aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1029
		self.iFullPath = aPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1030
		self.iScriptErrorCounts = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1031
		self.iHasGroupDir = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1032
		self.iNumberOfLinesScanned = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1033
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1034
	def appendComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1035
		for scriptName in aComponent.iScriptErrorCounts.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1036
			if self.iScriptErrorCounts.has_key(scriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1037
				self.iScriptErrorCounts[scriptName] += aComponent.iScriptErrorCounts[scriptName]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1038
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1039
				self.iScriptErrorCounts[scriptName] = aComponent.iScriptErrorCounts[scriptName]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1040
		self.iNumberOfLinesScanned += aComponent.iNumberOfLinesScanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1041
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1042
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1043
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1044
class CComponentManager:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1045
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1046
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1047
	# CComponentManager - controls access to components
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1048
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1049
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1050
		self.iComponentStack = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1051
		self.iCompletedComponents = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1052
		self.iRootComponent = CComponent("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1053
		self.iUseFullComponentPath = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1054
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1055
	def SetRoot(self, aRootPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1056
		# set the list of root directories - used to left-trim component names
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1057
		self.iRootPath = self.SanitizePath(aRootPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1058
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1059
	def BeginDirectory(self, aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1060
		aPath = self.SanitizePath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1061
		if os.path.isdir(aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1062
			newComponent = CComponent(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1063
			contents = os.listdir(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1064
			for entry in contents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1065
				if (entry.upper() == "GROUP"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1066
					entryPath = os.path.normpath(os.path.join(aPath, entry))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1067
					if os.path.isdir(entryPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1068
						newComponent.iHasGroupDir = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1069
						break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1070
			if len(self.iComponentStack) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1071
				topComponent = self.iComponentStack[len(self.iComponentStack)-1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1072
				if (newComponent.iHasGroupDir or (not topComponent.iHasGroupDir)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1073
					self.BeginComponent(newComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1074
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1075
					scanner.iLog.Write(aPath + " taken as part of " + topComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1076
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1077
				self.BeginComponent(newComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1078
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1079
			scanner.iLog.Write("ERROR: CComponentManager::BeginDirectory: bad path "+aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1080
		return aPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1081
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1082
	def EndDirectory(self, aPath, numberOfLinesScanned):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1083
		aPath = self.SanitizePath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1084
		if len(self.iComponentStack) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1085
			topComponent = self.iComponentStack[len(self.iComponentStack)-1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1086
			topComponent.iNumberOfLinesScanned += numberOfLinesScanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1087
			if (topComponent.iFullPath == aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1088
				self.EndComponent()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1089
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1090
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1091
		scanner.iRendererManager.ReportError(aLineContext, aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1092
		for component in self.iComponentStack:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1093
			if component.iFullPath == aLineContext.iComponentName:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1094
				if component.iScriptErrorCounts.has_key(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1095
					component.iScriptErrorCounts[aScript.iScriptName] = component.iScriptErrorCounts[aScript.iScriptName] + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1096
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1097
					component.iScriptErrorCounts[aScript.iScriptName] = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1098
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1099
	def ScriptComponentErrorCount(self, aComponentName, aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1100
		for component in self.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1101
			if component.iFullPath == aComponentName:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1102
				if component.iScriptErrorCounts.has_key(aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1103
					return component.iScriptErrorCounts[aScriptName]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1104
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1105
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1106
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1107
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1108
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1109
		scanner.iRendererManager.BeginComponent(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1110
		scanner.ReportAction("Begin component: " + aComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1111
		self.iComponentStack.append(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1112
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1113
	def EndComponent(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1114
		previousComponent = self.iComponentStack.pop()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1115
		matchingComponent = self.MatchingComponent(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1116
		if (matchingComponent <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1117
			matchingComponent.appendComponent(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1118
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1119
			self.iCompletedComponents.append(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1120
		scanner.ReportAction("End component: " + previousComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1121
		scanner.iRendererManager.EndComponent(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1122
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1123
	def MatchingComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1124
		for component in self.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1125
			if (ComponentCompare(component, aComponent) == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1126
				return component
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1127
		return None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1128
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1129
	def CurrentComponentName(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1130
		if len(self.iComponentStack) < 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1131
			return None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1132
		return self.iComponentStack[len(self.iComponentStack)-1].iFullPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1133
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1134
	def SanitizePath(self, aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1135
		# Translate an unspecified or relative pathname into an absolute pathname
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1136
		if len(aPath) < 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1137
			aPath = "."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1138
		aPath = os.path.normpath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1139
		# translate "." and ".." into absolute paths
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1140
		aPath = os.path.abspath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1141
		return aPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1142
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1143
	def ComponentName(self, aFullComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1144
		if (self.iUseFullComponentPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1145
			(unused, componentName) = os.path.splitdrive(aFullComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1146
			if len(componentName) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1147
				if componentName[0] == os.path.sep and len(componentName) > 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1148
					componentName = componentName[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1149
			return componentName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1150
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1151
			return self.RelativeComponentName(aFullComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1152
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1153
	def RelativeComponentName(self, aFullComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1154
		# Remove the root path from the specified component name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1155
		rootLen = len(self.iRootPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1156
		if aFullComponentName[0:rootLen] == self.iRootPath:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1157
			relativeComponentName = aFullComponentName[rootLen:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1158
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1159
			# this case is unexpected...but we'll try to make the best of it
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1160
			(unused, relativeComponentName) = os.path.splitdrive(aFullComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1161
		# trim leading path separator, if present
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1162
		if len(relativeComponentName) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1163
			if relativeComponentName[0] == os.path.sep and len(relativeComponentName) > 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1164
				relativeComponentName = relativeComponentName[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1165
		return relativeComponentName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1166
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1167
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1168
class CLineContext:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1169
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1170
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1171
	# CLineContext
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1172
	# A description of the line of source code currently being scanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1173
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1174
	iComponentName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1175
	iFileName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1176
	iLineNumber = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1177
	iClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1178
	iMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1179
	iLineText = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1180
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1181
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1182
class CCodeScanner:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1183
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1184
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1185
	# CCodeScanner - main application class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1186
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1187
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1188
		self.iCategoriedScripts = CCategorisedScripts()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1189
		self.iRendererManager   = CRendererManager()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1190
		self.iComponentManager = CComponentManager()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1191
		self.iLineContext = CLineContext()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1192
		self.iDomConfig = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1193
		self.iVerbose = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1194
		self.iLog = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1195
		self.iSource = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1196
		self.iEncodedFileList = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1197
		self.iOutputDirectory = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1198
		self.iStartTimeObj = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1199
		self.iStartTime = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1200
		self.iEndTime = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1201
		self.iLxrUrl = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1202
		self.iLxrVersion = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1203
		self.iConfigFilename = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1204
		self.iInputFilenames = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1205
		self.iLogFilename = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1206
		self.iOutputFormat = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1207
		self.iTimeStampedOutput = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1208
		self.iReMethod = re.compile(r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1209
			((?P<class>\w+)::~?)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1210
			(?P<method>[A-Za-z0-9<>=!*\-+/]+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1211
			[\s\n]*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1212
			\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1213
			[^;]*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1214
			$
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1215
			""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1216
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1217
	def ReportError(self, aErrorMsg):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1218
		self.iLog.Write(aErrorMsg)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1219
		print aErrorMsg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1220
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1221
	def ReportAction(self, aAction):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1222
		self.iLog.Write(aAction)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1223
		if self.iVerbose:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1224
			print aAction
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1225
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1226
	def ReportInfo(self, aInfoMsg):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1227
		self.iLog.Write(aInfoMsg)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1228
		print aInfoMsg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1229
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1230
	def CleanOutputDirectory(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1231
		self.iLog.Write("Deleting existing contents of output directory " + self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1232
		for root, dirs, files in os.walk(self.iOutputDirectory, topdown = False):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1233
			for name in files:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1234
				os.remove(os.path.join(root, name))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1235
			for name in dirs:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1236
				os.rmdir(os.path.join(root, name))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1237
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1238
	def CheckSourceIncluded(self, aSourceFileName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1239
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1240
			for sourceNode in self.iDomConfig.getElementsByTagName("sources"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1241
				for excludeSourceNode in sourceNode.getElementsByTagName("exclude"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1242
					reExcludeSourceStr = excludeSourceNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1243
					reExcludeSource = re.compile(reExcludeSourceStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1244
					if reExcludeSource.search(aSourceFileName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1245
						self.ReportInfo("Note: excluding " + aSourceFileName + " : " + reExcludeSourceStr)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1246
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1247
		return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1248
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1249
	def CheckScriptEnabled(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1250
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1251
			for scriptsNode in self.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1252
				for scriptNode in scriptsNode.getElementsByTagName(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1253
					enabledAttr = scriptNode.getAttribute("enable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1254
					if (enabledAttr.lower() == "false"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1255
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1256
			for severitiesNode in self.iDomConfig.getElementsByTagName("severities"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1257
				for severityNode in severitiesNode.getElementsByTagName(KSeverityConfigMap[aScript.iSeverity]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1258
					enabledAttr = severityNode.getAttribute("enable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1259
					if (enabledAttr.lower() == "false"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1260
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1261
			for categoriesNode in self.iDomConfig.getElementsByTagName("categories"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1262
				for categoryNode in categoriesNode.getElementsByTagName(KCategoryConfigMap[aScript.iCategory]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1263
					enabledAttr = categoryNode.getAttribute("enable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1264
					if (enabledAttr.lower() == "false"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1265
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1266
		return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1267
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1268
	def UpdateScriptCategory(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1269
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1270
			for scriptsNode in self.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1271
				for scriptNode in scriptsNode.getElementsByTagName(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1272
					if scriptNode.hasAttribute("category"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1273
						newCategory = scriptNode.getAttribute("category").lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1274
						if (newCategory <> KCategoryConfigMap[aScript.iCategory]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1275
							for name, value in KCategoryConfigMap.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1276
								if (newCategory == value):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1277
									return name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1278
		# no update needed, return original category
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1279
		return aScript.iCategory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1280
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1281
	def UpdateScriptSeverity(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1282
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1283
			for scriptsNode in self.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1284
				for scriptNode in scriptsNode.getElementsByTagName(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1285
					if scriptNode.hasAttribute("severity"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1286
						newSeverity = scriptNode.getAttribute("severity").lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1287
						if (newSeverity <> KSeverityConfigMap[aScript.iSeverity]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1288
							for name, value in KSeverityConfigMap.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1289
								if (newSeverity == value):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1290
									return name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1291
		# no update needed, return original severity
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1292
		return aScript.iSeverity
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1293
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1294
	def ScanFile(self, aSourceFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1295
		self.iLineContext.iFileName = aSourceFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1296
		self.iLineContext.iLineNumber = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1297
		self.iLineContext.iClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1298
		self.iLineContext.iMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1299
		self.iLineContext.iComponentName = self.iComponentManager.CurrentComponentName()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1300
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1301
		self.iRendererManager.BeginFile(aSourceFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1302
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1303
		# note source file extension - used for filtering later on
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1304
		(unused, sourceFileExt) = os.path.splitext(aSourceFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1305
		if len(sourceFileExt) > 0 and sourceFileExt[0] == '.':
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1306
			sourceFileExt = sourceFileExt[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1307
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1308
		# open, read, and preparse source file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1309
		inputFileHandle = file(aSourceFile, "r")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1310
		inputFileLines = inputFileHandle.readlines()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1311
		inputFileHandle.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1312
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1313
		(noQuoteFileLines, noCommentFileLines, noCommentOrQuoteFileLines, csCommands) = self.PreParseSourceFile(inputFileLines)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1314
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1315
		# bundle all the filtered versions of the file contents into
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1316
		# a hash to re-factor code
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1317
		fileContentsToTest = { KIgnoreNothing           : inputFileLines,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1318
							   KIgnoreComments          : noCommentFileLines,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1319
							   KIgnoreQuotes            : noQuoteFileLines,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1320
							   KIgnoreCommentsAndQuotes : noCommentOrQuoteFileLines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1321
							   }
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1322
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1323
		# now apply test scripts to source file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1324
		iBraceCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1325
		iBraceCountList = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1326
		newCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1327
		newCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1328
		self.iCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1329
		self.iCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1330
		self.iCurrentMethodStart = -1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1331
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1332
		totalNumberOfLines = len(inputFileLines)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1333
		reConstant = re.compile(r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1334
			^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1335
			(static\s+)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1336
			const
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1337
			\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1338
			\w+		# type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1339
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1340
			[\*&]?	# reference or pointer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1341
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1342
			\w+		# name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1343
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1344
			(=|\()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1345
			""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1346
		reInheritance = re.compile("[\s:]*(public|protected|private)\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1347
		rePreprocessorIf = re.compile("^\s*\#(el)*if(.*)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1348
		rePreprocessorElse = re.compile("^\s*\#else")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1349
		rePreprocessorEnd = re.compile("^\s*\#endif")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1350
		reTypedef = re.compile("^\s*typedef")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1351
		i = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1352
		while (i < totalNumberOfLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1353
			# for extra open braces in #if blocks
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1354
			if (rePreprocessorIf.search(noCommentOrQuoteFileLines[i])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1355
				iBraceCountList.append(iBraceCount)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1356
			if (rePreprocessorElse.search(noCommentOrQuoteFileLines[i])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1357
				if (len(iBraceCountList) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1358
					iBraceCount = iBraceCountList.pop()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1359
			if (rePreprocessorEnd.search(noCommentOrQuoteFileLines[i])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1360
				if (len(iBraceCountList) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1361
					iBraceCountList.pop()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1362
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1363
			if (newCurrentMethodName == ""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1364
				methodString = noCommentOrQuoteFileLines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1365
				currentLine = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1366
				m = self.iReMethod.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1367
				if not m and (i + 1 < totalNumberOfLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1368
					currentLine = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1369
					methodString += noCommentOrQuoteFileLines[currentLine]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1370
					m = self.iReMethod.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1371
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1372
				if m and (iBraceCount == 0) and (methodString.find("#") == -1) and (methodString.find("_LIT") == -1):	# must be at root level and not a preprocessor directive or a _LIT
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1373
					if not reTypedef.match(methodString) and not reConstant.match(methodString):  # must not be typedef or constant declaration 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1374
						# check for cases where macros are used to declare a class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1375
						# by searching for the inheritance part
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1376
						# eg. NONSHARABLE_CLASS(CMyClass) : public CBase
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1377
						isClass = reInheritance.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1378
						if not isClass and (currentLine + 1 < totalNumberOfLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1379
							methodString += noCommentOrQuoteFileLines[currentLine + 1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1380
							isClass = reInheritance.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1381
						if not isClass:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1382
							newCurrentMethodName = m.group('method')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1383
							if m.group('class'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1384
								newCurrentClassName = m.group('class')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1385
							else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1386
								newCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1387
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1388
			iBraceCount += noCommentOrQuoteFileLines[i].count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1389
			if (iBraceCount > 0) and (newCurrentMethodName <> ""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1390
				self.iCurrentClassName = newCurrentClassName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1391
				self.iCurrentMethodName = newCurrentMethodName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1392
				self.iCurrentMethodStart = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1393
				newCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1394
				newCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1395
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1396
			self.iLineContext.iLineNumber = i+1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1397
			self.iLineContext.iClassName = self.iCurrentClassName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1398
			self.iLineContext.iMethodName = self.iCurrentMethodName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1399
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1400
			# perform all test scripts onto source file									   
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1401
			for script in self.iCategoriedScripts.AllScripts():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1402
				if (script.iFileExts.count(sourceFileExt) > 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1403
				    and fileContentsToTest[script.iIgnore][i] != "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1404
					and	script.iCompare(fileContentsToTest[script.iIgnore], i, script.iReMatch, aSourceFile)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1405
					# skip any script that has been disabled via CodeScanner command(s) in sources
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1406
					if script.iScriptName.lower() in csCommands[i].lower():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1407
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1408
					self.iLineContext.iLineText = fileContentsToTest[script.iIgnore][i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1409
					self.iComponentManager.ReportError(self.iLineContext, script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1410
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1411
			iBraceCount -= noCommentOrQuoteFileLines[i].count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1412
			if (iBraceCount < 0):	# for extra close braces in #if blocks
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1413
				iBraceCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1414
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1415
			if (iBraceCount == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1416
				self.iCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1417
				self.iCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1418
				self.iCurrentMethodStart = -1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1419
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1420
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1421
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1422
		self.iRendererManager.EndFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1423
		return totalNumberOfLines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1424
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1425
	def TraverseDirectory(self, aDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1426
		# skip folders marked to be excluded in configuration file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1427
		aPath = self.iComponentManager.SanitizePath(aDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1428
		if (not self.CheckSourceIncluded(aPath)) or (not self.CheckSourceIncluded(aPath + os.path.sep)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1429
			return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1430
		aDirectory = self.iComponentManager.BeginDirectory(aDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1431
		contents = os.listdir(aDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1432
		numberOfLinesScanned = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1433
		for entry in contents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1434
			entryPath = os.path.normpath(os.path.join(aDirectory, entry))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1435
			if os.path.isdir(entryPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1436
				self.TraverseDirectory(entryPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1437
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1438
				if self.CheckSourceIncluded(entryPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1439
					numberOfLinesScanned += self.ScanFile(entryPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1440
		self.iComponentManager.EndDirectory(aDirectory, numberOfLinesScanned)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1441
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1442
	def AddScript(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1443
		enabled = self.CheckScriptEnabled(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1444
		if enabled:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1445
			aScript.iCategory = self.UpdateScriptCategory(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1446
			aScript.iSeverity = self.UpdateScriptSeverity(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1447
			self.iCategoriedScripts.AddScript(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1448
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1449
			self.ReportInfo("Note: script '" + aScript.iScriptName + "' DISABLED")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1450
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1451
	def AddCustomScript(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1452
		self.ReportInfo("Note: custom rule '" + aScript.iScriptName + "' ADDED")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1453
		self.iCategoriedScripts.AddScript(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1454
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1455
	def PreParseSourceFile(self, aLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1456
		# it provides 3 versions of input:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1457
		# 	1. without quotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1458
		# 	2. without comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1459
		# 	3. without quotes and without comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1460
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1461
		inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1462
		noQuoteLines = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1463
		noCommentLines = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1464
		noCommentOrQuoteLines = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1465
		csCommands = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1466
		reCSCommand = re.compile("codescanner((::\w+)+)") # CodeScanner command(s) in comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1467
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1468
		for line in aLines:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1469
			noQuoteLine = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1470
			noCommentLine = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1471
			noCommentOrQuoteLine = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1472
			csCommand = "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1473
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1474
			i = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1475
			startQuote = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1476
			b = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1477
			escCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1478
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1479
			while i < len(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1480
				# skip quotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1481
				if not inCommentBlock and ((line[i] == "\"") or (line[i] == "\'")):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1482
					startQuote = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1483
					i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1484
					while (i < len(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1485
						endIndex = line[i:].find(line[startQuote])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1486
						if (endIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1487
							b = i + endIndex - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1488
							escCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1489
							while (line[b] == "\\"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1490
								escCount += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1491
								b -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1492
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1493
							i += endIndex + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1494
							if (escCount % 2 == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1495
								noQuoteLine += "\"\""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1496
								noCommentOrQuoteLine += "\"\""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1497
								noCommentLine += line[startQuote:i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1498
								break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1499
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1500
							#	print "Unterminated quote : " + line
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1501
							break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1502
					continue	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1503
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1504
				# parse comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1505
				if not inCommentBlock:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1506
					if (line[i] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1507
						if (i < (len(line)-1)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1508
							if (line[i + 1] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1509
								noCommentLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1510
								noCommentOrQuoteLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1511
								noQuoteLine += line[i:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1512
								# look for CodeScanner command(s) in comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1513
								m = reCSCommand.search(line[i:])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1514
								if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1515
									csCommand = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1516
								break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1517
							elif (line[i + 1] == "*"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1518
								inCommentBlock = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1519
								i += 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1520
								noQuoteLine += "/*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1521
								continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1522
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1523
					noCommentLine += line[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1524
					noCommentOrQuoteLine += line[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1525
					noQuoteLine += line[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1526
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1527
					# look for CodeScanner command(s) in comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1528
					m = reCSCommand.search(line[i:])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1529
					if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1530
						csCommand = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1531
					endIndex = line[i:].find("*/")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1532
					if (endIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1533
						inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1534
						noQuoteLine += line[i:i + endIndex + 2]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1535
						i += endIndex + 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1536
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1537
					else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1538
						noCommentLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1539
						noCommentOrQuoteLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1540
						noQuoteLine = line[i:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1541
						break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1542
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1543
				i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1544
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1545
			noCommentLines.append(noCommentLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1546
			noCommentOrQuoteLines.append(noCommentOrQuoteLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1547
			noQuoteLines.append(noQuoteLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1548
			csCommands.append(csCommand)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1549
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1550
		return [noQuoteLines, noCommentLines, noCommentOrQuoteLines, csCommands]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1551
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1552
	def ReadConfigFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1553
		if self.iConfigFilename <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1554
			if (os.path.isfile(self.iConfigFilename)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1555
				self.iDomConfig = xml.dom.minidom.parse(self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1556
				if self.iVerbose:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1557
					print "Note: using configuration file " + self.iConfigFilename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1558
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1559
				self.ReportInfo("Unable to open specified configuration file: " + self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1560
				self.iLog.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1561
				sys.exit(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1562
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1563
	def ReadArgumentsFromConfigFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1564
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1565
			for argumentsNode in self.iDomConfig.getElementsByTagName("arguments"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1566
				# read input file names
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1567
				for inputFileNode in argumentsNode.getElementsByTagName("input"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1568
					self.iInputFilenames += inputFileNode.firstChild.nodeValue + "::"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1569
				# read output format
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1570
				for outputFormatNode in argumentsNode.getElementsByTagName("outputformat"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1571
					self.iOutputFormat += outputFormatNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1572
				# read lxr URL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1573
				for lxrURLNode in argumentsNode.getElementsByTagName("lxr"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1574
					self.iLxrUrl = lxrURLNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1575
				# read lxr version
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1576
				for lxrVersionNode in argumentsNode.getElementsByTagName("lxrversion"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1577
					self.iLxrVersion = lxrVersionNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1578
				# read time stamped output option
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1579
				for timeStampedOutputNode in argumentsNode.getElementsByTagName("timestampedoutput"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1580
					self.iTimeStampedOutput = timeStampedOutputNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1581
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1582
	def ReadCustomRulesFromConfigFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1583
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1584
			for customRulesNode in self.iDomConfig.getElementsByTagName("customrules"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1585
				for customRuleNode in customRulesNode.getElementsByTagName("customrule"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1586
					ignoreComments = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1587
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1588
					# read the name of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1589
					ruleName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1590
					for ruleNameNode in customRuleNode.getElementsByTagName("name"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1591
						if (ruleNameNode == None) or (ruleNameNode.firstChild == None) or (ruleNameNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1592
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1593
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1594
							ruleName = ruleNameNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1595
					if len(ruleName) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1596
						self.ReportError("Missing custom rule name in configuration file: " + self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1597
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1598
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1599
					# read the keywords associated with the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1600
					keywordList = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1601
					badKeywordElement = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1602
					for keywordNode in customRuleNode.getElementsByTagName("keyword"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1603
						# read keyword content
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1604
						if (keywordNode == None) or (keywordNode.firstChild == None) or (keywordNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1605
							badKeywordElement = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1606
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1607
						newKeyword = CCustomRuleKeyword()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1608
						newKeyword.iContent = keywordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1609
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1610
						# read keyword type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1611
						if not keywordNode.hasAttribute("type"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1612
							badKeywordElement = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1613
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1614
						type = keywordNode.getAttribute("type").lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1615
						if type in KCustomRuleKeywordMap.values():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1616
							if type == KKeywordComment:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1617
								ignoreComments = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1618
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1619
							type = KCustomRuleKeywordMap[KKeywordUnknown]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1620
						newKeyword.iType = type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1621
						keywordList.append(newKeyword)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1622
					if (len(keywordList) == 0) or (badKeywordElement == True):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1623
						self.ReportBadCustomRuleElement(ruleName, "keyword")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1624
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1625
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1626
					# read the file types associated with the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1627
					fileTypeList = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1628
					badFileTypeElement = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1629
					for fileTypeNode in customRuleNode.getElementsByTagName("filetype"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1630
						if (fileTypeNode == None) or (fileTypeNode.firstChild == None) or (fileTypeNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1631
							badFileTypeElement = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1632
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1633
						newFileType = fileTypeNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1634
						fileTypeList.append(newFileType.lower())
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1635
					if (len(fileTypeList) == 0) or (badFileTypeElement == True):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1636
						self.ReportBadCustomRuleElement(ruleName, "file type")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1637
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1638
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1639
					# read the severity level of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1640
					severity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1641
					for severityNode in customRuleNode.getElementsByTagName("severity"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1642
						if (severityNode == None) or (severityNode.firstChild == None) or (severityNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1643
							self.ReportBadCustomRuleElement(ruleName, "severity")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1644
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1645
						severityValue = severityNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1646
						for severityKey in KSeverityConfigMap.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1647
							if severityValue == KSeverityConfigMap[severityKey]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1648
								severity = severityKey
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1649
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1650
					# read the tile of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1651
					title = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1652
					for titleNode in customRuleNode.getElementsByTagName("title"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1653
						if (titleNode == None) or (titleNode.firstChild == None) or (titleNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1654
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1655
						title = titleNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1656
					if len(title) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1657
						self.ReportBadCustomRuleElement(ruleName, "title")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1658
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1659
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1660
					# read the description of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1661
					description = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1662
					for descriptionNode in customRuleNode.getElementsByTagName("description"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1663
						if (descriptionNode == None) or (descriptionNode.firstChild == None) or (descriptionNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1664
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1665
						description = descriptionNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1666
					if len(description) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1667
						self.ReportBadCustomRuleElement(ruleName, "description")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1668
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1669
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1670
					# read the optional link of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1671
					link = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1672
					for linkNode in customRuleNode.getElementsByTagName("link"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1673
						if (linkNode == None) or (linkNode.firstChild == None) or (linkNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1674
							self.ReportBadCustomRuleElement(ruleName, "link")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1675
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1676
						link = linkNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1677
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1678
					# create the RE string for the custom rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1679
					keywordMap = self.ConstructCustomRuleKeywordMap(keywordList)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1680
					reString = self.ConstructCustomRuleREString(keywordMap)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1681
					if len(reString) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1682
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1683
					
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1684
					# create a script based on the custom rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1685
					aScript = CCustomScript(ruleName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1686
					aScript.iReString = reString
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1687
					aScript.iReMatch = re.compile(reString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1688
					aScript.iFileExts = fileTypeList
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1689
					aScript.iCategory = KCategoryOther
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1690
					if keywordMap.has_key(KKeywordBaseClass):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1691
						aScript.iBaseClass = keywordMap[KKeywordBaseClass]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1692
						aScript.iCompare = aScript.DefaultInheritanceCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1693
					if ignoreComments:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1694
						aScript.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1695
					else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1696
						aScript.iIgnore = KIgnoreQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1697
					aScript.iSeverity = severity
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1698
					aScript.iTitle = title
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1699
					aScript.iIdeTitle = title
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1700
					aScript.iDescription = description
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1701
					if link <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1702
						aScript.iLink = link
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1703
					self.AddCustomScript(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1704
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1705
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1706
	def ReportBadCustomRuleElement(self, name, element):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1707
		self.ReportError("<customrule> element '" + name + "' has bad <" + element + "> child element in configuration file: " + self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1708
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1709
	def ConstructCustomRuleKeywordMap(self, keywordList):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1710
		reString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1711
		keywordMap = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1712
		for keyword in keywordList:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1713
			if keywordMap.has_key(keyword.iType):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1714
				keywordMap[keyword.iType] = keywordMap[keyword.iType] + "|" + keyword.iContent
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1715
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1716
				keywordMap[keyword.iType] = keyword.iContent
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1717
		return keywordMap
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1718
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1719
	def ConstructCustomRuleREString(self, keywordMap):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1720
		# generate RE string based on the keyword types
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1721
		if keywordMap.has_key(KKeywordBaseClass):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1722
			reString = "^\s*class\s+(\w+::)?(\w+)\s*:(.*)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1723
		elif keywordMap.has_key(KKeywordCall):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1724
			reString = "(" + keywordMap[KKeywordCall] + ")\s*\(.*\)\s*;"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1725
		elif keywordMap.has_key(KKeywordClassName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1726
			if keywordMap.has_key(KKeywordMethod):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1727
				reString = "([A-Za-z0-9]+\s+" + keywordMap[KKeywordClassName] + "::)?(" + keywordMap[KKeywordMethod] + ")\s*\(.*\)\s*[^;]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1728
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1729
				reString = "^\s*class\s+(\w+::)?(" + keywordMap[KKeywordClassName] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1730
		elif keywordMap.has_key(KKeywordComment):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1731
			reString = "/(/|\*).*(" + keywordMap[KKeywordComment] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1732
		elif keywordMap.has_key(KKeywordGeneric):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1733
			reString = "(" + keywordMap[KKeywordGeneric] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1734
		elif keywordMap.has_key(KKeywordLocal):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1735
			reString = "^\s*[A-Z]\w*\s*[\*&\s]\s*(" + keywordMap[KKeywordLocal] + ")\w*\s*[;\(=]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1736
		elif keywordMap.has_key(KKeywordMacro):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1737
			reString = "^\s*\#define\s+(" + keywordMap[KKeywordMacro] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1738
		elif keywordMap.has_key(KKeywordMember):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1739
			reString = "^\s*[A-Z]\w*\s*[\*&\s]\s*(" + keywordMap[KKeywordMember] + ")\w*\s*[;\(=]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1740
		elif keywordMap.has_key(KKeywordMethod):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1741
			reString = "[A-Za-z0-9]+\s+[C|T|R][A-Za-z0-9]+::(" + keywordMap[KKeywordMethod] + ")\s*\(.*\)\s*[^;]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1742
		elif keywordMap.has_key(KKeywordParameter):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1743
			reString = "({)*\s*(" + keywordMap[KKeywordParameter] + ")\s*=\s*(.*);"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1744
		return reString
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1745
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1746
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1747
class CCustomRuleKeyword:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1748
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1749
	# CCustomRuleKeyword - keyword associated with custom rules
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1750
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1751
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1752
		iContent = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1753
		iType = "unknown"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1754
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1755
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1756
# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1757
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1758
class CEncodedFile:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1759
    def Extract(self, aBaseDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1760
        outputFileHandle = open(os.path.join(aBaseDirectory, self.iFilename), 'wb')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1761
        outputFileBinary = zlib.decompress(base64.decodestring(self.iFileBody))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1762
        outputFileHandle.write(outputFileBinary)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1763
        outputFileHandle.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1764
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1765
	iFilename = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1766
	iFileBody = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1767
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1768
# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1769
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1770
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1771
class CEncodedFileList:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1772
	def AddEncodedFile(self, aEncodedFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1773
		self.iEncodedFileList[aEncodedFile.iFilename.lower()] = aEncodedFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1774
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1775
	def ExtractEncodedFile(self, aFilename, aBaseDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1776
		# look for the filename in our list of files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1777
		filename = aFilename.lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1778
		if (self.iEncodedFileList.has_key(filename)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1779
			self.iEncodedFileList[filename].Extract(aBaseDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1780
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1781
			scanner.iLog.Write("Missing "+filename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1782
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1783
	def ExtractAllEncodedFiles(self, aBaseDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1784
		# run through associative array and extract everything
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1785
		for filename in self.iEncodedFileList.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1786
			self.ExtractEncodedFile(filename, aBaseDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1787
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1788
	# declare iEncodedFileList is an associative array
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1789
	iEncodedFileList = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1790
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1791
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1792
# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1793
# main()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1794
scanner = CCodeScanner()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1795
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1796
# process command line arguments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1797
opts, args = getopt.getopt(sys.argv[1:], "hvc:i:l:o:x:r:t:", ["help", "verbose", "config=", "input=", "logfile=", "outputformat=", "lxr=", "lxrversion=", "timestampedoutput="])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1798
for o, a in opts:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1799
	if o in ("-h", "--help"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1800
		Usage(0)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1801
	if o in ("-v", "--verbose"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1802
		scanner.iVerbose = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1803
	if o in ("-c", "--config"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1804
		scanner.iConfigFilename = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1805
	if o in ("-i", "--input"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1806
		scanner.iInputFilenames += a + "::"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1807
	if o in ("-l", "--logfile"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1808
		scanner.iLogFilename = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1809
	if o in ("-o", "--outputformat"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1810
		scanner.iOutputFormat += a			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1811
	if o in ("-x", "--lxr"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1812
		scanner.iLxrUrl = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1813
	if o in ("-r", "--lxrversion"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1814
		scanner.iLxrVersion = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1815
	if o in ("-t", "--timestampedoutput"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1816
		scanner.iTimeStampedOutput = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1817
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1818
if len(args) < 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1819
	Usage(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1820
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1821
scanner.iLog = CLogger(scanner.iLogFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1822
scanner.iLog.Write("Command line: " + str(sys.argv[1:]))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1823
scanner.iLog.Write("Current working directory: " + os.getcwd())
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1824
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1825
scanner.ReadConfigFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1826
scanner.ReadArgumentsFromConfigFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1827
scanner.ReadCustomRulesFromConfigFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1828
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1829
scanner.iSource = args[0]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1830
scanner.iEncodedFileList = CEncodedFileList()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1831
scanner.iStartTimeObj = datetime.datetime.now()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1832
scanner.iStartTime = scanner.iStartTimeObj.ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1833
scanner.iOutputDirectory = scanner.iStartTimeObj.strftime("%a-%b-%d-%H-%M-%S-%Y")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1834
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1835
# invoke the pysco module to improve performance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1836
psyco.full()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1837
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1838
# choose renderer based on command line arguments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1839
if len(args) > 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1840
	if ("off" in scanner.iTimeStampedOutput.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1841
		scanner.iOutputDirectory = args[1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1842
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1843
		scanner.iOutputDirectory = os.path.normpath(os.path.join(args[1], scanner.iOutputDirectory))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1844
	scanner.CleanOutputDirectory()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1845
	if scanner.iOutputFormat <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1846
	#user specified output format
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1847
		if ("xml" in scanner.iOutputFormat.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1848
			CXmlRenderer(scanner.iRendererManager, scanner.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1849
		if ("html" in scanner.iOutputFormat.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1850
			CHtmlRenderer(scanner.iRendererManager, scanner.iOutputDirectory, scanner.iLxrUrl, scanner.iLxrVersion)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1851
		if ("std" in scanner.iOutputFormat.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1852
			CStdOutRenderer(scanner.iRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1853
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1854
	#default output format
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1855
		CHtmlRenderer(scanner.iRendererManager, scanner.iOutputDirectory, scanner.iLxrUrl, scanner.iLxrVersion)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1856
else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1857
	CStdOutRenderer(scanner.iRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1858
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1859
#!PARSE
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1860
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1861
if (scanner.iVerbose):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1862
	scanner.iCategoriedScripts.PrintListOfTestScripts()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1863
	scanner.iRendererManager.PrintListOfRenderers()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1864
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1865
print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1866
print "Scanning inititated : " + scanner.iStartTime
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1867
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1868
if scanner.iInputFilenames <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1869
	scanner.iComponentManager.iUseFullComponentPath = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1870
	#additional input files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1871
	inputFiles = scanner.iInputFilenames.split("::")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1872
	for inputFile in inputFiles:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1873
		if inputFile <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1874
			ScanDirOrFile(inputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1875
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1876
argument = args[0]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1877
ScanDirOrFile(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1878
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1879
print "Scanning finished   : " + scanner.iEndTime
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1880
scanner.iLog.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1881
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1882
if (scanner.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1883
	scanner.iDomConfig.unlink()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1884
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1885
sys.exit(0)