def ufo2glyphs(options):
import fontTools.designspaceLib<EOL>import defcon<EOL>sources = options.designspace_file_or_UFOs<EOL>designspace_file = None<EOL>if (<EOL>len(sources) == <NUM_LIT:1><EOL>and sources[<NUM_LIT:0>].endswith("<STR_LIT>")<EOL>and os.path.isfile(sources[<NUM_LIT:0>])<EOL>):<EOL><INDENT>designspace_file = sources[<NUM_LIT:0>]<EOL>designspace = fontTools.designspaceLib.DesignSpaceDocument()<EOL>designspace.read(designspace_file)<EOL>object_to_read = designspace<EOL><DEDENT>elif all(source.endswith("<STR_LIT>") and os.path.isdir(source) for source in sources):<EOL><INDENT>ufos = [defcon.Font(source) for source in sources]<EOL>ufos.sort(<EOL>key=lambda ufo: [  <EOL>ufo.info.openTypeOS2WeightClass or <NUM_LIT>,<EOL>ufo.info.openTypeOS2WidthClass or <NUM_LIT:5>,<EOL>]<EOL>)<EOL>object_to_read = ufos<EOL><DEDENT>else:<EOL><INDENT>print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>file=sys.stderr,<EOL>)<EOL>return <NUM_LIT:1><EOL><DEDENT>font = glyphsLib.to_glyphs(<EOL>object_to_read, minimize_ufo_diffs=options.no_preserve_glyphsapp_metadata<EOL>)<EOL>font.customParameters["<STR_LIT>"] = options.enable_last_change<EOL>font.disablesAutomaticAlignment = options.enable_automatic_alignment<EOL>if options.output_path:<EOL><INDENT>font.save(options.output_path)<EOL><DEDENT>else:<EOL><INDENT>if designspace_file:<EOL><INDENT>filename_to_write = os.path.splitext(designspace_file)[<NUM_LIT:0>] + "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>filename_to_write = os.path.join(<EOL>os.path.dirname(sources[<NUM_LIT:0>]),<EOL>font.familyName.replace("<STR_LIT:U+0020>", "<STR_LIT>") + "<STR_LIT>",<EOL>)<EOL><DEDENT>font.save(filename_to_write)<EOL><DEDENT>
Convert one designspace file or one or more UFOs to a Glyphs.app source file.