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