/[collab-qa]/udd/udd/lintian_gatherer.py
ViewVC logotype

Contents of /udd/udd/lintian_gatherer.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1534 - (show annotations) (download) (as text)
Fri Jul 24 10:33:27 2009 UTC (3 years, 9 months ago) by lucas
File MIME type: text/x-python
File size: 2391 byte(s)
add information column in lintian table
1 #!/usr/bin/env python
2
3 """
4 This script imports lintian run results into the database
5 See lintian.debian.org
6 """
7
8 from aux import quote
9 from gatherer import gatherer
10 import re
11
12 def get_gatherer(connection, config, source):
13 return lintian_gatherer(connection, config, source)
14
15 class lintian_gatherer(gatherer):
16 #RE to parse lintian output, pushing the tag code to $1, package name
17 #to $2, pkg type to $3, tag name to $4 and extra info to $5
18 # (stolen from Russ Allbery, thanks dude)
19 output_re = re.compile("([EWIXOP]): (\S+)(?: (\S+))?: (\S+)(?:\s+(.*))?");
20
21 ignore_re = re.compile("^((gpg|secmem usage|warning|(/bin/)?tar|internal error|/usr/bin/xgettext|ERROR): | |Use of uninitialized value in numeric lt .*)");
22
23 code_to_tag_type_map = {
24 "E": "error",
25 "W": "warning",
26 "I": "information",
27 "X": "experimental",
28 "O": "overriden",
29 "P": "pedantic",
30 }
31
32 def __init__(self, connection, config, source):
33 gatherer.__init__(self, connection, config, source)
34 self.assert_my_config('path', 'table')
35
36 def run(self):
37 my_config = self.my_config
38
39 #start harassing the DB, preparing the final inserts and making place
40 #for the new data:
41 cur = self.cursor()
42
43 cur.execute("DELETE FROM %s" % my_config["table"])
44
45 cur.execute("""PREPARE lintian_insert
46 AS INSERT INTO %s (package, package_type, tag, tag_type, information)
47 VALUES ($1, $2, $3, $4, $5)""" % (my_config['table']))
48
49 lintian_data = open(my_config['path'])
50 line_number = 0
51 for line in lintian_data:
52 line_number += 1
53
54 #ignore information and verbose output:
55 if line.startswith("N:"):
56 continue
57
58 match = lintian_gatherer.output_re.match(line)
59 if match:
60 (code, pkg, pkg_type, tag, extra) = match.groups();
61 #this one is optional:
62 if pkg_type:
63 pkg_type = quote(pkg_type)
64 else:
65 pkg_type = 'NULL'
66
67 cur.execute("EXECUTE lintian_insert (%s, %s, %s, %s, %s)"\
68 % (quote(pkg), pkg_type, quote(tag), quote(lintian_gatherer.code_to_tag_type_map[code]), quote(extra)));
69 elif not lintian_gatherer.ignore_re.match(line):
70 print "Can't parse line %d: %s" % (line_number, line.rstrip())
71
72 cur.execute("DEALLOCATE lintian_insert")
73 cur.execute("ANALYZE %s" % my_config["table"])
74
75 if __name__ == '__main__':
76 main()
77
78 # vim:set et tabstop=2:

  ViewVC Help
Powered by ViewVC 1.1.5