mirror of https://github.com/dirtbags/moth.git
further debugging; now appears to work properly
This commit is contained in:
parent
6c028ffa29
commit
1558c67dd5
|
@ -113,15 +113,22 @@ you are a fool.
|
||||||
path = self.path.rstrip('/')
|
path = self.path.rstrip('/')
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
title = None
|
title = None
|
||||||
|
fpath = None
|
||||||
|
points = None
|
||||||
cat = None
|
cat = None
|
||||||
|
puzzle = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fpath = os.path.join("puzzles", parts[2])
|
fpath = os.path.join("puzzles", parts[2])
|
||||||
cat = moth.Category(path, seed)
|
points = int(parts[3])
|
||||||
puzzle = cat.puzzle(int(parts[3]))
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if fpath:
|
||||||
|
cat = moth.Category(fpath, seed)
|
||||||
|
if points:
|
||||||
|
puzzle = cat.puzzle(int(parts[3]))
|
||||||
|
|
||||||
if not cat:
|
if not cat:
|
||||||
title = "Puzzle Categories"
|
title = "Puzzle Categories"
|
||||||
body.write("<ul>")
|
body.write("<ul>")
|
||||||
|
@ -133,26 +140,26 @@ you are a fool.
|
||||||
title = "Puzzles in category `{}`".format(parts[2])
|
title = "Puzzles in category `{}`".format(parts[2])
|
||||||
body.write("<ul>")
|
body.write("<ul>")
|
||||||
for points in cat.pointvals:
|
for points in cat.pointvals:
|
||||||
body.write('<li><a href="/puzzles/{cat}{points}">puzzles/{cat}{points}</a></li>'.format(cat=parts[2], points=points))
|
body.write('<li><a href="/puzzles/{cat}/{points}">puzzles/{cat}/{points}</a></li>'.format(cat=parts[2], points=points))
|
||||||
body.write("</ul>")
|
body.write("</ul>")
|
||||||
if len(parts) == 4:
|
elif len(parts) == 4:
|
||||||
# Serve up a puzzle
|
# Serve up a puzzle
|
||||||
title = "{} puzzle {}".format(parts[2], parts[3])
|
title = "{} puzzle {}".format(parts[2], parts[3])
|
||||||
body.write("<h2>Author</h2><p>{}</p>".format(puzzle.author))
|
|
||||||
body.write("<h2>Summary</h2><p>{}</p>".format(puzzle.summary))
|
|
||||||
body.write("<h2>Body</h2>")
|
body.write("<h2>Body</h2>")
|
||||||
body.write(puzzle.html_body())
|
body.write(puzzle.html_body())
|
||||||
|
body.write("<h2>Files</h2>")
|
||||||
|
body.write("<ul>")
|
||||||
|
for name in puzzle.files:
|
||||||
|
body.write('<li><a href="/{cat}/{points}/{filename}">{filename}</a></li>'
|
||||||
|
.format(cat=parts[2], points=puzzle.points, filename=name))
|
||||||
|
body.write("</ul>")
|
||||||
body.write("<h2>Answers</h2>")
|
body.write("<h2>Answers</h2>")
|
||||||
body.write("<ul>")
|
body.write("<ul>")
|
||||||
for a in puzzle.answers:
|
for a in puzzle.answers:
|
||||||
body.write("<li><code>{}</code></li>".format(html.escape(a)))
|
body.write("<li><code>{}</code></li>".format(html.escape(a)))
|
||||||
body.write("</ul>")
|
body.write("</ul>")
|
||||||
body.write("<h2>Files</h2>")
|
body.write("<h2>Author</h2><p>{}</p>".format(puzzle.author))
|
||||||
body.write("<ul>")
|
body.write("<h2>Summary</h2><p>{}</p>".format(puzzle.summary))
|
||||||
for f in puzzle.files:
|
|
||||||
body.write('<li><a href="/{cat}/{points}/{filename}">{filename}</a></li>'
|
|
||||||
.format(cat=parts[2], points=puzzle.points, filename=f.name))
|
|
||||||
body.write("</ul>")
|
|
||||||
body.write("<h2>Debug Log</h2>")
|
body.write("<h2>Debug Log</h2>")
|
||||||
body.write('<ul class="log">')
|
body.write('<ul class="log">')
|
||||||
for l in puzzle.logs:
|
for l in puzzle.logs:
|
||||||
|
@ -195,7 +202,7 @@ you are a fool.
|
||||||
except OSError:
|
except OSError:
|
||||||
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
|
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
|
||||||
return
|
return
|
||||||
if fspath.endswith(".md"):
|
if path.endswith(".md"):
|
||||||
ctype = "text/html; charset=utf-8"
|
ctype = "text/html; charset=utf-8"
|
||||||
content = mdpage(payload.decode('utf-8'))
|
content = mdpage(payload.decode('utf-8'))
|
||||||
payload = content.encode('utf-8')
|
payload = content.encode('utf-8')
|
||||||
|
|
|
@ -9,6 +9,7 @@ import importlib.machinery
|
||||||
import mistune
|
import mistune
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import string
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
@ -124,7 +125,7 @@ class Puzzle:
|
||||||
|
|
||||||
def random_hash(self):
|
def random_hash(self):
|
||||||
"""Create a file basename (no extension) with our number generator."""
|
"""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):
|
def make_temp_file(self, name=None, visible=True):
|
||||||
"""Get a file object for adding dynamically generated data to the puzzle. When you're
|
"""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
|
: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:
|
if name is None:
|
||||||
name = self.random_hash()
|
name = self.random_hash()
|
||||||
|
|
||||||
stream = tempfile.TemporaryFile()
|
|
||||||
self.files[name] = PuzzleFile(stream, name, visible)
|
self.files[name] = PuzzleFile(stream, name, visible)
|
||||||
return stream
|
|
||||||
|
|
||||||
def make_answer(self, word_count, sep=' '):
|
def make_answer(self, word_count, sep=' '):
|
||||||
"""Generate and return a new answer. It's automatically added to the puzzle answer list.
|
"""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
|
: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)
|
self.answers.append(answer)
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue