#!/usr/bin/env python
# Copyright (C) 2009, Thomas Leonard
# See the README file for details, or visit http://0install.net.
import os, sys
from os.path import dirname

import gettext
import locale
from logging import warn
try:
	locale.setlocale(locale.LC_ALL, '')
except locale.Error:
	warn('Error setting locale (eg. Invalid locale)')

# This is for pycentral on Debian-type systems. 0launch-gui is a symlink to the
# copy in the pycentral source directory. Python does a realpath() on this
# before adding the containing directory to sys.path, which means we don't see
# the .pyc files. If run as root, this also causes .pyc files to be created in
# the source directory, leaving a mess when the package is removed.
_mydir = dirname(__file__)
sys.path.insert(0, _mydir)

# Make sure we're using our bundled copy of Zero Install, not the system version
# (if different)
sys.path.insert(0, dirname(dirname(_mydir)))

from zeroinstall.support.tasks import get_loop
get_loop().glib.threads_init()

from zeroinstall import localedir

if localedir:
	# Tell GTK where to find the translations, if they're not in
	# the default system location.
	if hasattr(locale, 'bindtextdomain'):
		locale.bindtextdomain('zero-install', localedir)

import main

try:
	main.run_gui(sys.argv[1:])
except KeyboardInterrupt:
	sys.exit(1)
