diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-09-13 17:31:07 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-09-13 17:31:07 +0200 |
| commit | 5111362f0e0201f6b260ed23e4f71c0bfa8dfdf4 (patch) | |
| tree | 501b8466be6b5762dc4d4ffcf760bb2cc2e59ef2 | |
| parent | dc8f4ffd41fa854d18bec424dfffa379156e9b34 (diff) | |
| download | quiz-5111362f0e0201f6b260ed23e4f71c0bfa8dfdf4.tar.gz quiz-5111362f0e0201f6b260ed23e4f71c0bfa8dfdf4.zip | |
add a file name filter option for matching questions
| -rwxr-xr-x | quiz.py | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -14,6 +14,7 @@ import argparse import csv +import fnmatch from pathlib import Path import random import platform @@ -50,8 +51,8 @@ def terminate_subprocesses(): proc.kill() -def possible_questions(question_dirs: list[Path]) -> list[Path]: - """return all file in the question directories""" +def possible_questions(question_dirs: list[Path], match='*') -> list[Path]: + """return all files in the question directories""" questions = [] ignored_file_names = [Path(__file__).name, 'solutions'] for question_dir in question_dirs: @@ -60,7 +61,7 @@ def possible_questions(question_dirs: list[Path]) -> list[Path]: questions.extend([ p for p in question_dir.iterdir() if p.is_file() - if p.name not in ignored_file_names + if p.name not in ignored_file_names and fnmatch.fnmatch(p, match) ]) return questions @@ -196,10 +197,13 @@ def main(): help='file containing the solutions') parser.add_argument( '--select', help='selector string to identify a subset of solutions') + parser.add_argument('--question-match', + help='match question files names', + default='*') args = parser.parse_args() question_dirs = [Path(p) for p in args.question_dir or ['.']] - questions = possible_questions(question_dirs) + questions = possible_questions(question_dirs, match=args.question_match) solution_files = [] if args.solution_file: |
