#! /usr/bin/env python

### Copyright (C) 2002-2006 Stephen Kennedy <stevek@gnome.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.

### 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

#
# pychecker
#
import sys
if "--pychecker" in sys.argv:
    sys.argv.remove("--pychecker")
    import os
    os.environ['PYCHECKER'] = "--no-argsused --no-classattr --stdlib"
        #'--blacklist=gettext,locale,pygtk,gtk,gtk.keysyms,popen2,random,difflib,filecmp,tempfile'
    import pychecker.checker
#
# i18n support
#
sys.path += [ #LIBDIR#
]
import paths
import gettext
from gettext import gettext as _

gettext.bindtextdomain("meld", paths.locale_dir())
gettext.textdomain("meld")

# Check requirements: Python 2.3, pygtk 2.8
pyver = (2,3)
pygtkver = (2,8,0)

def missing_reqs(mod, ver):
    modver = mod + " " + ".".join(map(str, ver))
    print _("Meld requires %s or higher.") % modver
    sys.exit(1)

if sys.version_info[:2] < pyver:
    missing_reqs("Python", pyver)

try:
    import pygtk
    pygtk.require("2.0")
    import gtk
    import gtk.glade
except ImportError, e:
    print e
    missing_reqs("pygtk", pygtkver)

if gtk.pygtk_version < pygtkver:
    missing_reqs("pygtk", pygtkver)

# Ignore deprecation warnings from pygtk > 2.6
if gtk.pygtk_version >= (2,8,0):
    import warnings
    warnings.filterwarnings("ignore", category=DeprecationWarning)

gtk.glade.bindtextdomain("meld", paths.locale_dir())
gtk.glade.textdomain("meld")

#
# main
#
import meldapp
for ignore in "--sm-config-prefix", "--sm-client-id":
    try: # ignore session management
        smprefix = sys.argv.index(ignore)
        del sys.argv[smprefix]
        del sys.argv[smprefix]
    except (ValueError,IndexError):
        pass
try: # don't pass on the profiling flag
    minusp = sys.argv.index("--profile")
    del sys.argv[minusp]
    import profile
    profile.run("meldapp.main()")
except ValueError:
    meldapp.main()
sys.exit(0)
