seopardy/seopardy.py

59 lines
1.6 KiB
Python
Raw Normal View History

2013-11-06 20:42:00 +01:00
#!/usr/bin/python
from __future__ import print_function
import argparse
import os
import sys
#from PySide import QtCore, QtGui
from PySide import QtGui
from question import Questions
from gamestate import GameState
from game import SeopardyGame
def _parser():
parser = argparse.ArgumentParser(description="Sebas jeopardy/beopardy clone")
parser.add_argument("--fifo", action="store", default="/tmp/seopardy-fifo", help="Name of the fifo to create")
parser.add_argument("--gamestate", action="store", default=None, help="Gamestate to load to recover a crashed game")
2013-11-13 21:16:50 +01:00
parser.add_argument("--savedir", action="store", default="/tmp/seopardy/", help="Directory where to save the temporary gamestates to, in case of game-crash")
2013-11-06 20:42:00 +01:00
parser.add_argument("questions", action="store", help="Path to questionfile")
return parser
if __name__ == '__main__':
parser = _parser()
args = parser.parse_args()
fifo = None
try:
if os.path.exists(args.fifo):
os.unlink(args.fifo)
os.mkfifo(args.fifo)
except OSError as e:
print("Error: Could not create fifo: %s" % (str(e),), file=sys.stderr)
2013-12-01 22:41:44 +01:00
sys.exit(1)
2013-11-06 20:42:00 +01:00
questions = Questions(args.questions)
# start gui
app = QtGui.QApplication([])
2013-12-01 22:41:44 +01:00
# create or load gamestate
gamestate = None
if args.gamestate:
sstream = None
try:
sstream = open(args.gamestate, "r")
except IOError as e:
print("Error: Could not load gamestate: %s" % (str(e),), file=sys.stderr)
sys.exit(1)
gamestate = GameState.load(sstream, args.savedir)
else:
gamestate = GameState(args.savedir)
# create board
2013-11-06 20:42:00 +01:00
board = SeopardyGame(questions, gamestate)
board.show()
app.exec_()
sys.exit()