diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-12-24 18:12:56 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-12-24 18:12:56 +0100 |
| commit | 19f7f50dd3863881591e639ec724457b4c6fbc08 (patch) | |
| tree | 7adda9e8096c2ba90d6404604d649243964ca58d /quiz.py | |
| parent | 9e281b4cc42a5aa935d694364dffb3b728a0ba16 (diff) | |
| download | quiz-19f7f50dd3863881591e639ec724457b4c6fbc08.tar.gz quiz-19f7f50dd3863881591e639ec724457b4c6fbc08.zip | |
add support for an exclude file
Diffstat (limited to 'quiz.py')
| -rwxr-xr-x | quiz.py | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -67,6 +67,16 @@ def possible_questions(question_dirs: list[Path], match='*') -> list[Path]: return questions +def exclude_questions(questions: list[Path], + excludes_file_path: str) -> list[Path]: + """exclude all paths in excludes_file from the questions""" + + with open(excludes_file_path, 'r', encoding='utf-8') as excludes_file: + excludes = [l[:-1] for l in excludes_file.readlines()] + + return [q for q in questions if q.name not in excludes] + + def read_solutions_from_toml(solution_path: Path, selector='') -> dict[str, str]: """return solutions from a toml solutions file @@ -195,6 +205,9 @@ def main(): parser.add_argument('-s', '--solution-file', help='file containing the solutions') + parser.add_argument('-x', + '--excludes-file', + help='file containing the questions to exclude') parser.add_argument( '--select', help='selector string to identify a subset of solutions') parser.add_argument('--question-match', @@ -208,6 +221,9 @@ def main(): question_dirs = [Path(p) for p in args.question_dir or ['.']] questions = possible_questions(question_dirs, match=args.question_match) + if args.excludes_file: + questions = exclude_questions(questions, args.excludes_file) + solution_files = [] if args.solution_file: solution_files.append(Path(args.solution_file)) |
