# HG changeset patch # User Jeff Hammel # Date 1355716998 28800 # Node ID 99cdb343273fe0924d325f98be04debcad277f38 # Parent 15c264451c3d11554b1cdfddfe22889d04303a52 can now attach things diff -r 15c264451c3d -r 99cdb343273f bzconsole/api.py --- a/bzconsole/api.py Fri Dec 14 16:39:40 2012 -0800 +++ b/bzconsole/api.py Sun Dec 16 20:03:18 2012 -0800 @@ -2,6 +2,7 @@ console API to bugzilla """ +import base64 import httplib import json import os @@ -181,6 +182,11 @@ contents = file(attachment).read() is_patch = bool(patch.fromstring(contents)) + if is_patch: + content_type = 'text/plain' + else: + # TODO: better content_type + content_type = 'text/plain' # patch flags flags = [] @@ -195,15 +201,20 @@ # create attachment data structure # https://wiki.mozilla.org/Bugzilla:REST_API:Objects#Attachment - attachment= {'bug': int(bug), + contents = contents.encode('base64') + attachment= {#'bug_id': int(bug), + 'content_type': content_type, + 'data': contents, 'description': description, + 'encoding': 'base64', 'file_name': basename, 'flags': flags, 'is_patch': is_patch, - 'is_private': False + 'is_private': False, + 'size': len(contents) } - self._request('/bug/%s/attachment' % bug, attachment) + return self._request('/bug/%s/attachment' % bug, attachment) def configuration(self): """bugzilla configuration"""