#!/usr/bin/python

"""
Python Bugzilla Interface

Simple command-line interface to bugzilla to allow:
 - searching
 - getting bug info
 - saving attachments

Requirements
------------
 - Python 2.5 or later

Classes
-------
 - BugzillaProxy - Server proxy for communication with Bugzilla
 - PrettyBugz - Command line interface to Bugzilla

"""

import locale
import os
import sys
import traceback

from bugz.argparsers import make_parser
from bugz.cli import BugzError, PrettyBugz
from bugz.configfile import get_config

def main():
	parser = make_parser()

	# parse options
	args = parser.parse_args()
	get_config(args)
	if getattr(args, 'columns') is None:
		setattr(args, 'columns', 0)

	try:
		bugz = PrettyBugz(args)
		args.func(bugz, args)

	except BugzError, e:
		print ' ! Error: %s' % e
		sys.exit(-1)

	except TypeError, e:
		print ' ! Error: Incorrect number of arguments supplied'
		print
		traceback.print_exc()
		sys.exit(-1)

	except RuntimeError, e:
		print ' ! Error: %s' % e
		sys.exit(-1)

	except KeyboardInterrupt:
		print
		print 'Stopped.'
		sys.exit(-1)

	except:
		raise

if __name__ == "__main__":
	main()
