Adding more logging to core MOTH library

This commit is contained in:
John Donaldson 2019-10-30 16:05:07 +00:00
parent 107aa5e736
commit 8639077655
1 changed files with 9 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import hashlib
import html
import io
import importlib.machinery
import logging
import mistune
import os
import random
@ -19,6 +20,8 @@ import yaml
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
LOGGER = logging.getLogger(__name__)
def djb2hash(str):
h = 5381
for c in str.encode("utf-8"):
@ -28,6 +31,7 @@ def djb2hash(str):
@contextlib.contextmanager
def pushd(newdir):
curdir = os.getcwd()
LOGGER.debug("Attempting to chdir from %s to %s" % (curdir, newdir))
os.chdir(newdir)
# Force a copy of the old path, instead of just a reference
@ -48,6 +52,7 @@ def pushd(newdir):
del(sys.modules[module])
sys.path = old_path
LOGGER.debug("Changing directory back from %s to %s" % (newdir, curdir))
os.chdir(curdir)
@ -154,8 +159,10 @@ class Puzzle:
stream.seek(0)
if header == "yaml":
LOGGER.info("Puzzle is YAML-formatted")
self.read_yaml_header(stream)
elif header == "moth":
LOGGER.info("Puzzle is MOTH-formatted")
self.read_moth_header(stream)
for line in stream:
@ -190,6 +197,7 @@ class Puzzle:
self.handle_header_key(key, val)
def handle_header_key(self, key, val):
LOGGER.debug("Handling key: %s, value: %s", key, val)
if key == 'author':
self.authors.append(val)
elif key == 'summary':
@ -213,6 +221,7 @@ class Puzzle:
parts = shlex.split(val)
name = parts[0]
hidden = False
LOGGER.debug("Attempting to open %s", os.path.abspath(name))
stream = open(name, 'rb')
try:
name = parts[1]