diff --git a/Dockerfile.moth-devel b/Dockerfile.moth-devel index bf5cf4f..4d5f214 100644 --- a/Dockerfile.moth-devel +++ b/Dockerfile.moth-devel @@ -1,5 +1,8 @@ FROM alpine +ARG http_proxy +ENV http_proxy=${http_proxy} + RUN apk --no-cache add python3 py3-pillow COPY tools/devel-server.py /moth/ diff --git a/tools/devel-server.py b/tools/devel-server.py index aa69535..fdda12f 100755 --- a/tools/devel-server.py +++ b/tools/devel-server.py @@ -31,12 +31,13 @@ sys.dont_write_bytecode = True # XXX: This will eventually cause a problem. Do something more clever here. seed = 1 -def page(title, body): +def page(title, body, scripts=[]): return """ {title} + {scripts}

{title}

@@ -44,17 +45,21 @@ def page(title, body): {body} -""".format(title=title, body=body) +""".format( + title=title, + body=body, + scripts="\n".join(''.format(s) for s in scripts), + ) -def mdpage(body): +def mdpage(body, scripts=[]): try: title, _ = body.split('\n', 1) except ValueError: title = "Result" title = title.lstrip("#") title = title.strip() - return page(title, mistune.markdown(body, escape=False)) + return page(title, mistune.markdown(body, escape=False), scripts=scripts) # XXX: What horrors did we unleash with our chdir shenanigans that @@ -123,6 +128,7 @@ you are a fool. body = io.StringIO() path = self.path.rstrip('/') parts = path.split("/") + scripts = [] title = None fpath = None points = None @@ -156,6 +162,7 @@ you are a fool. body.write("") elif len(parts) == 4: # Serve up a puzzle + scripts = puzzle.scripts title = "{} puzzle {}".format(parts[2], parts[3]) body.write("

Body

") body.write(puzzle.html_body()) @@ -200,7 +207,7 @@ you are a fool. shutil.copyfileobj(pfile.stream, self.wfile) return - payload = page(title, body.getvalue()).encode('utf-8') + payload = page(title, body.getvalue(), scripts=scripts).encode('utf-8') self.send_response(HTTPStatus.OK) self.send_header("Content-Type", "text/html; charset=utf-8") self.send_header("Content-Length", len(payload)) diff --git a/tools/moth.py b/tools/moth.py index d15dac3..07986b0 100644 --- a/tools/moth.py +++ b/tools/moth.py @@ -73,6 +73,7 @@ class Puzzle: self.summary = None self.authors = [] self.answers = [] + self.scripts = [] self.files = {} self.body = io.StringIO() self.logs = [] @@ -112,6 +113,11 @@ class Puzzle: except IndexError: pass self.files[name] = PuzzleFile(stream, name, not hidden) + 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) else: raise ValueError("Unrecognized header field: {}".format(key)) else: diff --git a/tools/package-puzzles.py b/tools/package-puzzles.py index 79b74cf..35b2b3a 100755 --- a/tools/package-puzzles.py +++ b/tools/package-puzzles.py @@ -50,6 +50,7 @@ def generate_html(ziphandle, puzzle, puzzledir, category, points, authors, files ''' ''') + scripts = [''.format(s) for s in puzzle.scripts] html_content.write( ''' @@ -59,6 +60,7 @@ def generate_html(ziphandle, puzzle, puzzledir, category, points, authors, files {category} {points} + {scripts}

{category} for {points} points

@@ -80,7 +82,14 @@ def generate_html(ziphandle, puzzle, puzzledir, category, points, authors, files Sandia National Laboratories -'''.format(category=category, points=points, body=puzzle.html_body(), file_content=file_content.getvalue(), authors=', '.join(authors))) +'''.format( + category=category, + points=points, + body=puzzle.html_body(), + file_content=file_content.getvalue(), + authors=', '.join(authors)), + scripts='\n'.join(scripts), + ) ziphandle.writestr(os.path.join(puzzledir, 'index.html'), html_content.getvalue()) def build_category(categorydir, outdir): @@ -151,7 +160,7 @@ def build_category(categorydir, outdir): shutil.move(zipfileraw.name, zipfilename) -if __name__ == '__main__': +if __name__ == '__main__': parser = argparse.ArgumentParser(description='Build a category package') parser.add_argument('outdir', help='Output directory') parser.add_argument('categorydirs', nargs='+', help='Directory of category source')