aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2024-09-10 13:56:05 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2024-09-10 13:56:05 +0200
commiteeee3bdc4f71f8d47fd70a0906fa6b82b64e41c7 (patch)
treee5332d2f8400d8f5db820e3cebf1faba1c104768
parent55e6421b012c3ad6ef97e5c632506fdc445d6067 (diff)
downloadquiz-eeee3bdc4f71f8d47fd70a0906fa6b82b64e41c7.tar.gz
quiz-eeee3bdc4f71f8d47fd70a0906fa6b82b64e41c7.zip
support question order defined in the solutions file
-rwxr-xr-xquiz.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/quiz.py b/quiz.py
index a0d83ac..4ee72e8 100755
--- a/quiz.py
+++ b/quiz.py
@@ -217,10 +217,12 @@ def main():
parser.add_argument('--answers',
help='match question files names',
nargs='*')
- parser.add_argument('-nr',
- '--no-random',
- help='Do not randomize questions',
- action='store_true')
+ parser.add_argument('--sort',
+ default='random',
+ const='random',
+ nargs='?',
+ choices=['random', 'filename', 'solutions'])
+
args = parser.parse_args()
question_dirs = [Path(p) for p in args.question_dir or ['.']]
@@ -228,7 +230,7 @@ def main():
if args.excludes_file:
questions = exclude_questions(questions, args.excludes_file)
- if args.no_random:
+ if args.sort == 'filename':
questions.sort()
solution_files = []
@@ -239,9 +241,21 @@ def main():
solutions = load_solutions(question_dirs, solution_files, args.select)
+ # Sort the questions acording to the loaded solutions
+ if args.sort == 'solutions':
+ sorted_questions = []
+ for s in solutions.keys():
+ key = Path(s).stem
+ for q in questions:
+ if q.stem == key:
+ sorted_questions.append(q)
+ continue
+
+ questions = sorted_questions
+
solved = []
while questions:
- if args.no_random:
+ if args.sort != 'random':
next_question = questions[0]
else:
next_question = random.choice(questions)