# HG changeset patch # User Jeff Hammel # Date 1289086327 25200 # Node ID 3cdbc94626b84c979cab65bf8a9b33dcbd6b3891 # Parent b350ae6fe3c9206e8e9296689cf69a3314ee619b better url encoding; however, i still get a 500 diff -r b350ae6fe3c9 -r 3cdbc94626b8 bzconsole/main.py --- 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)