view bzconsole/main.py @ 58:cb3330bcff99

bzconsole/api.py
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 Sep 2013 11:40:23 -0700
parents 027a85c2a6d7
children 355d00c749d9
line wrap: on
line source

#!/usr/bin/env python

import os
import sys
from api import BZapi
from command import CommandParser
from StringIO import StringIO

class BZcli(BZapi):
    """command line interface front-end for the API class"""

    def file(self, component, title, path, **kwargs):
        """read from a file [NOTIMPLEMENTED]"""
        raise NotImplementedError

    def ls(self, directory=os.getcwd()):
        """list bug related files in the given directory"""
        

    def unique(self, component=None):
        """display unique and duplicated components"""
        unique, dupe = self._unique_components()

        if component:
            # determine if the component is unique
            if component in unique:
                return '%s: %s' % (component, unique[component])
            if component in dupe:
                return '>>>DUPLICATE<<<'
            return 'Component "%s" not found' % component

        buffer = StringIO()
        print >> buffer, 'Unique:'
        for key in sorted(unique.keys()):
            print >> buffer, ' %s: %s' % (key, unique[key])
        print >> buffer
        print >> buffer, 'Duplicate:'
        for value in sorted(dupe):
            print >> buffer, ' %s' % value
        return buffer.getvalue()

def main(args=sys.argv[1:]):
    parser = CommandParser(BZcli)
    parser.invoke(args)

if __name__ == '__main__':
    main()