#! /usr/bin/env python

import extractor
import defcon
import sys
import fire

def main(fromfile, targetUfoPath=None, ufoFormatVersion=None):
    """ Use extractor to make a UFO from a binary font file

    FROMFILE: OpenType font file.
    TARGETUFOPATH: directory name of the UFO or \| (default) to write a pickled defcon object to stdout.
    UFOFORMATVERSION: if the font UFO is written to disk, save with this version (default: 3)
    """
    font = defcon.Font()
    extractor.extractUFO(fromfile, font)
    if targetUfoPath is None or targetUfoPath == '|':
        # write pickle serialization to stdout
        sys.stdout.write(font.serialize())
    else:
        font.save(targetUfoPath, formatVersion=ufoFormatVersion)

if __name__ == '__main__':
    fire.Fire(main)
