From c47a8b0f3b373a959acd3fa54a84da93a738d3dd Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 25 Oct 2016 03:09:04 +0000 Subject: [PATCH] Make category-wide puzzles work --- tools/devel-server.py | 10 ++++++---- tools/moth.py | 29 +++++++++++------------------ 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tools/devel-server.py b/tools/devel-server.py index ccffe66..42785c6 100755 --- a/tools/devel-server.py +++ b/tools/devel-server.py @@ -29,15 +29,16 @@ def page(title, body): return """ - {} + {title} +

{title}

- {} + {body}
-""".format(title, body) +""".format(title=title, body=body) def mdpage(body): @@ -132,7 +133,7 @@ you are a fool. if not cat: title = "Puzzle Categories" body.write("") elif not puzzle: @@ -155,6 +156,7 @@ you are a fool. body.write("") body.write("

Answers

") body.write("") diff --git a/tools/moth.py b/tools/moth.py index 6f23652..7b2b526 100644 --- a/tools/moth.py +++ b/tools/moth.py @@ -177,24 +177,16 @@ class Category: self.pointvals = [] self.catmod = None - try: - catmod = SourceFileLoader( + if os.path.exists(os.path.join(path, 'category.py')): + self.catmod = importlib.machinery.SourceFileLoader( 'catmod', os.path.join(path, 'category.py')).load_module() - assert all([ - hasattr(catmod, 'make'), - hasattr(catmod, 'points'), - type(catmod.points) is list, - ]) - self.catmod = catmod - self.pointvals.extend(catmod.points) - except: - pass - - for fpath in glob.glob(os.path.join(path, "[0-9]*")): - pn = os.path.basename(fpath) - points = int(pn) - self.pointvals.append(points) + self.pointvals = self.catmod.points[:] + else: + for fpath in glob.glob(os.path.join(path, "[0-9]*")): + pn = os.path.basename(fpath) + points = int(pn) + self.pointvals.append(points) self.pointvals.sort() @@ -202,8 +194,9 @@ class Category: puzzle = Puzzle(self.seed, points) path = os.path.join(self.path, str(points)) if self.catmod: - self.catmod.make(p, points) - puzzle.read_directory(path) + self.catmod.make(points, puzzle) + else: + puzzle.read_directory(path) return puzzle def puzzles(self):