From e3242229744453370f54693b5640f45db758d7c7 Mon Sep 17 00:00:00 2001 From: Erik van Blokland Date: Tue, 28 Mar 2017 23:04:30 +0200 Subject: [PATCH 1/2] This addresses a problem caused by files in which a source element has no name attribute. Mutator uses the value of the name attribute to store some data and retrieve it later. This adds a temporary simple unique name. --- Lib/mutatorMath/ufo/document.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/mutatorMath/ufo/document.py b/Lib/mutatorMath/ufo/document.py index adb325e2..bea10aff 100644 --- a/Lib/mutatorMath/ufo/document.py +++ b/Lib/mutatorMath/ufo/document.py @@ -502,12 +502,19 @@ def readSources(self): """ + sourceCount = 0 for sourceElement in self.root.findall(".sources/source"): # shall we just read the UFO here? filename = sourceElement.attrib.get('filename') # filename is a path relaive to the documentpath. resolve first. sourcePath = os.path.abspath(os.path.join(os.path.dirname(self.path), filename)) sourceName = sourceElement.attrib.get('name') + if sourceName is None: + # if the source element has no name attribute + # (some authoring tools do not need them) + # then we should make a temporary one + sourceName = "temp_master.%d"%(sourceCount) + print("created temp source name", sourceName) self.reportProgress("prep", 'load', sourcePath) if not os.path.exists(sourcePath): raise MutatorError("Source not found at %s"%sourcePath) @@ -561,6 +568,7 @@ def readSources(self): # store self.sources[sourceName] = sourceObject, sourceLocationObject self.reportProgress("prep", 'done') + sourceCount+=1 def locationFromElement(self, element): """ From 1a6e6d37dc4089a38a43680bbaaa686204feece5 Mon Sep 17 00:00:00 2001 From: Erik van Blokland Date: Wed, 29 Mar 2017 00:07:31 +0200 Subject: [PATCH 2/2] As per comment from @anthrotype use enumerate. Remove print. --- Lib/mutatorMath/ufo/document.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Lib/mutatorMath/ufo/document.py b/Lib/mutatorMath/ufo/document.py index bea10aff..78d18e34 100644 --- a/Lib/mutatorMath/ufo/document.py +++ b/Lib/mutatorMath/ufo/document.py @@ -502,8 +502,7 @@ def readSources(self): """ - sourceCount = 0 - for sourceElement in self.root.findall(".sources/source"): + for sourceCount, sourceElement in enumerate(self.root.findall(".sources/source")): # shall we just read the UFO here? filename = sourceElement.attrib.get('filename') # filename is a path relaive to the documentpath. resolve first. @@ -512,9 +511,8 @@ def readSources(self): if sourceName is None: # if the source element has no name attribute # (some authoring tools do not need them) - # then we should make a temporary one + # then we should make a temporary one. We still need it for reference. sourceName = "temp_master.%d"%(sourceCount) - print("created temp source name", sourceName) self.reportProgress("prep", 'load', sourcePath) if not os.path.exists(sourcePath): raise MutatorError("Source not found at %s"%sourcePath) @@ -568,7 +566,6 @@ def readSources(self): # store self.sources[sourceName] = sourceObject, sourceLocationObject self.reportProgress("prep", 'done') - sourceCount+=1 def locationFromElement(self, element): """