/[gentoo]/src/packages/bugs.py
Gentoo

Diff of /src/packages/bugs.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.2
1"""This is probably overkill for packages.gentoo.org, but perhaps it can be 1"""This is probably overkill for packages.gentoo.org, but perhaps it can be
2used elsewhere""" 2used elsewhere"""
3 3
4__version__ = '$Revision: 1.1 $' 4__revision__ = '$Revision: 1.2 $'
5# $Source: /var/cvsroot/gentoo/src/packages/bugs.py,v $ 5# $Source: /var/cvsroot/gentoo/src/packages/bugs.py,v $
6 6
7# importers may want to override this. This is the current(?) 7# importers may want to override this. This is the current(?)
8# bugs.gentoo.org settings 8# bugs.gentoo.org settings
9STATUS = {'UNCONFIRMED': 'UNCONFIRMED', 9STATUS = {'UNCONFIRMED': 'UNCONFIRMED',
11 'ASSIGNED': 'ASSIGNED', 11 'ASSIGNED': 'ASSIGNED',
12 'REOPENED': 'REOPENED', 12 'REOPENED': 'REOPENED',
13 'RESOLVED': 'RESOLVED', 13 'RESOLVED': 'RESOLVED',
14 'VERIFIED': 'VERIFIED', 14 'VERIFIED': 'VERIFIED',
15 'CLOSED': 'CLOSED'} 15 'CLOSED': 'CLOSED'}
16
17def parse_csv(line):
18 """parse a line of CSV"""
19 data = []
20 indata = 0
21 inquote = 0
22 line = line.strip()
23 cdata = ''
24 prev_char = ''
25 for char in line:
26 if char == ',':
27 if indata:
28 if not inquote:
29 data.append(cdata)
30 cdata = ''
31 indata = 0
32 else:
33 cdata = cdata + char
34 elif prev_char == '' or prev_char == ',':
35 data.append('')
36 elif char == '"':
37 if indata:
38 data.append(cdata)
39 indata = 0
40 cdata = ''
41 inquote = 0
42 else:
43 indata = 1
44 inquote = 1
45 elif indata:
46 cdata = cdata + char
47 else:
48 indata = 1
49 cdata = cdata = char
50 prev_char = char
51 if prev_char != '"':
52 data.append(cdata)
53 return data
54 16
55class Bug: 17class Bug:
56 """a bugzilla bug""" 18 """a bugzilla bug"""
57 def __init__(self, bug_id, severity, priority, rep_platform, assigned_to, 19 def __init__(self, bug_id, severity, priority, rep_platform, assigned_to,
58 status, resolution, short_desc): 20 status, resolution, short_desc):
62 self.rep_platform = rep_platform 24 self.rep_platform = rep_platform
63 self.assigned_to = assigned_to 25 self.assigned_to = assigned_to
64 self.status = status 26 self.status = status
65 self.resolution = resolution 27 self.resolution = resolution
66 self.short_desc = short_desc 28 self.short_desc = short_desc
29
30 self.data = (self.bug_id, self.severity, self.priority,
31 self.rep_platform, self.assigned_to, self.status, self.resolution,
32 self.short_desc)
67 33
68 def to_dict(self): 34 def to_dict(self):
69 """convert to dict""" 35 """convert to dict"""
70 return {'bug_id': self.bug_id, 36 return {'bug_id': self.bug_id,
71 'severity': self.severity, 37 'severity': self.severity,
76 'resolution': self.resolution, 42 'resolution': self.resolution,
77 'short_desc': self.short_desc} 43 'short_desc': self.short_desc}
78 44
79 def to_tuple(self): 45 def to_tuple(self):
80 """convert to tuple""" 46 """convert to tuple"""
81 return [self.bug_id, self.severity, self.priority, self.rep_platform, 47 return self.data
82 self.assigned_to, self.status, self.resolution, self.short_desc] 48
49 def __iter__(self):
50 """Same as above"""
51 for field in self.data:
52 yield field
53
54 def __getitem__(self, index):
55 """Makes me look like a tuple or list"""
56 return self.data[index]
83 57
84class BugFactory: 58class BugFactory:
85 """create bugs from dict data""" 59 """create bugs from dict data"""
86 def __init__(self): 60 def __init__(self):
87 """to shut pylint up""" 61 """to shut pylint up"""
88 pass 62 pass
89 63
90 def fromDict(self, mapping): 64 def from_dict(self, mapping):
91 """from dict => BugFactory.fromDict(mapping).to_dict() == mapping""" 65 """from_dict => BugFactory.from_dict(mapping).to_dict() == mapping"""
92 bug_id = mapping.get("bug_id", "unknown") 66 bug_id = mapping.get("bug_id", "unknown")
93 severity = mapping.get("severity") 67 severity = mapping.get("severity")
94 priority = mapping.get("priority") 68 priority = mapping.get("priority")
95 rep_platform = mapping.get("rep_platform") 69 rep_platform = mapping.get("rep_platform")
96 assigned_to = mapping.get("assigned_to") 70 assigned_to = mapping.get("assigned_to")
99 short_desc = mapping.get("short_desc") 73 short_desc = mapping.get("short_desc")
100 74
101 return Bug(bug_id, severity, priority, rep_platform, assigned_to, 75 return Bug(bug_id, severity, priority, rep_platform, assigned_to,
102 status, resolution, short_desc) 76 status, resolution, short_desc)
103 77
104 def fromListOfDicts(self, buglist): 78 def from_list_of_dicts(self, buglist):
105 """when you have a list of dicts""" 79 """when you have a list of dicts"""
106 all = [] 80 return [self.from_dict(mapping) for mapping in buglist]
107 for mapping in buglist: 81
108 all.append(self.fromDict(mapping)) 82 def from_list_of_lists(self, lists):
109 return all 83 """Return list of bugs from list of lists. Lists must be in same
84 order as call to Bug.__init__()
110 85 """
86 return [Bug(*bug_list) for bug_list in lists]
87
88 from_db_query = from_list_of_lists
89
111 def fromCSV(self, csv_file): 90 def from_csv(self, csv_file):
112 """fp should be a file object with CSV data in the format as returned 91 """fp should be a file object with CSV data in the format as returned
113 by bugzlla""" 92 by bugzlla"""
114 93
115 all = [] 94 import csv
116 for line in csv_file.readlines()[1:]: 95 reader = csv.reader(csv_file)
117 mapping = {} 96 return [Bug(*data[:8]) for data in reader]
118 fields = parse_csv(line)
119 if len(fields) < 7:
120 continue # wtf?
121 #print fields
122 (mapping['bug_id'], mapping['severity'], mapping['priority'],
123 mapping['rep_platform'], mapping['assigned_to'],
124 mapping['status'], mapping['resolution'],
125 mapping['short_desc']) = fields[:8]
126 all.append(self.fromDict(mapping))
127
128 return all
129
130 97
131class HTMLWriter: 98class HTMLWriter:
132 """convert list of bugs to HTML""" 99 """convert list of bugs to HTML"""
133 def __init__(self, bugs, bugzilla_site=None): 100 def __init__(self, bugs, bugzilla_site=None):
134 """where <bugs> is a list of Bugs""" 101 """where <bugs> is a list of Bugs"""
102
135 html = '<table class="buglist">\n' 103 table_begin = '<table class="buglist">'
136 html = ('%s<tr class="heading"><th class="bug_id">Bug ID</th>' 104 table_heading = ('<tr class="heading">'
105 '<th class="bug_id">Bug ID</th>'
137 '<th class="severity">Severity</th><th class="priority">' 106 '<th class="severity">Severity</th>'
107 '<th class="priority">Priority</th>'
138 'Priority</th><th class="platform">Platform</th>' 108 '<th class="platform">Platform</th>'
139 #'<th class="assigned_to">Assigned To</th>' 109 #'<th class="assigned_to">Assigned To</th>'
140 '<th class="status">Status</th>' 110 '<th class="status">Status</th>'
141 #'<th class="resolution">Resolution</th>' 111 #'<th class="resolution">Resolution</th>'
142 '<th class="description">Description</th>' 112 '<th class="description">Description</th>'
143 '</tr>\n' % html) 113 '</tr>')
114 rows = []
144 for bug in bugs: 115 for bug in bugs:
145 bug_dict = bug.to_dict() 116 bug_dict = bug.to_dict()
146 html = html + '<tr class="bug">'
147 if bugzilla_site: 117 if bugzilla_site:
148 html = html + ('<td class="bug_id">' 118 bug_id = ('<td class="bug_id">'
149 '<a href="http://%s/show_bug.cgi?id=%s">' 119 '<a href="http://%s/show_bug.cgi?id=%s">'
150 '%s</td>' % (bugzilla_site, bug_dict['bug_id'], 120 '%s</td>' % (bugzilla_site, bug_dict['bug_id'],
151 bug_dict['bug_id'])) 121 bug_dict['bug_id']))
152 else: 122 else:
153 html = html + '<td class="bug_id">%(bug_id)s</td>' % bug_dict 123 bug_id = '<td class="bug_id">%(bug_id)s</td>' % bug_dict
154 124
155 html = html + ('<td class="severity">%(severity)s</td>' 125 bug_data = ('<td class="severity">%(severity)s</td>'
156 '<td class="priority">%(priority)s</td>' 126 '<td class="priority">%(priority)s</td>'
157 '<td class="platform">%(rep_platform)s' 127 '<td class="platform">%(rep_platform)s'
158 #'<td class="assigned_to">%(assigned_to)s</td>' 128 #'<td class="assigned_to">%(assigned_to)s</td>'
159 '<td class="status">%(status)s</td>' 129 '<td class="status">%(status)s</td>'
160 #'<td class="resolution">%(resolution)s</td>' 130 #'<td class="resolution">%(resolution)s</td>'
161 '<td class="description">%(short_desc)s</td>' 131 '<td class="description">%(short_desc)s</td>'
162 '</tr>\n' % bug_dict) 132 % bug_dict)
163 html = html + '</table>\n' 133 row = '<tr class="bug">%(bug_id)s%(bug_data)s</tr>' % locals()
164 self.html = html 134 rows.append(row)
135 table_end = '</table>'
136 self.html = '\n '.join([table_begin, table_heading] + rows +
137 [table_end])
165 138
166 def __str__(self): 139 def __str__(self):
167 return self.html 140 return self.html

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.20