1""" Utility functions for lintian checks in dak 

2 

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""" 

8 

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. 

13 

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. 

18 

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 

22 

23################################################################################ 

24 

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 

44 

45################################################################################ 

46 

47from collections.abc import Iterable 

48 

49from .regexes import re_parse_lintian 

50 

51 

52def parse_lintian_output(output: str) -> Iterable[dict]: 

53 """ 

54 Parses Lintian output and returns a generator with the data. 

55 

56 >>> list(parse_lintian_output('W: pkgname: some-tag path/to/file')) 

57 [('W', 'pkgname', 'some-tag', 'path/to/file')] 

58 

59 :param output: The output from lintian 

60 """ 

61 

62 return ( 

63 m.groupdict() 

64 for line in output.split('\n') 

65 if (m := re_parse_lintian.match(line)) 

66 ) 

67 

68 

69def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args) -> Iterable[str]: 

70 """ 

71 Generates package reject messages by comparing parsed lintian output with 

72 tag definitions. Returns a generator containing the reject messages. 

73 

74 :param parsed_tags: Parsed lintian tags as returned by :func:`parse_lintian_output` 

75 :param tag_definitions: YAML.load lintian tag definitions to reject on 

76 

77 :return: Reject message(s), if any 

78 """ 

79 

80 tags = set() 

81 for values in tag_definitions.values(): 

82 for tag_name in values: 

83 tags.add(tag_name) 

84 

85 for tag in parsed_tags: 

86 tag_name = tag['tag'] 

87 

88 if tag_name not in tags: 

89 continue 

90 

91 # Was tag overridden? 

92 if tag['level'] == 'O': 

93 

94 if tag_name in tag_definitions['nonfatal']: 

95 # Overriding this tag is allowed. 

96 pass 

97 

98 elif tag_name in tag_definitions['fatal']: 98 ↛ 85line 98 didn't jump to line 85, because the condition on line 98 was never false

99 # Overriding this tag is NOT allowed. 

100 

101 log('ftpmaster does not allow tag to be overridable', tag_name) 

102 yield "%(package)s: Overriden tag %(tag)s found, but this " \ 

103 "tag may not be overridden." % tag 

104 

105 else: 

106 # Tag is known and not overridden; reject 

107 yield "%(package)s: lintian output: '%(tag)s %(description)s', " \ 

108 "automatically rejected package." % tag 

109 

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 " \ 

114 "override this lintian tag." % tag 

115 else: 

116 log("auto rejecting", "not overridable", tag_name)