#!/usr/bin/python
# -*-python-*-

# Author: Robert Park <robru@gottengeography.ca>, (C) 2010
# Copyright: See COPYING file included with this distribution.


from gi.repository import Gtk
import sys


def need(dependency):
    """Exit the program and tell the user what dependency was missing."""
    sys.exit('GottenGeography requires at least ' + dependency)


try:
    assert sys.version_info > (3, 1)
except:
    need('Python 3.2')


try:
    from dateutil.parser import parse
    parse('2017-05-14')  # Suppress pyflakes warning.
except:
    need('python3-dateutil 2.0')


try:
    import gi
    # Raises AttributeError with pygobject 2.21.
    gi.require_version('Gtk', '3.0')
except:
    need('Gtk 3.0 (via pygobject3 3.0.3)')


try:
    from gi.repository import Champlain
    # Raises AttributeError with libchamplain 0.8 or earlier.
    Champlain.PathLayer

    # Raises TypeError with libchamplain 0.12.0
    [source.get_id() for source in
        Champlain.MapSourceFactory.dup_default().get_registered()]
except:
    need('libchamplain 0.12.2')


try:
    from gi.repository import GExiv2
    GExiv2.Metadata()
except:
    need('gexiv2 0.4.90 (with introspection support, gir1.2-gexiv2-0.4)')


old_hook = sys.excepthook
def new_hook(*args):
    """Exit cleanly if there was an unhandled exception."""
    old_hook(*args)
    while Gtk.main_level():
        Gtk.main_quit()
    sys.exit()
sys.excepthook = new_hook


# If we got this far, it looks like we have everything we need!
# Time to launch the app.


from gg.app import GottenGeography
GottenGeography(not sys.argv[1:]).run(sys.argv)
