lintian.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 regexes import re_parse_lintian
  41. def parse_lintian_output(output):
  42. """
  43. Parses Lintian output and returns a generator with the data.
  44. >>> list(parse_lintian_output('W: pkgname: some-tag path/to/file'))
  45. [('W', 'pkgname', 'some-tag', 'path/to/file')]
  46. @type output: string
  47. @param output: The output from lintian
  48. """
  49. for line in output.split('\n'):
  50. m = re_parse_lintian.match(line)
  51. if m:
  52. yield m.groupdict()
  53. def generate_reject_messages(parsed_tags, tag_definitions, log=lambda *args: args):
  54. """
  55. Generates package reject messages by comparing parsed lintian output with
  56. tag definitions. Returns a generator containing the reject messages.
  57. @param parsed_tags: Parsed lintian tags as returned by L{parse_lintian_output}
  58. @param tag_definitions: YAML.load lintian tag definitions to reject on
  59. @return: Reject message(s), if any
  60. """
  61. tags = set()
  62. for values in tag_definitions.values():
  63. for tag_name in values:
  64. tags.add(tag_name)
  65. for tag in parsed_tags:
  66. tag_name = tag['tag']
  67. if tag_name not in tags:
  68. continue
  69. # Was tag overridden?
  70. if tag['level'] == 'O':
  71. if tag_name in tag_definitions['nonfatal']:
  72. # Overriding this tag is allowed.
  73. pass
  74. elif tag_name in tag_definitions['fatal']:
  75. # Overriding this tag is NOT allowed.
  76. log('ftpmaster does not allow tag to be overridable', tag_name)
  77. yield "%(package)s: Overriden tag %(tag)s found, but this " \
  78. "tag may not be overridden." % tag
  79. else:
  80. # Tag is known and not overridden; reject
  81. yield "%(package)s: lintian output: '%(tag)s %(description)s', " \
  82. "automatically rejected package." % tag
  83. # Now tell if they *might* override it.
  84. if tag_name in tag_definitions['nonfatal']:
  85. log("auto rejecting", "overridable", tag_name)
  86. yield "%(package)s: If you have a good reason, you may " \
  87. "override this lintian tag." % tag
  88. else:
  89. log("auto rejecting", "not overridable", tag_name)