Make question media path relative to file

This commit is contained in:
Sebastian Lohff 2014-12-17 05:11:24 +01:00
parent 0ec7bb3a7e
commit 5e34d4e9b1
2 changed files with 7 additions and 2 deletions

View File

@ -13,9 +13,11 @@ class Questions(object):
QUESTION_TYPES = ["Text", "Image", "Music", "Code", "Video"]
QUESTION_KEYS = ["Name", "Question", "Answer", "Type", "Double-Jeopardy", "Audio"]
def __init__(self, qfile):
def __init__(self, qfile, appendPath=False):
self.qfile = qfile
self._questions = None
self._appendPath = appendPath
self._basedir = os.path.dirname(qfile)
self._read_questions()
def get_sections(self):
@ -90,6 +92,8 @@ class Questions(object):
# check if file for music/image questions exist
if q["Type"] in ("Music", "Image", "Video"):
if self._appendPath:
q["Question"] = os.path.join(self._basedir, q["Question"])
if not os.path.isfile(q["Question"]):
raise QuestionException("File for question %d, section %d (%s) not found" % (j, i, sec["Section"]))

View File

@ -17,6 +17,7 @@ def _parser():
parser = argparse.ArgumentParser(description="Sebas jeopardy/beopardy clone")
parser.add_argument("--gamestate", action="store", default=None, help="Gamestate to load to recover a crashed game")
parser.add_argument("--conf", action="store", default="seopardy.conf", help="Path to config file")
parser.add_argument("--no-cwd", action="store_true", default=False, help="Do not change working directory to question folder")
parser.add_argument("questions", action="store", help="Path to questionfile")
return parser
@ -27,7 +28,7 @@ if __name__ == '__main__':
questions = None
try:
questions = Questions(args.questions)
questions = Questions(args.questions, appendPath=not args.no_cwd)
except QuestionException as e:
print(str(e), file=sys.stderr)
sys.exit(1)