From c12ee422c4b8c2e8cb64f4e77f34a836211284dc Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Mon, 30 Jan 2017 19:13:02 +0000 Subject: [PATCH] multiple author support --- tools/devel-server.py | 2 +- tools/moth.py | 7 +++++-- tools/package-puzzles.py | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/devel-server.py b/tools/devel-server.py index 8ed4b0c..1fca578 100755 --- a/tools/devel-server.py +++ b/tools/devel-server.py @@ -176,7 +176,7 @@ you are a fool. for a in puzzle.answers: body.write("
  • {}
  • ".format(html.escape(a))) body.write("") - body.write("

    Author

    {}

    ".format(puzzle.author)) + body.write("

    Authors

    {}

    ".format(', '.join(puzzle.get_authors()))) body.write("

    Summary

    {}

    ".format(puzzle.summary)) if puzzle.logs: body.write("

    Debug Log

    ") diff --git a/tools/moth.py b/tools/moth.py index 4ff86a8..e29f651 100644 --- a/tools/moth.py +++ b/tools/moth.py @@ -63,8 +63,8 @@ class Puzzle: super().__init__() self.points = points - self.author = None self.summary = None + self.authors = [] self.answers = [] self.files = {} self.body = io.StringIO() @@ -88,7 +88,7 @@ class Puzzle: key = key.lower() val = val.strip() if key == 'author': - self.author = val + self.authors.append(val) elif key == 'summary': self.summary = val elif key == 'answer': @@ -234,6 +234,9 @@ class Puzzle: self.body.write('{:08x}\n'.format(offset)) self.body.write('') + def get_authors(self): + return self.authors or [self.author] + def get_body(self): return self.body.getvalue() diff --git a/tools/package-puzzles.py b/tools/package-puzzles.py index db4cc61..f4980a1 100755 --- a/tools/package-puzzles.py +++ b/tools/package-puzzles.py @@ -35,7 +35,7 @@ def write_kv_pairs(ziphandle, filename, kv): def escape(s): return s.replace('&', '&').replace('<', '<').replace('>', '>') -def generate_html(ziphandle, puzzle, puzzledir, category, points, author, files): +def generate_html(ziphandle, puzzle, puzzledir, category, points, authors, files): html_content = io.StringIO() file_content = io.StringIO() if files: @@ -73,14 +73,14 @@ def generate_html(ziphandle, puzzle, puzzledir, category, points, author, files) -
    Puzzle by {author}
    +
    Puzzle by {authors}
    Los Alamos National Laboratory US Department Of Energy Sandia National Laboratories
    -'''.format(category=category, points=points, body=puzzle.html_body(), file_content=file_content.getvalue(), author=author)) +'''.format(category=category, points=points, body=puzzle.html_body(), file_content=file_content.getvalue(), authors=', '.join(authors))) ziphandle.writestr(os.path.join(puzzledir, 'index.html'), html_content.getvalue()) def build_category(categorydir, outdir): @@ -132,14 +132,14 @@ def build_category(categorydir, outdir): zf.writestr(os.path.join(puzzledir, fn), payload) puzzledict = { - 'author': puzzle.author, + 'authors': puzzle.authors, 'hashes': puzzle.hashes(), 'files': files, 'body': puzzle.html_body(), } puzzlejson = json.dumps(puzzledict) zf.writestr(os.path.join(puzzledir, 'puzzle.json'), puzzlejson) - generate_html(zf, puzzle, puzzledir, categoryname, puzzle.points, puzzle.author, files) + generate_html(zf, puzzle, puzzledir, categoryname, puzzle.points, puzzle.get_authors(), files) write_kv_pairs(zf, 'map.txt', mapping) write_kv_pairs(zf, 'answers.txt', answers)