diff options
-rwxr-xr-x | git-bz | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -1273,7 +1273,30 @@ class Bug(object): print "Bug %d - %s" % (self.id, short_desc) print self.get_url() - def create_patch(self, description, comment, filename, data, obsoletes=[], status='none'): + def _patch_via_xmlrpc(self, description, comment, filename, data, obsoletes, status): + params = dict() + params['ids'] = [str(self.id)] + params['data'] = data + params['file_name'] = filename + params['summary'] = description + params['content_type'] = 'text/plain; charset=UTF-8' + params['is_patch'] = '1' + + try: + response = self.server.get_xmlrpc_proxy().Bug.add_attachment(params) + except xmlrpclib.Fault, e: + if "Failed to locate method" in e.faultString: + raise NoXmlRpcError("No add_attachment method") + die(e.faultString) + except xmlrpclib.ProtocolError, e: + if e.errcode == 404: + raise NoXmlRpcError(e.errmsg) + else: + print >>sys.stderr, "Problem creating attachment via XML-RPC: %s (%d)\n" % (e.errmsg, e.errcode) + print >>sys.stderr, "falling back to form post\n" + raise NoXmlRpcError("Communication error") + + def _patch_via_form(self, description, comment, filename, data, obsoletes, status): fields = {} fields['bugid'] = str(self.id) fields['action'] = 'insert' @@ -1299,6 +1322,13 @@ class Bug(object): print response_data die ("Failed to attach patch to bug %d, status=%d" % (self.id, response.status)) + + def create_patch(self, description, comment, filename, data, obsoletes=[], status='none'): + try: + self._patch_via_xmlrpc(description, comment, filename, data, obsoletes, status) + except NoXmlRpcError: + self._patch_via_form(description, comment, filename, data, obsoletes, status) + print "Attached %s" % filename # Update specified fields of a bug; keyword arguments are interpreted |