File: gameclock

package info (click to toggle)
gameclock 5.0
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 272 kB
  • ctags: 289
  • sloc: python: 1,551; makefile: 9
file content (53 lines) | stat: -rwxr-xr-x 1,632 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
#
# gameclock - a simple chess/game clock

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(os.path.realpath(__file__))))
if s == 'scripts':
    sys.path.insert(0, d)
import gameclock

verbose = 0 # 0 means not verbose, higher numbers show more information, see ui.debug 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__, gameclock.__copyright__, sys.argv[0])

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

    settings = {}
    for o, a in opts:
        if o in ("-v", "--verbose"):
            if not 'verbose' in settings:
                settings['verbose'] = 0
            settings['verbose'] += 1
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-f", "--fullscreen"):
            settings['fullscreen'] = True
        else:
            assert False, "unhandled option"
    from gameclock.gtkui import GameclockUI
    clock = GameclockUI(**settings)
    clock.main()