diff --git a/tools/devel-server.py b/tools/devel-server.py
index 770f5f2..fbf9d46 100755
--- a/tools/devel-server.py
+++ b/tools/devel-server.py
@@ -113,15 +113,22 @@ you are a fool.
path = self.path.rstrip('/')
parts = path.split("/")
title = None
+ fpath = None
+ points = None
cat = None
+ puzzle = None
try:
fpath = os.path.join("puzzles", parts[2])
- cat = moth.Category(path, seed)
- puzzle = cat.puzzle(int(parts[3]))
+ points = int(parts[3])
except:
pass
+ if fpath:
+ cat = moth.Category(fpath, seed)
+ if points:
+ puzzle = cat.puzzle(int(parts[3]))
+
if not cat:
title = "Puzzle Categories"
body.write("
")
@@ -133,26 +140,26 @@ you are a fool.
title = "Puzzles in category `{}`".format(parts[2])
body.write("")
- if len(parts) == 4:
+ elif len(parts) == 4:
# Serve up a puzzle
title = "{} puzzle {}".format(parts[2], parts[3])
- body.write("Author
{}
".format(puzzle.author))
- body.write("Summary
{}
".format(puzzle.summary))
body.write("Body
")
body.write(puzzle.html_body())
+ body.write("Files
")
+ body.write("")
+ for name in puzzle.files:
+ body.write('- {filename}
'
+ .format(cat=parts[2], points=puzzle.points, filename=name))
+ body.write("
")
body.write("Answers
")
body.write("")
for a in puzzle.answers:
body.write("{}
".format(html.escape(a)))
body.write("
")
- body.write("Files
")
- body.write("")
- for f in puzzle.files:
- body.write('- {filename}
'
- .format(cat=parts[2], points=puzzle.points, filename=f.name))
- body.write("
")
+ body.write("Author
{}
".format(puzzle.author))
+ body.write("Summary
{}
".format(puzzle.summary))
body.write("Debug Log
")
body.write('')
for l in puzzle.logs:
@@ -195,7 +202,7 @@ you are a fool.
except OSError:
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
return
- if fspath.endswith(".md"):
+ if path.endswith(".md"):
ctype = "text/html; charset=utf-8"
content = mdpage(payload.decode('utf-8'))
payload = content.encode('utf-8')
diff --git a/tools/moth.py b/tools/moth.py
index bf9281a..6f23652 100644
--- a/tools/moth.py
+++ b/tools/moth.py
@@ -9,6 +9,7 @@ import importlib.machinery
import mistune
import os
import random
+import string
import tempfile
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -124,7 +125,7 @@ class Puzzle:
def random_hash(self):
"""Create a file basename (no extension) with our number generator."""
- return ''.join(self.random.choice(string.ascii_lowercase) for i in range(8))
+ return ''.join(self.rand.choice(string.ascii_lowercase) for i in range(8))
def make_temp_file(self, name=None, visible=True):
"""Get a file object for adding dynamically generated data to the puzzle. When you're
@@ -136,12 +137,14 @@ class Puzzle:
:return: A file object for writing
"""
+ stream = tempfile.TemporaryFile()
+ self.add_stream(stream, name, visible)
+ return stream
+
+ def add_stream(self, stream, name=None, visible=True):
if name is None:
name = self.random_hash()
-
- stream = tempfile.TemporaryFile()
self.files[name] = PuzzleFile(stream, name, visible)
- return stream
def make_answer(self, word_count, sep=' '):
"""Generate and return a new answer. It's automatically added to the puzzle answer list.
@@ -150,7 +153,7 @@ class Puzzle:
:returns: The answer string
"""
- answer = sep.join(self.rand.sample(self.ANSWER_WORDS, word_count))
+ answer = sep.join(self.rand.sample(ANSWER_WORDS, word_count))
self.answers.append(answer)
return answer