[mtiLib] replace print with logger
inside main(), I just do a basic config for the library logger, but keep the debug messages from mtiLib turned off.
This commit is contained in:
parent
e5b6be00a0
commit
b62f550952
@ -15,15 +15,16 @@ from fontTools.ttLib.tables.otBase import ValueRecord, valueRecordFormatDict
|
|||||||
from fontTools.otlLib import builder as otl
|
from fontTools.otlLib import builder as otl
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from operator import setitem
|
from operator import setitem
|
||||||
|
import logging
|
||||||
|
|
||||||
class MtiLibError(Exception): pass
|
class MtiLibError(Exception): pass
|
||||||
class ReferenceNotFoundError(MtiLibError): pass
|
class ReferenceNotFoundError(MtiLibError): pass
|
||||||
class FeatureNotFoundError(ReferenceNotFoundError): pass
|
class FeatureNotFoundError(ReferenceNotFoundError): pass
|
||||||
class LookupNotFoundError(ReferenceNotFoundError): pass
|
class LookupNotFoundError(ReferenceNotFoundError): pass
|
||||||
|
|
||||||
def debug(*args):
|
|
||||||
#print(*args)
|
log = logging.getLogger(__name__)
|
||||||
pass
|
|
||||||
|
|
||||||
def makeGlyph(s):
|
def makeGlyph(s):
|
||||||
if s[:2] == 'U ':
|
if s[:2] == 'U ':
|
||||||
@ -79,18 +80,18 @@ class DeferredMapping(dict):
|
|||||||
self._deferredMappings = []
|
self._deferredMappings = []
|
||||||
|
|
||||||
def addDeferredMapping(self, setter, sym, e):
|
def addDeferredMapping(self, setter, sym, e):
|
||||||
debug("Adding deferred mapping for symbol '%s'" % sym, type(e).__name__)
|
log.debug("Adding deferred mapping for symbol '%s' %s", sym, type(e).__name__)
|
||||||
self._deferredMappings.append((setter,sym, e))
|
self._deferredMappings.append((setter,sym, e))
|
||||||
|
|
||||||
def applyDeferredMappings(self):
|
def applyDeferredMappings(self):
|
||||||
for setter,sym,e in self._deferredMappings:
|
for setter,sym,e in self._deferredMappings:
|
||||||
debug("Applying deferred mapping for symbol '%s'" % sym, type(e).__name__)
|
log.debug("Applying deferred mapping for symbol '%s' %s", sym, type(e).__name__)
|
||||||
try:
|
try:
|
||||||
mapped = self[sym]
|
mapped = self[sym]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise e
|
raise e
|
||||||
setter(mapped)
|
setter(mapped)
|
||||||
debug("Set to %s" % mapped)
|
log.debug("Set to %s", mapped)
|
||||||
self._deferredMappings = []
|
self._deferredMappings = []
|
||||||
|
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ def parseScriptList(lines, featureMap=None):
|
|||||||
with lines.between('script table'):
|
with lines.between('script table'):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
scriptTag, langSysTag, defaultFeature, features = line
|
scriptTag, langSysTag, defaultFeature, features = line
|
||||||
debug("Adding script", scriptTag, "language-system", langSysTag)
|
log.debug("Adding script %s language-system %s", scriptTag, langSysTag)
|
||||||
|
|
||||||
langSys = ot.LangSys()
|
langSys = ot.LangSys()
|
||||||
langSys.LookupOrder = None
|
langSys.LookupOrder = None
|
||||||
@ -676,7 +677,7 @@ def parseContext(self, lines, font, Type, lookupMap=None):
|
|||||||
typ = lines.peek()[0].split()[0].lower()
|
typ = lines.peek()[0].split()[0].lower()
|
||||||
if typ == 'glyph':
|
if typ == 'glyph':
|
||||||
self.Format = 1
|
self.Format = 1
|
||||||
debug("Parsing %s format %s" % (Type, self.Format))
|
log.debug("Parsing %s format %s", Type, self.Format)
|
||||||
c = ContextHelper(Type, self.Format)
|
c = ContextHelper(Type, self.Format)
|
||||||
rules = []
|
rules = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -690,7 +691,7 @@ def parseContext(self, lines, font, Type, lookupMap=None):
|
|||||||
bucketizeRules(self, c, rules, self.Coverage.glyphs)
|
bucketizeRules(self, c, rules, self.Coverage.glyphs)
|
||||||
elif typ.endswith('class'):
|
elif typ.endswith('class'):
|
||||||
self.Format = 2
|
self.Format = 2
|
||||||
debug("Parsing %s format %s" % (Type, self.Format))
|
log.debug("Parsing %s format %s", Type, self.Format)
|
||||||
c = ContextHelper(Type, self.Format)
|
c = ContextHelper(Type, self.Format)
|
||||||
classDefs = [None] * c.DataLen
|
classDefs = [None] * c.DataLen
|
||||||
while lines.peek()[0].endswith("class definition begin"):
|
while lines.peek()[0].endswith("class definition begin"):
|
||||||
@ -720,7 +721,7 @@ def parseContext(self, lines, font, Type, lookupMap=None):
|
|||||||
bucketizeRules(self, c, rules, range(max(firstClasses) + 1))
|
bucketizeRules(self, c, rules, range(max(firstClasses) + 1))
|
||||||
elif typ.endswith('coverage'):
|
elif typ.endswith('coverage'):
|
||||||
self.Format = 3
|
self.Format = 3
|
||||||
debug("Parsing %s format %s" % (Type, self.Format))
|
log.debug("Parsing %s format %s", Type, self.Format)
|
||||||
c = ContextHelper(Type, self.Format)
|
c = ContextHelper(Type, self.Format)
|
||||||
coverages = tuple([] for i in range(c.DataLen))
|
coverages = tuple([] for i in range(c.DataLen))
|
||||||
while lines.peek()[0].endswith("coverage definition begin"):
|
while lines.peek()[0].endswith("coverage definition begin"):
|
||||||
@ -782,7 +783,7 @@ def parseReverseChainedSubst(self, lines, font, _lookupMap=None):
|
|||||||
def parseLookup(lines, tableTag, font, lookupMap=None):
|
def parseLookup(lines, tableTag, font, lookupMap=None):
|
||||||
line = lines.expect('lookup')
|
line = lines.expect('lookup')
|
||||||
_, name, typ = line
|
_, name, typ = line
|
||||||
debug("Parsing lookup type %s %s" % (typ, name))
|
log.debug("Parsing lookup type %s %s", typ, name)
|
||||||
lookup = ot.Lookup()
|
lookup = ot.Lookup()
|
||||||
with lines.until('lookup end'):
|
with lines.until('lookup end'):
|
||||||
|
|
||||||
@ -838,7 +839,7 @@ def parseGSUBGPOS(lines, font, tableTag):
|
|||||||
lookupMap = DeferredMapping()
|
lookupMap = DeferredMapping()
|
||||||
featureMap = DeferredMapping()
|
featureMap = DeferredMapping()
|
||||||
assert tableTag in ('GSUB', 'GPOS')
|
assert tableTag in ('GSUB', 'GPOS')
|
||||||
debug("Parsing", tableTag)
|
log.debug("Parsing %s", tableTag)
|
||||||
self = getattr(ot, tableTag)()
|
self = getattr(ot, tableTag)()
|
||||||
self.Version = 1.0
|
self.Version = 1.0
|
||||||
fields = {
|
fields = {
|
||||||
@ -933,7 +934,7 @@ def parseMarkFilteringSets(lines, font):
|
|||||||
return makeMarkFilteringSets(sets, font)
|
return makeMarkFilteringSets(sets, font)
|
||||||
|
|
||||||
def parseGDEF(lines, font):
|
def parseGDEF(lines, font):
|
||||||
debug("Parsing GDEF")
|
log.debug("Parsing GDEF")
|
||||||
self = ot.GDEF()
|
self = ot.GDEF()
|
||||||
fields = {
|
fields = {
|
||||||
'class definition begin':
|
'class definition begin':
|
||||||
@ -954,7 +955,7 @@ def parseGDEF(lines, font):
|
|||||||
while lines.peek() is not None:
|
while lines.peek() is not None:
|
||||||
typ = lines.peek()[0].lower()
|
typ = lines.peek()[0].lower()
|
||||||
if typ not in fields:
|
if typ not in fields:
|
||||||
debug ('Skipping', line)
|
log.debug('Skipping %s', typ)
|
||||||
next(lines)
|
next(lines)
|
||||||
continue
|
continue
|
||||||
attr,parser = fields[typ]
|
attr,parser = fields[typ]
|
||||||
@ -964,7 +965,7 @@ def parseGDEF(lines, font):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def parseTable(lines, font, tableTag=None):
|
def parseTable(lines, font, tableTag=None):
|
||||||
debug("Parsing table")
|
log.debug("Parsing table")
|
||||||
line = lines.peek()
|
line = lines.peek()
|
||||||
if line[0].split()[0] == 'FontDame':
|
if line[0].split()[0] == 'FontDame':
|
||||||
next(lines)
|
next(lines)
|
||||||
@ -1103,13 +1104,18 @@ class MockFont(object):
|
|||||||
return self._glyphOrder
|
return self._glyphOrder
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
from fontTools import configLogger
|
||||||
|
# configure the library logger (for >= WARNING)
|
||||||
|
configLogger()
|
||||||
|
# comment this out to enable debug messages from mtiLib's logger
|
||||||
|
# log.setLevel(logging.DEBUG)
|
||||||
font = MockFont()
|
font = MockFont()
|
||||||
tableTag = None
|
tableTag = None
|
||||||
if args[0].startswith('-t'):
|
if args[0].startswith('-t'):
|
||||||
tableTag = args[0][2:]
|
tableTag = args[0][2:]
|
||||||
del args[0]
|
del args[0]
|
||||||
for f in args:
|
for f in args:
|
||||||
debug("Processing", f)
|
log.debug("Processing %s", f)
|
||||||
table = build(open(f, 'rt', encoding="utf-8"), font, tableTag=tableTag)
|
table = build(open(f, 'rt', encoding="utf-8"), font, tableTag=tableTag)
|
||||||
blob = table.compile(font) # Make sure it compiles
|
blob = table.compile(font) # Make sure it compiles
|
||||||
decompiled = table.__class__()
|
decompiled = table.__class__()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user