Merge branch 'v3.5_devel' of https://github.com/dirtbags/moth into add_contributing_document

This commit is contained in:
John Donaldson 2020-02-21 18:33:34 +00:00
commit 0d5abcc97a
5 changed files with 28 additions and 0 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- URL parameter to points.json to allow returning only the JSON for a single - 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). team by its team id (e.g., points.json?id=abc123).
- A CONTRIBUTING.md to describe expectations when contributing to MOTH - A CONTRIBUTING.md to describe expectations when contributing to MOTH
- Include basic metadata in mothballs
### Fixed ### Fixed
- Handle cases where non-legacy puzzles don't have an `author` attribute - Handle cases where non-legacy puzzles don't have an `author` attribute
- Handle YAML-formatted file and script lists as expected - Handle YAML-formatted file and script lists as expected

View File

@ -17,6 +17,7 @@ COPY devel /app/
COPY example-puzzles /puzzles/ COPY example-puzzles /puzzles/
COPY theme /theme/ COPY theme /theme/
COPY LICENSE.md /LICENSE COPY LICENSE.md /LICENSE
COPY VERSION /VERSION
ENTRYPOINT [ "python3", "/app/devel-server.py" ] ENTRYPOINT [ "python3", "/app/devel-server.py" ]
CMD [ "--bind", "0.0.0.0:8080", "--puzzles", "/puzzles", "--theme", "/theme" ] CMD [ "--bind", "0.0.0.0:8080", "--puzzles", "/puzzles", "--theme", "/theme" ]

View File

@ -118,6 +118,7 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler):
obj["hint"] = puzzle.hint obj["hint"] = puzzle.hint
obj["summary"] = puzzle.summary obj["summary"] = puzzle.summary
obj["logs"] = puzzle.logs obj["logs"] = puzzle.logs
obj["format"] = puzzle._source_format
self.send_response(200) self.send_response(200)
self.send_header("Content-Type", "application/json") self.send_header("Content-Type", "application/json")

View File

@ -123,6 +123,8 @@ class Puzzle:
super().__init__() super().__init__()
self._source_format = "py"
self.points = points self.points = points
self.summary = None self.summary = None
self.authors = [] self.authors = []
@ -153,8 +155,10 @@ class Puzzle:
line = "" line = ""
if stream.read(3) == "---": if stream.read(3) == "---":
header = "yaml" header = "yaml"
self._source_format = "yaml"
else: else:
header = "moth" header = "moth"
self._source_format = "moth"
stream.seek(0) stream.seek(0)

View File

@ -2,12 +2,14 @@
import argparse import argparse
import binascii import binascii
import datetime
import hashlib import hashlib
import io import io
import json import json
import logging import logging
import moth import moth
import os import os
import platform
import shutil import shutil
import tempfile import tempfile
import zipfile import zipfile
@ -61,6 +63,24 @@ def build_category(categorydir, outdir):
zipfileraw.close() zipfileraw.close()
shutil.move(zipfileraw.name, zipfilename) shutil.move(zipfileraw.name, zipfilename)
def write_metadata(ziphandle, category):
metadata = {"platform": {}, "moth": {}, "category": {}}
try:
with open("../VERSION", "r") as infile:
version = infile.read().strip()
metadata["moth"]["version"] = version
except IOError:
pass
metadata["category"]["build_time"] = datetime.datetime.now().strftime("%c")
metadata["category"]["type"] = "catmod" if category.catmod is not None else "traditional"
metadata["platform"]["arch"] = platform.machine()
metadata["platform"]["os"] = platform.system()
metadata["platform"]["version"] = platform.platform()
metadata["platform"]["python_version"] = platform.python_version()
ziphandle.writestr("meta.json", json.dumps(metadata))
# Returns a file-like object containing the contents of the new zip file # Returns a file-like object containing the contents of the new zip file
def package(categoryname, categorydir, seed): def package(categoryname, categorydir, seed):
@ -94,6 +114,7 @@ def package(categoryname, categorydir, seed):
write_kv_pairs(zf, 'map.txt', mapping) write_kv_pairs(zf, 'map.txt', mapping)
write_kv_pairs(zf, 'answers.txt', answers) write_kv_pairs(zf, 'answers.txt', answers)
write_kv_pairs(zf, 'summaries.txt', summary) write_kv_pairs(zf, 'summaries.txt', summary)
write_metadata(zf, cat)
# clean up # clean up
zf.close() zf.close()