changeset 10:3cdbc94626b8

better url encoding; however, i still get a 500
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 06 Nov 2010 16:32:07 -0700
parents b350ae6fe3c9
children e7dfad8c8f27
files bzconsole/main.py
diffstat 1 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/bzconsole/main.py	Sat Nov 06 14:57:43 2010 -0700
+++ b/bzconsole/main.py	Sat Nov 06 16:32:07 2010 -0700
@@ -50,8 +50,8 @@
         assert product in configuration['product'], 'Product %s not found' % product
         return sorted(configuration['product'][product]['component'].keys())
 
-    def new(self, product, component, title, version=None):
-        """file a new bug"""
+    def new(self, product, component, title, version=None, description=None):
+        """file a new bug. username and password must be set"""
 
         # sanity check
         assert product in self.products(), "Product not found"
@@ -65,15 +65,22 @@
         assert version in self._configuration['product'][product]['version'], 'Version not found'
         
         # get the bug description
-        description = tmpbuffer()
+        if not description:
+            description = tmpbuffer()
         assert description, "Must provide a non-empty description"
 
         # create the needed data structure
         request = dict(product=product, component=component,
                        summary=title, version=version,
-                       comments=[description])
+                       comments=[description],
+                       op_sys='Any', platform='Any',)
+
+        # POST the request
+        try:
+            results = self._request('/bug', request)
+        except Exception, e:
+            raise
         
-        import pdb; pdb.set_trace()
 
     def configuration(self):
         """bugzilla configuration"""
@@ -97,19 +104,23 @@
 
     def _request(self, path, data=None):
         url = self.server + path
-        query = []
+        query = {}
         if self.username:
-            query.append(self.username)
+            query['username'] = self.username
         if self.password:
-            query.append(self.password)
+            query['password'] = self.password
         if query:
-            url += '?' + '&'.join(query) # TODO: urlencode this
+            query = urllib.urlencode(query)
+            url += '?' + query
         headers = {'Accept': 'application/json',
                    'Content-Type': 'application/json'}
         if data:
             data = json.dumps(data)
         req = urllib2.Request(url, data, headers)
-        response = urllib2.urlopen(req)
+        try:
+            response = urllib2.urlopen(req)
+        except Exception, e:
+            import pdb; pdb.set_trace()
         the_page = response.read()
         return json.loads(the_page)