Skip to content

Commit

Permalink
Merge pull request #28 from daltonmaag/keep-empty-required-plist
Browse files Browse the repository at this point in the history
Keep required plist files even if empty
  • Loading branch information
typesupply committed Apr 6, 2016
2 parents 464b8cd + deef98a commit 58ab51f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
26 changes: 25 additions & 1 deletion normalization/test_ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
_normalizeGlifOutlineFormat2, _normalizeGlifContourFormat2,
_normalizeGlifPointAttributesFormat2,
_normalizeGlifComponentAttributesFormat2, _normalizeGlifTransformation,
_normalizeColorString, _convertPlistElementToObject)
_normalizeColorString, _convertPlistElementToObject, _normalizePlistFile)
from ufonormalizer import __version__ as ufonormalizerVersion

# Python 3.4 deprecated readPlistFromBytes and writePlistToBytes
Expand Down Expand Up @@ -155,6 +155,15 @@
</plist>
'''

EMPTY_PLIST = '''\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
'''


class UFONormalizerErrorTest(unittest.TestCase):
def test_str(self):
Expand Down Expand Up @@ -1659,6 +1668,21 @@ def test_subpathRemoveFile(self):
subpathRemoveFile(self.directory, self.filename)
self.assertFalse(os.path.exists(self.filepath))

def test__normalizePlistFile_remove_empty(self):
emptyPlist = os.path.join(self.directory, "empty.plist")
with open(emptyPlist, "w") as f:
f.write(EMPTY_PLIST)
# 'removeEmpty' keyword argument is True by default
_normalizePlistFile({}, self.directory, "empty.plist")
self.assertFalse(os.path.exists(emptyPlist))

def test__normalizePlistFile_keep_empty(self):
emptyPlist = os.path.join(self.directory, "empty.plist")
with open(emptyPlist, "w") as f:
f.write(EMPTY_PLIST)
_normalizePlistFile({}, self.directory, "empty.plist", removeEmpty=False)
self.assertTrue(os.path.exists(emptyPlist))

def test_subpathGetModTime(self):
self.createTestFile('')
mtime = subpathGetModTime(self.directory, self.filename)
Expand Down
10 changes: 5 additions & 5 deletions normalization/ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def normalizeGlyphNames(ufoPath, layerDirectory):
# update contents.plist
subpathWritePlist(newGlyphMapping, ufoPath, layerDirectory, "contents.plist")
# normalize contents.plist
_normalizePlistFile({}, ufoPath, layerDirectory, "contents.plist")
_normalizePlistFile({}, ufoPath, layerDirectory, "contents.plist", removeEmpty=False)
return newGlyphMapping

def _test_normalizeGlyphNames(oldGlyphMapping, expectedGlyphMapping):
Expand Down Expand Up @@ -373,16 +373,16 @@ def _normalizePlistFile(modTimes, ufoPath, *subpath, **kwargs):
text = normalizePropertyList(data, preprocessor=preprocessor)
subpathWriteFile(text, ufoPath, *subpath)
modTimes[subpath[-1]] = subpathGetModTime(ufoPath, *subpath)
# Don't write empty plist files.
else:
elif kwargs.get("removeEmpty", True):
# Don't write empty plist files, unless 'removeEmpty' is False
subpathRemoveFile(ufoPath, *subpath)
if subpath[-1] in modTimes:
del modTimes[subpath[-1]]

# metainfo.plist

def normalizeMetaInfoPlist(ufoPath, modTimes):
_normalizePlistFile(modTimes, ufoPath, "metainfo.plist")
_normalizePlistFile(modTimes, ufoPath, "metainfo.plist", removeEmpty=False)

# fontinfo.plist

Expand Down Expand Up @@ -469,7 +469,7 @@ def normalizeKerningPlist(ufoPath, modTimes):
# layercontents.plist

def normalizeLayerContentsPlist(ufoPath, modTimes):
_normalizePlistFile(modTimes, ufoPath, "layercontents.plist")
_normalizePlistFile(modTimes, ufoPath, "layercontents.plist", removeEmpty=False)

# lib.plist

Expand Down

0 comments on commit 58ab51f

Please sign in to comment.