#!/usr/bin/python
#
# Copyright (C) 2005, TUBITAK/UEKAE
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#

import sys

import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext

from pisi.cli.pisicli import PisiCLI
from pisi.ui import ui

def handle_exception(exception, value, tb):
    import traceback
    import exceptions
    from pisi.xmlext import XmlError
    from pisi.ui import ui

    if exception == exceptions.KeyboardInterrupt:
        ui.error(_("\nKeyboardInterrupt: Exiting...\n"))
        sys.exit(1)
    elif exception == XmlError:
        ui.error(str(value))
        sys.exit(1)

    ui.error(_("""
Internal PISI Error:
Please file a bug report! (http://bugs.uludag.org.tr)

"""))

    ui.error("%s\n" %value)
    ui.info(_("Traceback:\n"))
    traceback.print_tb(tb)
    sys.exit(1)

if __name__ == "__main__":

    sys.excepthook = handle_exception

    cli = PisiCLI()
    cli.run_command()
