#!/usr/bin/python
""" 
The main startup module.  Try to figure out whether we're running
installed or not, and sort things out accordingly.
"""

import os, sys
from os.path import dirname, realpath, join, isdir

try:
	import googsystray
	sys.stderr = open(os.path.join(googsystray.temp_dir, 'googsystray.err.log'), 'w')
	sys.stdout = open(os.path.join(googsystray.temp_dir, 'googsystray.out.log'), 'w')
	googsystray.set_installed(True)

	basedir = googsystray.get_basedir()
	if not isdir(join(basedir, "icons")):
		basedir = dirname(realpath(sys.argv[0]))
except ImportError:
	# This is an 'uninstalled' case. We want stderr and stdout to remain
	# normal here.
	pkgdir = dirname(dirname(realpath(sys.argv[0])))
	sys.path.append(pkgdir)
	import googsystray

	basedir = googsystray.get_basedir()
	
googsystray.set_basedir(basedir)

import googsystray.GMain	

if googsystray._installed:
	googsystray.GMain.main()
else:
#	import cProfile
#	cProfile.run('googsystray.GMain.main()')
	googsystray.GMain.main()
