lintian.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/python
  2. """ 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. """
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. ################################################################################
  20. # <mhy> I often wonder if we should use NSA bot or something instead and get dinstall
  21. # to send emails telling us about its progress :-)
  22. # <mhy> dinstall: I'm processing openoffice
  23. # <mhy> dinstall: I'm choking, please help me
  24. # <Ganneff> yeah. get floods in here, for 600 accepted packages.
  25. # <mhy> hehe
  26. # <Ganneff> im not sure the other opers will like it if i oper up the bot, just so it
  27. # can flood faster
  28. # <mhy> flood all debian related channels
  29. # <mhy> just to be safe
  30. # <Ganneff> /msg #debian-* dinstall: starting
  31. # <Ganneff> more interesting would be the first message in #debian, the next in
  32. # #d-devel, then #d-qa
  33. # <Ganneff> and expect people to monitor all.
  34. # <Ganneff> i bet we have enough debian channels to at least put the timestamps in
  35. # seperate channels each
  36. # <Ganneff> and if not - we can make it go multi-network
  37. # <Ganneff> first oftc, then opn, then ircnet, then - we will find some. quakenet anyone?
  38. # <mhy> I should know better than to give you ideas
  39. ################################################################################
  40. from __future__ import absolute_import, print_function
  41. from .regexes import re_parse_lintian
  42. def parse_lintian_output(output):
  43. """
  44. Parses Lintian output and returns a generator with the data.
  45. >>> list(parse_lintian_output('W: pkgname: some-tag path/to/file'))
  46. [('W', 'pkgname', 'some-tag', 'path/to/file')]
  47. @type output: string
  48. @param output: The output from lintian
  49. """
  50. for line in output.split('\n'):
  51. m = re_parse_lintian.match(line)
  52. if m:
  53. yield m.groupdict()
  54. def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args):
  55. """
  56. Generates package reject messages by comparing parsed lintian output with
  57. tag definitions. Returns a generator containing the reject messages.
  58. @param parsed_tags: Parsed lintian tags as returned by L{parse_lintian_output}
  59. @param tag_definitions: YAML.load lintian tag definitions to reject on
  60. @return: Reject message(s), if any
  61. """
  62. tags = set()
  63. for values in tag_definitions.values():
  64. for tag_name in values:
  65. tags.add(tag_name)
  66. for tag in parsed_tags:
  67. tag_name = tag['tag']
  68. if tag_name not in tags:
  69. continue
  70. # Was tag overridden?
  71. if tag['level'] == 'O':
  72. if tag_name in tag_definitions['nonfatal']:
  73. # Overriding this tag is allowed.
  74. pass
  75. elif tag_name in tag_definitions['fatal']:
  76. # Overriding this tag is NOT allowed.
  77. log('ftpmaster does not allow tag to be overridable', tag_name)
  78. yield "%(package)s: Overriden tag %(tag)s found, but this " \
  79. "tag may not be overridden." % tag
  80. else:
  81. # Tag is known and not overridden; reject
  82. yield "%(package)s: lintian output: '%(tag)s %(description)s', " \
  83. "automatically rejected package." % tag
  84. # Now tell if they *might* override it.
  85. if tag_name in tag_definitions['nonfatal']:
  86. log("auto rejecting", "overridable", tag_name)
  87. yield "%(package)s: If you have a good reason, you may " \
  88. "override this lintian tag." % tag
  89. else:
  90. log("auto rejecting", "not overridable", tag_name)