diff options
author | Owen W. Taylor <otaylor@fishsoup.net> | 2009-08-30 11:45:29 -0400 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2009-08-30 11:45:29 -0400 |
commit | 66da60a337ed559fc85144b3fa65bee654219ce2 (patch) | |
tree | 332cb38237ea52d3ddc352f241ae6d3c09bfe788 | |
parent | 6a580977ac13a987a7aa87ec9e2f8560a3f0d5ef (diff) | |
download | git-bz-66da60a337ed559fc85144b3fa65bee654219ce2.tar.gz |
Add a helper function for checking for success
Encapsulate the process of grepping through successful (200)
responses from Bugzilla to see if they were *really* successful
in a function.
-rwxr-xr-x | git-bz | 51 |
1 files changed, 33 insertions, 18 deletions
@@ -789,6 +789,30 @@ class BugTransport(xmlrpclib.Transport): xmlrpclib.Transport.send_request(self, connection, *args) connection.putheader("Cookie", self.server.get_cookie_string()) +# Unfortunately, Bugzilla doesn't set a useful status code for +# form posts. Because it's very confusing to claim we succeeded +# but not, we look for text in the response indicating success, +# and not text indicating failure. +# +# We generally look for specific <title> tags - these have been +# quite stable across versions, though translations will throw +# us off. +# +# *args are regular expressions to search for in response_data +# that indicate success. Returns the matched regular expression +# on success, None otherwise +def check_for_success(response, response_data, *args): + + if response.status != 200: + return False + + for pattern in args: + m = re.search(pattern, response_data) + if m: + return m + + return None + class Bug(object): def __init__(self, server): self.server = server @@ -884,15 +908,11 @@ class Bug(object): response = self.server.send_post("/post_bug.cgi", fields) response_data = response.read() - - if response.status != 200: - print response_data - die("Failed to create bug: %d" % response.status) - - m = re.search(r"<title>\s*Bug\s+([0-9]+)", response_data) + m = check_for_success(response, response_data, + r"<title>\s*Bug\s+([0-9]+)") if not m: print response_data - die("Filing bug failed") + die("Failed to create bug, status=%d" % response.status) self.id = int(m.group(1)) @@ -924,18 +944,13 @@ class Bug(object): response = self.server.send_post("/attachment.cgi", fields, files) response_data = response.read() - - if response.status != 200: - die ("Failed to attach patch to bug: status=%d" % response.status) - - # Older bugzilla's used this for successful attachments - m = re.search(r"<title>\s*Changes\s+Submitted", response_data) - if not m: - # Newer bugzilla's, use, instead: - m = re.search(r"<title>\s*Attachment\s+\d+\s+added", response_data) - if not m: + if not check_for_success(response, response_data, + # Older bugzilla's used this for successful attachments + r"<title>\s*Changes\s+Submitted", + # Newer bugzilla's, use, instead: + r"<title>\s*Attachment\s+\d+\s+added"): print response_data - die ("Failed to attach patch to bug") + die ("Failed to attach patch to bug %d, status=%d" % (self.id, response.status)) print "Attached %s" % filename |