From d6818dc4090dbe52b7946f9d8f615797654c8a62 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Wed, 29 Jan 2020 20:30:55 +0000 Subject: [PATCH 1/2] Fixing issue with detecting which authors/author field to use --- CHANGELOG.md | 2 ++ devel/moth.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf17fc..1ad1b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - URL parameter to points.json to allow returning only the JSON for a single team by its team id (e.g., points.json?id=abc123). +### Fixed +- Handle cases where non-legacy puzzles don't have an `author` attribute ## [3.4.3] - 2019-11-20 ### Fixed diff --git a/devel/moth.py b/devel/moth.py index d228b72..886ea14 100644 --- a/devel/moth.py +++ b/devel/moth.py @@ -384,7 +384,12 @@ class Puzzle: self.body.write('') def get_authors(self): - return self.authors or [self.author] + if len(self.authors) > 0: + return self.authors + elif hasattr(self, "author"): + return [self.author] + else: + return [] def get_body(self): return self.body.getvalue() From 3bd34ec5b5943430d0c08701dfe4498d08a7ef31 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Wed, 29 Jan 2020 22:21:58 +0000 Subject: [PATCH 2/2] Fixed handling of multiple files and scripts in YAML-formatted puzzles --- CHANGELOG.md | 3 +++ devel/moth.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf17fc..974ffbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - URL parameter to points.json to allow returning only the JSON for a single team by its team id (e.g., points.json?id=abc123). +### Fixed +- Handle YAML-formatted file and script lists as expected +- YAML-formatted example puzzle actually works as expected ## [3.4.3] - 2019-11-20 ### Fixed diff --git a/devel/moth.py b/devel/moth.py index d228b72..dc61727 100644 --- a/devel/moth.py +++ b/devel/moth.py @@ -233,11 +233,39 @@ class Puzzle: except IndexError: pass self.files[name] = PuzzleFile(stream, name, not hidden) + + elif key == 'files' and isinstance(val, dict): + for filename, options in val.items(): + if "source" in options: + source = options["source"] + else: + source = filename + + if "hidden" in options and options["hidden"]: + hidden = True + else: + hidden = False + + stream = open(source, "rb") + self.files[filename] = PuzzleFile(stream, filename, not hidden) + + elif key == 'files' and isinstance(val, list): + for filename in val: + stream = open(filename, "rb") + self.files[filename] = PuzzleFile(stream, filename) + elif key == 'script': stream = open(val, 'rb') # Make sure this shows up in the header block of the HTML output. self.files[val] = PuzzleFile(stream, val, visible=False) self.scripts.append(val) + + elif key == "scripts" and isinstance(val, list): + for script in val: + stream = open(script, "rb") + self.files[script] = PuzzleFile(stream, script, visible=False) + self.scripts.append(script) + elif key == "objective": self.objective = val elif key == "success":