Changeset 52594 in webkit
- Timestamp:
- Dec 27, 2009 11:59:00 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r52593 r52594 1 2009-12-27 Eric Seidel <eric@webkit.org> 2 3 Reviewed by Adam Barth. 4 5 Add more awesome bug-parsing logic to bugzilla.py in preparation for assign-to-committer command 6 https://bugs.webkit.org/show_bug.cgi?id=32980 7 8 * Scripts/modules/bugzilla.py: 9 - Add a new _parse_bug_page function and use it in fetch_attachments_from_bug 10 - Replace fetch_title_from_bug with a new fetch_bug call instead. 11 - Use list comprehensions where possible to reduce code duplication. 12 * Scripts/modules/bugzilla_unittest.py: 13 - Add a minimal bug parsing test. 14 - Share code between bug parsing and attachment parsing tests with _assert_dictionaries_equal 15 * Scripts/modules/commands/upload.py: 16 - Use fetch_bug(bug_id)["title"] instead of fetch_title_from_bug 17 1 18 2009-12-27 Adam Barth <abarth@webkit.org> 2 19 -
trunk/WebKitTools/Scripts/modules/bugzilla.py
r52540 r52594 113 113 return attachment 114 114 115 def fetch_attachments_from_bug(self, bug_id): 115 def _parse_bug_page(self, page): 116 soup = BeautifulSoup(page) 117 bug = {} 118 bug["id"] = int(soup.find("bug_id").string) 119 bug["title"] = unicode(soup.find("short_desc").string) 120 bug["reporter_email"] = str(soup.find("reporter").string) 121 bug["assign_to_email"] = str(soup.find("assigned_to").string) 122 bug["cc_emails"] = [str(element.string) for element in soup.findAll('cc')] 123 bug["attachments"] = [self._parse_attachment_element(element, bug_id) for element in soup.findAll('attachment')] 124 return bug 125 126 def fetch_bug(self, bug_id): 116 127 bug_url = self.bug_url_for_bug_id(bug_id, xml=True) 117 128 log("Fetching: %s" % bug_url) 118 119 129 page = self.browser.open(bug_url) 120 soup = BeautifulSoup(page) 121 122 attachments = [] 123 for element in soup.findAll('attachment'): 124 attachment = self._parse_attachment_element(element, bug_id) 125 attachments.append(attachment) 126 return attachments 130 return self._parse_bug_page(page) 131 132 # This should be an attachments() method on a Bug object. 133 def fetch_attachments_from_bug(self, bug_id): 134 bug = self.fetch_bug(bug_id) 135 if not bug: 136 return None 137 return bug["attachments"] 127 138 128 139 def _parse_bug_id_from_attachment_page(self, page): … … 156 167 return None # This should never be hit. 157 168 158 def fetch_title_from_bug(self, bug_id):159 bug_url = self.bug_url_for_bug_id(bug_id, xml=True)160 page = self.browser.open(bug_url)161 soup = BeautifulSoup(page)162 return soup.find('short_desc').string163 164 169 def fetch_patches_from_bug(self, bug_id): 165 patches = [] 166 for attachment in self.fetch_attachments_from_bug(bug_id): 167 if attachment['is_patch'] and not attachment['is_obsolete']: 168 patches.append(attachment) 169 return patches 170 return [patch for patch in self.fetch_attachments_from_bug(bug_id) if patch['is_patch'] and not patch['is_obsolete']] 170 171 171 172 # _view_source_link belongs in some sort of webkit_config.py module. … … 216 217 217 218 def fetch_unreviewed_patches_from_bug(self, bug_id): 218 unreviewed_patches = [] 219 for attachment in self.fetch_attachments_from_bug(bug_id): 220 if attachment.get('review') == '?' and not attachment['is_obsolete']: 221 unreviewed_patches.append(attachment) 222 return unreviewed_patches 223 219 return [patch for patch in self.fetch_attachments_from_bug(bug_id) if patch.get('review') == '?' and not patch['is_obsolete']] 220 221 # FIXME: fetch_reviewed_patches_from_bug and fetch_commit_queue_patches_from_bug 222 # should share more code and use list comprehensions. 224 223 def fetch_reviewed_patches_from_bug(self, bug_id, reject_invalid_patches=False): 225 224 reviewed_patches = [] … … 239 238 page = self.browser.open(query) 240 239 soup = BeautifulSoup(page) 241 242 bug_ids = [] 243 # Grab the cells in the first column (which happens to be the bug ids) 244 for bug_link_cell in soup('td', "first-child"): # tds with the class "first-child" 245 bug_link = bug_link_cell.find("a") 246 bug_ids.append(int(bug_link.string)) # the contents happen to be the bug id 247 248 return bug_ids 240 # The contents of the <a> inside the cells in the first column happen to be the bug id. 241 return [int(bug_link_cell.find("a").string) for bug_link_cell in soup('td', "first-child")] 249 242 250 243 def _parse_attachment_ids_request_query(self, page): -
trunk/WebKitTools/Scripts/modules/bugzilla_unittest.py
r52540 r52594 51 51 52 52 class BugzillaTest(unittest.TestCase): 53 54 53 _example_attachment = ''' 55 54 <attachment … … 105 104 self.assertEquals(None, parse_bug_id("http://bugs.webkit.org/show_bug.cgi?ctype=xml&id=12345")) 106 105 107 106 _example_bug = """ 107 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 108 <!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/bugzilla.dtd"> 109 <bugzilla version="3.2.3" 110 urlbase="https://bugs.webkit.org/" 111 maintainer="admin@webkit.org" 112 exporter="eric@webkit.org" 113 > 114 <bug> 115 <bug_id>32585</bug_id> 116 <creation_ts>2009-12-15 15:17 PST</creation_ts> 117 <short_desc>bug to test bugzilla-tool and commit-queue failures</short_desc> 118 <delta_ts>2009-12-27 21:04:50 PST</delta_ts> 119 <reporter_accessible>1</reporter_accessible> 120 <cclist_accessible>1</cclist_accessible> 121 <classification_id>1</classification_id> 122 <classification>Unclassified</classification> 123 <product>WebKit</product> 124 <component>Tools / Tests</component> 125 <version>528+ (Nightly build)</version> 126 <rep_platform>PC</rep_platform> 127 <op_sys>Mac OS X 10.5</op_sys> 128 <bug_status>NEW</bug_status> 129 <priority>P2</priority> 130 <bug_severity>Normal</bug_severity> 131 <target_milestone>---</target_milestone> 132 <everconfirmed>1</everconfirmed> 133 <reporter name="Eric Seidel">eric@webkit.org</reporter> 134 <assigned_to name="Nobody">webkit-unassigned@lists.webkit.org</assigned_to> 135 <cc>foo@bar.com</cc> 136 <cc>example@example.com</cc> 137 <long_desc isprivate="0"> 138 <who name="Eric Seidel">eric@webkit.org</who> 139 <bug_when>2009-12-15 15:17:28 PST</bug_when> 140 <thetext>bug to test bugzilla-tool and commit-queue failures 141 142 Ignore this bug. Just for testing failure modes of bugzilla-tool and the commit-queue.</thetext> 143 </long_desc> 144 </bug> 145 </bugzilla> 146 """ 147 _expected_example_bug_parsing = { 148 "id" : 32585, 149 "title" : u"bug to test bugzilla-tool and commit-queue failures", 150 "cc_emails" : ["foo@bar.com", "example@example.com"], 151 "reporter_email" : "eric@webkit.org", 152 "assign_to_email" : "webkit-unassigned@lists.webkit.org", 153 "attachments" : [], 154 } 155 156 def _assert_dictionaries_equal(self, actual, expected): 157 # Make sure we aren't parsing more or less than we expect 158 self.assertEquals(sorted(actual.keys()), sorted(expected.keys())) 159 160 for key, expected_value in expected.items(): 161 self.assertEquals(actual[key], expected_value, ("Failure for key: %s: Actual='%s' Expected='%s'" % (key, actual[key], expected_value))) 162 163 def test_bug_parsing(self): 164 bug = Bugzilla()._parse_bug_page(self._example_bug) 165 self._assert_dictionaries_equal(bug, self._expected_example_bug_parsing) 166 167 # This could be combined into test_bug_parsing later if desired. 108 168 def test_attachment_parsing(self): 109 169 bugzilla = Bugzilla() 110 111 170 soup = BeautifulSoup(self._example_attachment) 112 171 attachment_element = soup.find("attachment") 113 172 attachment = bugzilla._parse_attachment_element(attachment_element, self._expected_example_attachment_parsing['bug_id']) 114 173 self.assertTrue(attachment) 115 116 # Make sure we aren't parsing more or less than we expect 117 self.assertEquals(sorted(attachment.keys()), sorted(self._expected_example_attachment_parsing.keys())) 118 119 for key, expected_value in self._expected_example_attachment_parsing.items(): 120 self.assertEquals(attachment[key], expected_value, ("Failure for key: %s: Actual='%s' Expected='%s'" % (key, attachment[key], expected_value))) 174 self._assert_dictionaries_equal(attachment, self._expected_example_attachment_parsing) 121 175 122 176 _sample_attachment_detail_page = """ -
trunk/WebKitTools/Scripts/modules/commands/upload.py
r52528 r52594 223 223 (bug_id, svn_revision) = self._determine_bug_id_and_svn_revision(tool, bug_id, svn_revision) 224 224 225 log("Bug: <%s> %s" % (tool.bugs.short_bug_url_for_bug_id(bug_id), tool.bugs.fetch_ title_from_bug(bug_id)))225 log("Bug: <%s> %s" % (tool.bugs.short_bug_url_for_bug_id(bug_id), tool.bugs.fetch_bug(bug_id)["title"])) 226 226 log("Revision: %s" % svn_revision) 227 227
Note: See TracChangeset
for help on using the changeset viewer.