New (backwards compatible) round file format
This commit is contained in:
parent
c9dc16d634
commit
d4255a7971
35
question.py
35
question.py
|
@ -108,19 +108,39 @@ class Questions(object):
|
|||
|
||||
# read sections
|
||||
basedir = os.path.dirname(filename)
|
||||
for n, sec_filename in enumerate(ysrc["Sections"], 1):
|
||||
if type(sec_filename) not in (unicode, str):
|
||||
self._gen_error(filename, "Section element %d is not a string (type %s found)" % (n, type(sec_filename)))
|
||||
for n, sec_data in enumerate(ysrc["Sections"], 1):
|
||||
jeopardyOverride = None
|
||||
if type(sec_data) not in (unicode, str, dict):
|
||||
self._gen_error(filename, "Section element %d is neither a string nor a dict (type %s found)" % (n, type(sec_data)))
|
||||
|
||||
sec_filename = None
|
||||
if type(sec_data) == dict:
|
||||
if "File" not in sec_data:
|
||||
self._gen_error(filename, "Section element %d is a dictionary, but has no key 'File' pointing to a file to load" % (n,))
|
||||
|
||||
sec_filename = sec_data["File"]
|
||||
|
||||
if "Double-Jeopardies" in sec_data and sec_data["Double-Jeopardies"] != None:
|
||||
# TODO: load (override) double jeopardies for section
|
||||
if type(sec_data["Double-Jeopardies"]) != list:
|
||||
self._gen_error(filename, "Section %d: Double-Jeopardies has to be a list or null (type %s found)" % (n, type(sec_data["Double-Jeopardies"])))
|
||||
|
||||
# take care that jeopardyOverride is a list of 5 bools
|
||||
jeopardyOverride = map(bool, sec_data["Double-Jeopardies"])
|
||||
jeopardyOverride = jeopardyOverride[0:5]
|
||||
while len(jeopardyOverride) < 5:
|
||||
jeopardyOverride.append(False)
|
||||
else:
|
||||
sec_filename = sec_data
|
||||
fpath = os.path.join(basedir, sec_filename)
|
||||
sec_ysrc = None
|
||||
try:
|
||||
sec_ysrc = self._get_yaml(fpath)
|
||||
except (OSError, IOError) as e:
|
||||
raise QuestionException("Error reading question file %s: %s" % (fpath, str(e)))
|
||||
self._read_sections(sec_ysrc, fpath)
|
||||
self._read_sections(sec_ysrc, fpath, jeopardyOverride)
|
||||
|
||||
def _read_sections(self, ysrc, filename):
|
||||
def _read_sections(self, ysrc, filename, jeopardyOverride=None):
|
||||
basedir = os.path.dirname(filename)
|
||||
|
||||
# now to check the integrity of the question file
|
||||
|
@ -147,11 +167,16 @@ class Questions(object):
|
|||
self._gen_error(filename, "Qestion %d from section %d (%s) has invalid keyword '%s'" % (j, i, sec["Section"], key))
|
||||
|
||||
# check Double-Jeopardy is a bool and is set to false if non-existant
|
||||
|
||||
if "Double-Jeopardy" not in q.keys():
|
||||
q["Double-Jeopardy"] = False
|
||||
elif type(q["Double-Jeopardy"]) != bool:
|
||||
self._gen_error(filename, "The Double-Jeopardy key from question %d from section %d (%s) must be either true or false" % (j, i, sec["Section"]))
|
||||
|
||||
# handle Double-Jeopardy override by round file
|
||||
if jeopardyOverride:
|
||||
q["Double-Jeopardy"] = jeopardyOverride[i-1]
|
||||
|
||||
# check Audio is a bool and is set to false if non-existant
|
||||
if "Audio" not in q.keys():
|
||||
q["Audio"] = False
|
||||
|
|
Loading…
Reference in New Issue