#!/usr/bin/python
# -*- coding: utf8 -*-
#
# XSL - graphical interface for SL
# Copyright (C) 2007-2016 Devaev Maxim
#
# This file is part of XSL.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# apps/xsl/src/xsl/xsl.py.  Generated from xsl.py.in by configure.


import sys
import os
import getopt
import traceback


##### Private methods #####
def help() :
	print ( "Usage: xsl [options]\n"
		"Options:\n"
		"\t-h, --help -- Print this text\n"
		"\t--xsl-libs-path=<path/to/libs> -- Set path for loading XSL libs\n"
		"\t--enable-psyco -- Enable experimental Psyco environment\n"
		"\t-s=<string>, --session=<string> -- Restoring X11 session" )

##### Main #####
if __name__ == "__main__" :
	xsl_libs_path = os.path.join("/usr/lib", "xsl/xsl")
	enable_psyco_flag = False

	try :
		(opts_list, args_list) = getopt.getopt(sys.argv[1:], "hs:", ( "help", "no-splash", "no-tray-icon",
			"xsl-libs-path=", "enable-psyco", "session=" ))

		for (opts_list_item, args_list_item) in opts_list :
			if opts_list_item in ("-h", "--help") :
				help()
				sys.exit(0)

			elif opts_list_item in ("--xsl-libs-path",) :
				xsl_libs_path = args_list_item

			elif opts_list_item in ("--enable-psyco",) :
				enable_psyco_flag = True

			elif opts_list_item in ("-s", "--session",) :
				print >> sys.stderr, "Accepted X11 session: %s" % (args_list_item)
	except Exception, err :
		print "Bad command line options: %s" % (str(err))

	#####

	if enable_psyco_flag :
		try :
			import psyco
			psyco.full()
			print >> sys.stderr, "Experemintal Psyco environment is enabled"
		except :
			print >> sys.stderr, "Ignored enabling Psyco:\n%s" % (traceback.format_exc())

	sys.path.append(xsl_libs_path)
	import Main
	Main.Main().run()

