#! /usr/bin/env python

### Copyright (C) 2002-2003 Stephen Kennedy <steve9000@users.sf.net>

### 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#
# i18n support
#
import sys
sys.path += [ #LIBDIR#
]
import paths
import gettext
import locale

try:
    locale.setlocale(locale.LC_ALL, '')
    gettext.bindtextdomain("meld", paths.locale_dir() )
    gettext.textdomain("meld")
    gettext.install("meld", paths.locale_dir(), unicode=1)
except (IOError,locale.Error), e:
    # fake gettext until translations in place
    print "(meld): WARNING **: %s" % e
    __builtins__.__dict__["_"] = lambda x : x

#
# python version
#

pyver = (2,2)
pygtkver = (1,99,15)

def ver2str(ver):
    return ".".join(map(str,ver))

if sys.version_info[:2] < pyver:
    print _("Meld requires python%s or higher.") % ver2str(pyver)
    sys.exit(1)

#
# pygtk 2 
#
try:
    import pygtk
except ImportError, e:
    print e
    print _("Meld requires a recent version of pygtk.")
    print _("pygtk-%s or higher is recommended.") % ver2str(pygtkver)
    sys.exit(1)
else:
    pygtk.require("2.0")

#
# pygtk version
#
import gtk
if gtk.pygtk_version < pygtkver:
    print _("Meld works best with pygtk-%s or higher. (found %s)") % (ver2str(pygtkver), ver2str(gtk.pygtk_version))
    print _("Due to incompatible API changes some functions may not operate as expected.")

import gtk.glade # python2.2 needs this
gtk.glade.bindtextdomain("meld", paths.locale_dir() )
locale.setlocale(locale.LC_TIME, "C")

#
# main
#
import meldapp
try:
    minusp = sys.argv.index("--profile")
    del sys.argv[minusp]
    import profile
    profile.run("meldapp.main()")
except ValueError:
    meldapp.main()
