#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# gameclock - a simple chess/game clock

__copyright__ = """Copyright (C) 2008-2011  Antoine Beaupré
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
For details see the COPYRIGHT file distributed along this program."""

import getopt
import sys
import os
# crude hack to support running from the source directory
d, s = os.path.split(os.path.dirname(os.path.abspath(__file__)))
if s == 'scripts':
    sys.path.insert(0, d)
import gameclock

verbose = 0 # 0 means not verbose, higher numbers show more information, see maybe_print for more info

def usage():
    """gameclock v%s %s
Usage:
  %s [ -h | -v ... | -f ]

  -h --help: display this help
  -v --verbose: display progress information to stdout. repeating the flag will show more information
  -f --fullscreen: start in fullscreen mode

See the manpage for more information."""
    print usage.__doc__ % (gameclock.__version__, __copyright__, sys.argv[0])

if __name__ == "__main__":
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hvf:p:", ["help", "verbose", "fullscreen"])
    except getopt.GetoptError, err:
        # print help information and exit:
        usage()
        print "\nError: " + str(err) # will print something like "option -a not recognized"
        sys.exit(2)

    from gameclock.gtkui import GameclockUI
    clock = GameclockUI()
    for o, a in opts:
        if o in ("-v", "--verbose"):
            clock.verbose += 1
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-f", "--fullscreen"):
            clock.fullscreen = True
        else:
            assert False, "unhandled option"
    clock.maybe_print('running with verbosity: %d' % clock.verbose)
    clock.main()
