Browse Source

Make question media path relative to file

Sebastian Lohff 5 years ago
parent
commit
5e34d4e9b1
2 changed files with 7 additions and 2 deletions
  1. 5
    1
      question.py
  2. 2
    1
      seopardy.py

+ 5
- 1
question.py View File

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

+ 2
- 1
seopardy.py View File

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

Loading…
Cancel
Save