1 # -*- coding: utf-8 -*-
2 #############################################################################
5 # Author : Frederic Lepied
6 # Created on : Sat Oct 23 15:52:27 1999
7 # Version : $Id: Filter.py 1871 2011-06-18 09:40:52Z scop $
8 # Purpose : filter the output of rpmlint to allow exceptions.
9 #############################################################################
25 printed_messages = { "I": 0, "W": 0, "E": 0 }
30 def printInfo(pkg, reason, *details):
31 _print("I", pkg, reason, details)
33 def printWarning(pkg, reason, *details):
34 _print("W", pkg, reason, details)
36 def printError(pkg, reason, *details):
37 _print("E", pkg, reason, details)
39 def _print(msgtype, pkg, reason, details):
42 threshold = badnessThreshold()
46 badness = Config.badness(reason)
47 # anything with badness is an error
50 # errors without badness become warnings
55 if pkg.current_linenum is not None:
56 ln = "%s:" % pkg.current_linenum
58 if pkg.arch is not None:
59 arch = ".%s" % pkg.arch
60 s = "%s%s:%s %s: %s" % (pkg.name, arch, ln, msgtype, reason)
62 s = s + " (Badness: %d)" % badness
65 if Testing and Testing.isTest():
69 print >>_rawout, s.encode(locale.getpreferredencoding(), "replace")
70 if not Config.isFiltered(s):
71 printed_messages[msgtype] += 1
72 _badness_score += badness
74 _diagnostic.append(s + "\n")
78 printDescriptions(reason)
83 def printDescriptions(reason):
86 if d and d != '' and d != "\n":
87 __print(textwrap.fill(d, 78))
96 def printAllReasons():
97 threshold = badnessThreshold()
102 _diagnostic.sort(key = _diag_sortkey, reverse = True)
104 for diag in _diagnostic:
106 reason = diag.split()[2]
107 if reason != last_reason:
109 printDescriptions(last_reason)
112 if Config.info and len(last_reason):
113 printDescriptions(last_reason)
115 return _badness_score > threshold
120 def addDetails(*details):
121 for idx in range(len(details)/2):
122 if not details[idx*2] in _details:
123 _details[details[idx*2]] = details[idx*2+1]
126 return _badness_score
128 def badnessThreshold():
129 return Config.getOption("BadnessThreshold", -1)
135 _rawout = open(file, "w")
137 # Filter.py ends here
140 # indent-tabs-mode: nil
141 # py-indent-offset: 4