mirror of https://github.com/dirtbags/moth.git
Make it work with whatever version of Python I'm running here
This commit is contained in:
parent
f6d1dc741c
commit
cf241b7a0e
|
@ -98,7 +98,7 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
if not p.is_dir() or p.match(".*"):
|
if not p.is_dir() or p.match(".*"):
|
||||||
continue
|
continue
|
||||||
catName = p.parts[-1]
|
catName = p.parts[-1]
|
||||||
cat = moth.Category(str(p), self.seed)
|
cat = moth.Category(p, self.seed)
|
||||||
puzzles[catName] = [[i, str(i)] for i in cat.pointvals()]
|
puzzles[catName] = [[i, str(i)] for i in cat.pointvals()]
|
||||||
puzzles[catName].append([0, ""])
|
puzzles[catName].append([0, ""])
|
||||||
if len(puzzles) <= 1:
|
if len(puzzles) <= 1:
|
||||||
|
@ -157,7 +157,7 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-Type", "text/html; charset=\"utf-8\"")
|
self.send_header("Content-Type", "text/html; charset=\"utf-8\"")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(cgitb.html(sys.exc_info()))
|
self.wfile.write(bytes(cgitb.html(sys.exc_info()), "utf-8"))
|
||||||
return
|
return
|
||||||
|
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import string
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import shlex
|
import shlex
|
||||||
|
import pathlib
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
@ -55,7 +56,7 @@ def pushd(newdir):
|
||||||
|
|
||||||
|
|
||||||
def loadmod(name, path):
|
def loadmod(name, path):
|
||||||
abspath = os.path.abspath(path)
|
abspath = str(path.resolve())
|
||||||
loader = importlib.machinery.SourceFileLoader(name, abspath)
|
loader = importlib.machinery.SourceFileLoader(name, abspath)
|
||||||
return loader.load_module()
|
return loader.load_module()
|
||||||
|
|
||||||
|
@ -298,8 +299,9 @@ class Puzzle:
|
||||||
|
|
||||||
|
|
||||||
def read_directory(self, path):
|
def read_directory(self, path):
|
||||||
|
path = pathlib.Path(path)
|
||||||
try:
|
try:
|
||||||
puzzle_mod = loadmod("puzzle", os.path.join(path, "puzzle.py"))
|
puzzle_mod = loadmod("puzzle", path / "puzzle.py")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
puzzle_mod = None
|
puzzle_mod = None
|
||||||
|
|
||||||
|
@ -467,12 +469,12 @@ class Puzzle:
|
||||||
|
|
||||||
class Category:
|
class Category:
|
||||||
def __init__(self, path, seed):
|
def __init__(self, path, seed):
|
||||||
self.path = path
|
self.path = pathlib.Path(path)
|
||||||
self.seed = seed
|
self.seed = seed
|
||||||
self.catmod = None
|
self.catmod = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.catmod = loadmod('category', os.path.join(path, 'category.py'))
|
self.catmod = loadmod('category', self.path / 'category.py')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.catmod = None
|
self.catmod = None
|
||||||
|
|
||||||
|
@ -482,15 +484,14 @@ class Category:
|
||||||
pointvals = self.catmod.pointvals()
|
pointvals = self.catmod.pointvals()
|
||||||
else:
|
else:
|
||||||
pointvals = []
|
pointvals = []
|
||||||
for fpath in glob.glob(os.path.join(self.path, "[0-9]*")):
|
for fpath in self.path.glob("[0-9]*"):
|
||||||
pn = os.path.basename(fpath)
|
points = int(fpath.name)
|
||||||
points = int(pn)
|
|
||||||
pointvals.append(points)
|
pointvals.append(points)
|
||||||
return sorted(pointvals)
|
return sorted(pointvals)
|
||||||
|
|
||||||
def puzzle(self, points):
|
def puzzle(self, points):
|
||||||
puzzle = Puzzle(self.seed, points)
|
puzzle = Puzzle(self.seed, points)
|
||||||
path = os.path.join(self.path, str(points))
|
path = self.path / str(points)
|
||||||
if self.catmod:
|
if self.catmod:
|
||||||
with pushd(self.path):
|
with pushd(self.path):
|
||||||
self.catmod.make(points, puzzle)
|
self.catmod.make(points, puzzle)
|
||||||
|
|
Loading…
Reference in New Issue