From 761811d71b734003d53afe07d2a85cd70eeb5708 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 20 Nov 2019 16:23:01 -0800 Subject: [PATCH 01/10] Make top-scoring team take full width --- theme/scoreboard.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/theme/scoreboard.js b/theme/scoreboard.js index 8aa8e98..0c4d836 100644 --- a/theme/scoreboard.js +++ b/theme/scoreboard.js @@ -111,11 +111,15 @@ function scoreboardInit() { } winners.sort(teamCompare) winners.reverse() + + // Let's make some better names for things we've computed + let winningScore = winners[0].overallScore + let numCategories = Object.keys(highestCategoryScore).length // Clear out the element we're about to populate Array.from(element.childNodes).map(e => e.remove()) - let maxWidth = 100 / Object.keys(highestCategoryScore).length + let maxWidth = 100 / winningScore for (let team of winners) { let row = document.createElement("div") let ncat = 0 @@ -125,8 +129,6 @@ function scoreboardInit() { let catPct = catTeam / catHigh let width = maxWidth * catPct - console.log(catHigh, catTeam, catPct) - let bar = document.createElement("span") bar.classList.add("category") bar.classList.add("cat" + ncat) From acbd009136d780671098c89a231a82d7b08ff450 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Wed, 20 Nov 2019 18:29:44 -0600 Subject: [PATCH 02/10] Made to-scoring teams full-width --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b37b48..8765bfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Made top-scoring teams full-width ## [3.4.2] - 2019-11-18 ### Fixed From 07b4bd110107c19d7d25ad7849694818a8de54d1 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Wed, 20 Nov 2019 18:30:48 -0600 Subject: [PATCH 03/10] Releasing v3.4.3 --- CHANGELOG.md | 2 ++ VERSION | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8765bfa..c99e9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [3.4.3] - 2019-11-20 ### Fixed - Made top-scoring teams full-width diff --git a/VERSION b/VERSION index 4d9d11c..6cb9d3d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.4.2 +3.4.3 From aa5150f5421178c65f7486207636a8003f1fa116 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Wed, 18 Dec 2019 22:30:08 +0000 Subject: [PATCH 04/10] Fixing a devel server path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99549f0..1cfbfc8 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ you can copy the example puzzles as a starting point: Then launch the development server: - $ python3 tools/devel-server.py + $ python3 devel/devel-server.py Point a web browser at http://localhost:8080/ and start hacking on things in your `puzzles` directory. From da48c69551741a395bffd935fc4d04651407c163 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Wed, 18 Dec 2019 22:32:28 +0000 Subject: [PATCH 05/10] Adding dependencies into devel instructions --- docs/devel-server.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/devel-server.md b/docs/devel-server.md index bc05d3a..2ae34c8 100644 --- a/docs/devel-server.md +++ b/docs/devel-server.md @@ -28,6 +28,7 @@ If you can't use docker, try this: apt install python3 + pip3 install scapy pillow PyYAML git clone https://github.com/dirtbags/moth/ cd moth python3 devel/devel-server.py --puzzles example-puzzles From 9447d4e3de759dae7692b4d9e2f39433c3752a12 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Jan 2020 08:26:22 -0700 Subject: [PATCH 06/10] Add a MIME-type for .mjs files --- devel/devel-server.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index 0d775dc..31e6f12 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 -import asyncio import cgitb import html import cgi @@ -42,7 +41,15 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler): super().__init__(request, client_address, server, directory=server.args["theme_dir"]) except TypeError: super().__init__(request, client_address, server) + # Why can't they just use mimetypes?! + # Why isn't this the default?! + def guess_type(self, path): + mtype, encoding = mimetypes.guess_type(path) + if encoding: + return "%s; encoding=%s" % (mtype, encoding) + else: + return mtype # Backport from Python 3.7 def translate_path(self, path): @@ -285,10 +292,13 @@ if __name__ == '__main__': logging.basicConfig(level=log_level) + mimetypes.add_type("application/javascript", ".mjs") + server = MothServer((addr, port), MothRequestHandler) server.args["base_url"] = args.base server.args["puzzles_dir"] = pathlib.Path(args.puzzles) server.args["theme_dir"] = args.theme + logging.info("Listening on %s:%d", addr, port) server.serve_forever() From d3389d5bf127a56efeb48efa665802ab2bb170d3 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Jan 2020 08:29:08 -0700 Subject: [PATCH 07/10] Remove superfluous comment --- devel/devel-server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index 31e6f12..fd53d12 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -41,7 +41,6 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler): super().__init__(request, client_address, server, directory=server.args["theme_dir"]) except TypeError: super().__init__(request, client_address, server) - # Why can't they just use mimetypes?! # Why isn't this the default?! def guess_type(self, path): From f643f7b754e0dbcd176dcfbb6ead9dbedad8e203 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 21 Jan 2020 08:29:25 -0700 Subject: [PATCH 08/10] Remove superfluous newline --- devel/devel-server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index fd53d12..7d7b505 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -297,7 +297,6 @@ if __name__ == '__main__': server.args["base_url"] = args.base server.args["puzzles_dir"] = pathlib.Path(args.puzzles) server.args["theme_dir"] = args.theme - logging.info("Listening on %s:%d", addr, port) server.serve_forever() From d6818dc4090dbe52b7946f9d8f615797654c8a62 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Wed, 29 Jan 2020 20:30:55 +0000 Subject: [PATCH 09/10] 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 10/10] 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":