From be4fd828c0919373196a2c1175533a01f2a3ac71 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Mon, 2 Dec 2013 22:54:51 +0100 Subject: [PATCH] Check if soundfiles exist for jeopardy music --- music.py | 4 ++++ seopardy.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/music.py b/music.py index 9892135..1991766 100644 --- a/music.py +++ b/music.py @@ -1,5 +1,6 @@ from __future__ import print_function +import os import sys from PySide import phonon @@ -19,7 +20,10 @@ class MusicBox(object): @classmethod def add_music(clazz, name, media_path): if name not in clazz.media.iterkeys(): + if not os.path.isfile(media_path): + return False clazz.media[name] = phonon.Phonon.MediaSource(media_path) + return True @classmethod def play_music(clazz, name): diff --git a/seopardy.py b/seopardy.py index d8a1090..a4ee28c 100755 --- a/seopardy.py +++ b/seopardy.py @@ -59,7 +59,9 @@ if __name__ == '__main__': MusicBox.init() for name, path in config["music"].iteritems(): if path: - MusicBox.add_music(name, path) + if not MusicBox.add_music(name, path): + print("Error: Could not load music %s (file %s)" % (name, path), file=sys.stderr) + sys.exit(1) # create board board = SeopardyGame(questions, gamestate)