1"""Utility functions for lintian checks in dak
3@contact: Debian FTPMaster <ftpmaster@debian.org>
4@copyright: 2009, 2010 Joerg Jaspert <joerg@debian.org>
5@copyright: 2009 Chris Lamb <lamby@debian.org>
6@license: GNU General Public License version 2 or later
7"""
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23################################################################################
25# <mhy> I often wonder if we should use NSA bot or something instead and get dinstall
26# to send emails telling us about its progress :-)
27# <mhy> dinstall: I'm processing openoffice
28# <mhy> dinstall: I'm choking, please help me
29# <Ganneff> yeah. get floods in here, for 600 accepted packages.
30# <mhy> hehe
31# <Ganneff> im not sure the other opers will like it if i oper up the bot, just so it
32# can flood faster
33# <mhy> flood all debian related channels
34# <mhy> just to be safe
35# <Ganneff> /msg #debian-* dinstall: starting
36# <Ganneff> more interesting would be the first message in #debian, the next in
37# #d-devel, then #d-qa
38# <Ganneff> and expect people to monitor all.
39# <Ganneff> i bet we have enough debian channels to at least put the timestamps in
40# seperate channels each
41# <Ganneff> and if not - we can make it go multi-network
42# <Ganneff> first oftc, then opn, then ircnet, then - we will find some. quakenet anyone?
43# <mhy> I should know better than to give you ideas
45################################################################################
47from collections.abc import Iterable
49from .regexes import re_parse_lintian
52def parse_lintian_output(output: str) -> Iterable[dict]:
53 """
54 Parses Lintian output and returns a generator with the data.
56 >>> list(parse_lintian_output('W: pkgname: some-tag path/to/file'))
57 [('W', 'pkgname', 'some-tag', 'path/to/file')]
59 :param output: The output from lintian
60 """
62 return (
63 m.groupdict()
64 for line in output.split("\n")
65 if (m := re_parse_lintian.match(line))
66 )
69def generate_reject_messages(
70 parsed_tags, tag_definitions, log=lambda *args: args
71) -> Iterable[str]:
72 """
73 Generates package reject messages by comparing parsed lintian output with
74 tag definitions. Returns a generator containing the reject messages.
76 :param parsed_tags: Parsed lintian tags as returned by :func:`parse_lintian_output`
77 :param tag_definitions: YAML.load lintian tag definitions to reject on
79 :return: Reject message(s), if any
80 """
82 tags = set()
83 for values in tag_definitions.values():
84 for tag_name in values:
85 tags.add(tag_name)
87 for tag in parsed_tags:
88 tag_name = tag["tag"]
90 if tag_name not in tags:
91 continue
93 # Was tag overridden?
94 if tag["level"] == "O":
96 if tag_name in tag_definitions["nonfatal"]:
97 # Overriding this tag is allowed.
98 pass
100 elif tag_name in tag_definitions["fatal"]: 100 ↛ 87line 100 didn't jump to line 87, because the condition on line 100 was never false
101 # Overriding this tag is NOT allowed.
103 log("ftpmaster does not allow tag to be overridable", tag_name)
104 yield "%(package)s: Overriden tag %(tag)s found, but this " "tag may not be overridden." % tag
106 else:
107 # Tag is known and not overridden; reject
108 yield "%(package)s: lintian output: '%(tag)s %(description)s', " "automatically rejected package." % tag
110 # Now tell if they *might* override it.
111 if tag_name in tag_definitions["nonfatal"]:
112 log("auto rejecting", "overridable", tag_name)
113 yield "%(package)s: If you have a good reason, you may " "override this lintian tag." % tag
114 else:
115 log("auto rejecting", "not overridable", tag_name)