Skip to content

Instantly share code, notes, and snippets.

@typesupply
Last active January 31, 2020 13:14
Show Gist options
  • Save typesupply/e69163c8d3764d976c86747cb2d58251 to your computer and use it in GitHub Desktop.
Save typesupply/e69163c8d3764d976c86747cb2d58251 to your computer and use it in GitHub Desktop.
import os
import shutil
from mojo.events import addObserver
"""
Goal: Create a UFOZ automatically when a UFO is saved.
Off the top of my head, I can think of a few ways to do this:
1. Make a copy of the font object, save as UFOZ, discard the
copied object.
2. Save the UFO, save the same font object to UFOZ, switch
the path of the font object back to the UFO path.
3. Make a zip of the written UFO.
The third seems like it will be the most efficient, so I'm
going to use that. I'm too lazy to actually test all the
different methods, but someone could.
"""
class SaveUFOZ(object):
def __init__(self):
addObserver(self, "saveUFOZ", "fontDidSave")
def saveUFOZ(self, notification):
path = notification["path"]
base, extension = os.path.splitext(path)
if extension.lower() == ".ufoz":
return
zipPath = shutil.make_archive(path, format="zip", root_dir=os.path.dirname(path))
ufozPath = base + ".ufoz"
os.rename(zipPath, ufozPath)
SaveUFOZ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment