--- Config.py +++ Config.py @@ -126,6 +126,17 @@ else: _filters_re = None +_scoring={} + +def setBadness(s, score): + _scoring[s] = score + setOption('UseBadness', True) + +def badness(s): + if _scoring.has_key(s): + return _scoring[s] + return 0 + _non_named_group_re = re.compile('[^\\](\()[^:]') def isFiltered(s): global _filters --- Filter.py +++ Filter.py @@ -11,19 +11,27 @@ import Config import Testing +_badness_score = 0 +_diagnostic = list() + def printInfo(pkg, reason, *details): - if _print("I", pkg, reason, details) and Config.info: - printDescriptions(reason) + _print("I", pkg, reason, details) def printWarning(pkg, reason, *details): - if _print("W", pkg, reason, details) and Config.info: - printDescriptions(reason) + _print("W", pkg, reason, details) def printError(pkg, reason, *details): - if _print("E", pkg, reason, details) and Config.info: - printDescriptions(reason) + _print("E", pkg, reason, details) def _print(type, pkg, reason, details): + global _badness_score, _diagnostic + + badness = Config.badness(reason) + if Config.getOption('UseBadness'): + type = "W" + if badness: + type = "E" + ln = "" if pkg.current_linenum is not None: ln = "%s:" % pkg.current_linenum @@ -31,14 +39,16 @@ if pkg.arch is not None: arch = ".%s" % pkg.arch s = "%s%s:%s %s: %s" % (pkg.name, arch, ln, type, reason) + if badness: + s = s + " (Badness: %d)" % badness for d in details: s = s + " %s" % d if Testing.isTest(): Testing.addOutput(s) else: if not Config.isFiltered(s): - sys.stdout.write(s) - sys.stdout.write("\n") + _diagnostic.append(s + "\n") + _badness_score += badness return 1 return 0 @@ -52,12 +62,56 @@ except KeyError: pass +def _diag_compare(x,y): + + where_a = x.split()[2] + level_a = x.split()[1] + + where_b = y.split()[2] + level_b = y.split()[1] + + if (level_b > level_a): + return 1 + + if (level_b < level_a): + return -1 + + if (where_b < where_a): + return 1 + + if (where_b > where_a): + return -1 + + return 0 + +def printAllReasons(): + 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 > 1000 + _details={} def addDetails(*details): for idx in range(len(details)/2): _details[details[idx*2]]=details[idx*2+1] +def BadnessScore(): + global _badness_score + + return _badness_score + # Filter.py ends here # Local variables: --- README +++ README @@ -79,6 +79,7 @@ FilesCheck.py SystemLibPaths list of strings ('/lib', '/usr/lib', '/usr/X11R6/lib') UseBzip2 boolean 1 +UseBadness boolean 0 UseDefaultRunlevels boolean 1 UseEpoch boolean 0 UseIndexedJars boolean 1 --- rpmlint.py +++ rpmlint.py @@ -146,6 +146,10 @@ sys.stderr.write('Interrupted, exiting while scanning all packages\n') sys.exit(2) + if printAllReasons(): + sys.stdout.write('RPMLINT: E: BADNESS is %d - threshold exceeded. aborting the build.\n' % BadnessScore() ) + sys.exit(1) + finally: pkg and pkg.cleanup()