Mercurial > hg > bzconsole
changeset 3:7830ec1f5dcd
initial thingy
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 02 Nov 2010 10:41:16 -0700 |
parents | 3ceb77d8ca1e |
children | 9ee7b8236c36 |
files | bzconsole/command.py bzconsole/main.py |
diffstat | 2 files changed, 34 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/bzconsole/command.py Tue Nov 02 10:14:19 2010 -0700 +++ b/bzconsole/command.py Tue Nov 02 10:41:16 2010 -0700 @@ -97,6 +97,9 @@ print retval elif retval is None: pass + elif isinstance(retval, list): + for i in retval: + print i else: pprint(retval) return retval
--- a/bzconsole/main.py Tue Nov 02 10:14:19 2010 -0700 +++ b/bzconsole/main.py Tue Nov 02 10:41:16 2010 -0700 @@ -9,14 +9,9 @@ from command import CommandParser -def call(command, *args, **kw): - code = subprocess.call(command, *args, **kw) - if code: - if isinstance(command, basestring): - cmdstr = command - else: - cmdstr = ' '.join(command) - raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) +import json +import urllib +import urllib2 class BZapi(object): """ @@ -26,8 +21,34 @@ def __init__(self, server='https://api-dev.bugzilla.mozilla.org/latest'): self.server = server - def hello(self, name='world'): - print 'hello %s' % name + def products(self, classification=None): + """list bugzailla products""" + configuration = self._configuration() + if classification: + raise NotImplementedError + else: + return sorted(configuration['product'].keys()) + + def components(self, product): + """list bugzilla components for a particular product""" + configuration = self._configuration() + raise NotImplementedError + + def _configuration(self): + if not hasattr(self, '__configuration'): + self.__configuration = self._request('/configuration') + return self.__configuration + + def _request(self, path, data=None): + url = self.server + path + headers = {'Accept': 'application/json', + 'Content-Type': 'application/json'} + if data: + raise NotImplementedError + req = urllib2.Request(url, data, headers) + response = urllib2.urlopen(req) + the_page = response.read() + return json.loads(the_page) def main(args=sys.argv[1:]): parser = CommandParser(BZapi)