# HG changeset patch # User Jeff Hammel # Date 1288719676 25200 # Node ID 7830ec1f5dcd5e4b9fd6e9c79ae6349ff9bf6707 # Parent 3ceb77d8ca1e2eba0e9de42959477e3541855906 initial thingy diff -r 3ceb77d8ca1e -r 7830ec1f5dcd bzconsole/command.py --- 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 diff -r 3ceb77d8ca1e -r 7830ec1f5dcd bzconsole/main.py --- 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)