1999-10-24 02:27:11 +08:00
|
|
|
#############################################################################
|
2005-11-28 05:49:15 +08:00
|
|
|
# File : Filter.py
|
|
|
|
# Package : rpmlint
|
|
|
|
# Author : Frederic Lepied
|
|
|
|
# Created on : Sat Oct 23 15:52:27 1999
|
|
|
|
# Version : $Id$
|
|
|
|
# Purpose : filter the output of rpmlint to allow exceptions.
|
1999-10-24 02:27:11 +08:00
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
import sys
|
2008-10-30 04:40:29 +08:00
|
|
|
import textwrap
|
1999-10-24 02:27:11 +08:00
|
|
|
import Config
|
2006-07-05 22:53:19 +08:00
|
|
|
import Testing
|
1999-10-24 02:27:11 +08:00
|
|
|
|
2008-04-30 05:28:27 +08:00
|
|
|
_diagnostic = list()
|
|
|
|
_badness_score = 0
|
2008-04-30 04:22:55 +08:00
|
|
|
printed_messages = { "I": 0, "W": 0, "E": 0 }
|
|
|
|
|
1999-11-16 02:33:35 +08:00
|
|
|
def printInfo(pkg, reason, *details):
|
2008-04-30 05:28:27 +08:00
|
|
|
_print("I", pkg, reason, details)
|
2005-11-28 05:49:15 +08:00
|
|
|
|
1999-10-24 02:27:11 +08:00
|
|
|
def printWarning(pkg, reason, *details):
|
2008-04-30 05:28:27 +08:00
|
|
|
_print("W", pkg, reason, details)
|
1999-10-24 02:27:11 +08:00
|
|
|
|
|
|
|
def printError(pkg, reason, *details):
|
2008-04-30 05:28:27 +08:00
|
|
|
_print("E", pkg, reason, details)
|
1999-10-24 02:27:11 +08:00
|
|
|
|
|
|
|
def _print(type, pkg, reason, details):
|
2008-04-30 05:28:27 +08:00
|
|
|
global printed_messages, _badness_score, _diagnostics
|
|
|
|
|
|
|
|
threshold = badnessThreshold()
|
|
|
|
|
|
|
|
badness = 0
|
|
|
|
if threshold >= 0:
|
|
|
|
badness = Config.badness(reason)
|
|
|
|
type = badness and "E" or "W"
|
|
|
|
|
2007-05-15 06:02:01 +08:00
|
|
|
ln = ""
|
|
|
|
if pkg.current_linenum is not None:
|
|
|
|
ln = "%s:" % pkg.current_linenum
|
|
|
|
arch = ""
|
|
|
|
if pkg.arch is not None:
|
|
|
|
arch = ".%s" % pkg.arch
|
|
|
|
s = "%s%s:%s %s: %s" % (pkg.name, arch, ln, type, reason)
|
2008-04-30 05:28:27 +08:00
|
|
|
if badness:
|
|
|
|
s = s + " (Badness: %d)" % badness
|
1999-11-16 02:33:35 +08:00
|
|
|
for d in details:
|
2005-11-28 05:49:15 +08:00
|
|
|
s = s + " %s" % d
|
2006-07-05 22:53:19 +08:00
|
|
|
if Testing.isTest():
|
|
|
|
Testing.addOutput(s)
|
|
|
|
else:
|
|
|
|
if not Config.isFiltered(s):
|
2008-04-30 05:28:27 +08:00
|
|
|
printed_messages[type] += 1
|
|
|
|
_badness_score += badness
|
|
|
|
if threshold >= 0:
|
|
|
|
_diagnostic.append(s + "\n")
|
|
|
|
else:
|
|
|
|
sys.stdout.write(s)
|
|
|
|
sys.stdout.write("\n")
|
|
|
|
printDescriptions(reason)
|
2006-07-05 22:53:19 +08:00
|
|
|
return 1
|
2001-07-16 00:52:55 +08:00
|
|
|
|
|
|
|
return 0
|
1999-10-24 02:27:11 +08:00
|
|
|
|
2001-06-20 19:36:00 +08:00
|
|
|
def printDescriptions(reason):
|
2001-05-26 06:17:48 +08:00
|
|
|
try:
|
2001-06-20 19:36:00 +08:00
|
|
|
d = _details[reason]
|
|
|
|
if d and d != '' and d != "\n":
|
2008-10-30 04:40:29 +08:00
|
|
|
sys.stdout.write(textwrap.fill(d, 78))
|
2001-06-20 19:36:00 +08:00
|
|
|
sys.stdout.write("\n\n")
|
2001-05-26 06:17:48 +08:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2005-11-28 05:49:15 +08:00
|
|
|
|
2008-04-30 05:28:27 +08:00
|
|
|
def _diag_compare(x,y):
|
|
|
|
|
|
|
|
where_a = x.split()[1]
|
|
|
|
level_a = x.split()[2]
|
|
|
|
|
|
|
|
where_b = y.split()[1]
|
|
|
|
level_b = y.split()[2]
|
|
|
|
|
|
|
|
if level_b > level_a:
|
|
|
|
return 1
|
|
|
|
elif level_b == level_a:
|
|
|
|
if where_b > where_b:
|
|
|
|
return 1
|
|
|
|
elif where_b == where_a:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
|
|
def printAllReasons():
|
|
|
|
threshold = badnessThreshold()
|
|
|
|
if threshold < 0:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
global _badness_score, _diagnostic
|
|
|
|
_diagnostic.sort(_diag_compare)
|
|
|
|
last_reason=''
|
|
|
|
for diag in _diagnostic:
|
|
|
|
if Config.info:
|
|
|
|
reason = diag.split()[2]
|
|
|
|
if reason != last_reason:
|
|
|
|
if len(last_reason):
|
|
|
|
printDescriptions(last_reason)
|
|
|
|
last_reason=reason
|
|
|
|
sys.stdout.write(diag)
|
|
|
|
if Config.info and len(last_reason):
|
|
|
|
printDescriptions(last_reason)
|
|
|
|
_diagnostic = list()
|
|
|
|
return _badness_score > threshold
|
|
|
|
|
|
|
|
|
2001-05-26 06:17:48 +08:00
|
|
|
_details={}
|
|
|
|
|
|
|
|
def addDetails(*details):
|
|
|
|
for idx in range(len(details)/2):
|
|
|
|
_details[details[idx*2]]=details[idx*2+1]
|
2005-11-28 05:49:15 +08:00
|
|
|
|
2008-04-30 05:28:27 +08:00
|
|
|
def badnessScore():
|
|
|
|
global _badness_score
|
|
|
|
return _badness_score
|
|
|
|
|
|
|
|
def badnessThreshold():
|
|
|
|
return Config.getOption("BadnessThreshold", -1)
|
|
|
|
|
1999-10-24 02:27:11 +08:00
|
|
|
# Filter.py ends here
|
2006-04-01 16:09:17 +08:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# py-indent-offset: 4
|
|
|
|
# End:
|
|
|
|
# ex: ts=4 sw=4 et
|