#! /usr/bin/env python

# Copyright 2011 Harold Fellermann
# 
# This file is part of Spartacus.
#
# Spartacus 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 3 of the License, or
# (at your option) any later version.
#
# Spartacus 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 Spartacus.  If not, see <http://www.gnu.org/licenses/>.

"""spartacus start script
"""

if __name__ == "__main__" :
	import sys
	import getopt
	import logging

	logging.basicConfig(level=logging.DEBUG)

	kwds = {
		'gui' :     True,
		'output' :  False,
	}
	version = False

	# parse command line options
	try :
		opts,args = getopt.getopt(sys.argv[1:],"ovx")
	except getopt.GetoptError :
		sys.stderr.write("Usage: %s [-ox] [MODEL_FILE]\n" % sys.argv[0])
		sys.exit(1)

	for o,a in opts :
		if   o == '-o' : kwds['output'] = True
		elif o == '-x' : kwds['gui'] = False
		elif o == '-v' : version = True
		else :
			sys.stderr.write("Unknown option: '%s'\n" % o)
			sys.exit(1)

	# read optional model from command line
	model = args[0] if args else None

	# save everything after -- in options
	from spartacus import options
	options.command_line = args[1:]

	# initialize and start controller
	if version :
		from spartacus import version
		sys.stdout.write("%s\n" % version)
	else :
		from spartacus.controller import Controller
		controller = Controller(model, **kwds)
		controller.run()

