/[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 1952 - (show annotations) (download) (as text)
Tue May 31 08:18:25 2011 UTC (23 months, 3 weeks ago) by lucas
File MIME type: text/x-python
File size: 2845 byte(s)
ignore some extra info with broken utf8
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 = file(my_config['path'])
50 line_number = 0
51 entries = []
52 for line in lintian_data:
53 line_number += 1
54
55 #ignore information and verbose output:
56 if line.startswith("N:"):
57 continue
58
59 match = lintian_gatherer.output_re.match(line)
60 if match:
61 (code, pkg, pkg_type, tag, extra) = match.groups();
62 #this one is optional:
63 if pkg_type:
64 pkg_type = quote(pkg_type)
65 else:
66 pkg_type = 'NULL'
67
68 if (pkg == 'manpages-ja' and tag == 'manpage-has-errors-from-man') or \
69 (pkg == 'manpages-zh' and tag == 'manpage-has-errors-from-man') or \
70 (pkg == 'mplayer' and tag == 'manpage-has-errors-from-man'):
71 extra = '' # HACK psycopg2.DataError: invalid byte sequence for encoding "UTF8": 0xbb
72 entries.append((pkg, pkg_type, tag, lintian_gatherer.code_to_tag_type_map[code], extra))
73 # elif not lintian_gatherer.ignore_re.match(line):
74 # print "Can't parse line %d: %s" % (line_number, line.rstrip())
75
76 # for e in entries:
77 # print e
78 # cur.executemany("EXECUTE lintian_insert (%s, %s, %s, %s, %s)", [e])
79 cur.executemany("EXECUTE lintian_insert (%s, %s, %s, %s, %s)", entries)
80 cur.execute("DEALLOCATE lintian_insert")
81 cur.execute("ANALYZE %s" % my_config["table"])
82
83 if __name__ == '__main__':
84 main()
85
86 # vim:set et tabstop=2:

  ViewVC Help
Powered by ViewVC 1.1.5