#!/usr/bin/env python

# reportbug-ng - Report a bug in Debian's BTS.
# Copyright (C) 2007-2014  Bastian Venthur
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


import sys
sys.path.append('/usr/share/reportbug-ng')
import logging
from optparse import OptionParser

from PyQt4 import QtCore, QtGui

from rnggui import RngGui

from rnghelpers import getInstalledPackageVersion


if __name__ == "__main__":
    # Get Options
    description = """\
Report a bug in Debian's BTS. The optional paremter QUERY behaves exactly like the query inside the program. \
Supported queries are: packagename, bugnumber, maintainer@foo.bar, src:package, from:submitter@foo.bar, severity:foo and tag:bar."""
    usage = "%prog [Options] [Query]"
    version = """Reportbug-NG """ + getInstalledPackageVersion("reportbug-ng") + """
Copyright (C) 2007-2014 Bastian Venthur <venthur at debian org>

Homepage: http://reportbug-ng.alioth.debian.org

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.
"""
    parser = OptionParser(usage=usage, version=version, description=description)
    parser.add_option('-l', '--loglevel', type='choice', choices=['critical',
        'error', 'warning', 'info', 'debug', 'notset'], dest='loglevel',
        help='Which loglevel to use [default: warning]. Valid loglevels are: critical, error, warning, info, debug, notset',
        metavar='LEVEL')

    options, args = parser.parse_args()

    # Initialize logging
    loglevel = {'critical' : logging.CRITICAL,
                'error'    : logging.ERROR,
                'warning'  : logging.WARNING,
                'info'     : logging.INFO,
                'debug'    : logging.DEBUG,
                'notset'   : logging.NOTSET
                }.get(options.loglevel, logging.WARNING)

    logging.basicConfig(level=loglevel, format='%(name)-12s %(levelname)-8s %(message)s')
    logging.info('Logger initialized with level %s.' % options.loglevel)

    app = QtGui.QApplication(sys.argv)
    translator = QtCore.QTranslator()
    locale = QtCore.QLocale.system().name()
    translator.load(locale, "/usr/share/reportbug-ng/translations/")
    app.installTranslator(translator)
    gui = RngGui(args)
    gui.show()
    sys.exit(app.exec_())

