changeset 40:99cdb343273f

can now attach things
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 16 Dec 2012 20:03:18 -0800
parents 15c264451c3d
children 5d09b4e9a21b
files bzconsole/api.py
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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"""