more versatile logging, chdir into puzzle directory when loading category.py

This commit is contained in:
Neale Pickett 2017-01-31 17:03:42 -07:00
parent c12ee422c4
commit e749dcb9ee
1 changed files with 7 additions and 7 deletions

View File

@ -72,9 +72,10 @@ class Puzzle:
self.randseed = category_seed * self.points self.randseed = category_seed * self.points
self.rand = random.Random(self.randseed) self.rand = random.Random(self.randseed)
def log(self, msg): def log(self, *vals):
"""Add a new log message to this puzzle.""" """Add a new log message to this puzzle."""
self.logs.append(str(msg)) msg = ' '.join(str(v) for v in vals)
self.logs.append(msg)
def read_stream(self, stream): def read_stream(self, stream):
header = True header = True
@ -258,11 +259,10 @@ class Category:
self.catmod = None self.catmod = None
if os.path.exists(os.path.join(path, 'category.py')): if os.path.exists(os.path.join(path, 'category.py')):
self.catmod = importlib.machinery.SourceFileLoader( with pushd(path):
'catmod', loader = importlib.machinery.SourceFileLoader('catmod', 'category.py')
os.path.join(path, 'category.py')).load_module() self.catmod = loader.load_module()
self.pointvals.extend(self.catmod.points) self.pointvals.extend(self.catmod.points)
self.pointvals = self.catmod.points[:]
else: else:
for fpath in glob.glob(os.path.join(path, "[0-9]*")): for fpath in glob.glob(os.path.join(path, "[0-9]*")):
pn = os.path.basename(fpath) pn = os.path.basename(fpath)