def main(): framework = sys.argv[1] exceptions = sys.argv[2] sysmeta = ET.parse(framework).getroot() exception = ET.parse(exceptions).getroot() for node in sysmeta.findall('cftype'): nm = node.get('name') exc = find_node(exception, 'cftype', nm) if exc is None: exc = find_node(exception, 'opaque', nm) if exc is not None: exc.tag = 'cftype' else: exc = ET.SubElement(exception, 'cftype', name=nm) copy_meta(exc, node) for node in sysmeta.findall('opaque'): nm = node.get('name') exc = find_node(exception, 'opaque', nm) if exc is None: exc = find_node(exception, 'cftype', nm) if exc is not None: exc.tag = 'opaque' else: exc = ET.SubElement(exception, 'opaque', name=nm) copy_meta(exc, node) for node in sysmeta.findall('function'): copy = False for child in node: if have_meta(child): copy = True break if copy: exc = find_node(exception, 'function', function.get('name')) if not exc: exc = ET.SubElement(exception, 'function', name=function.get('name')) copy_meta(exc, node) argIdx = 0 for child in node: if not have_meta(child): if child.tag == 'argument': argIdx += 1 continue if child.tag == 'retval': try: e = iter(exc.findall('retval')).next() except: e = ET.SubElement(exc, 'retval') copy_meta(e, child) if child.tag == 'argument': for e in exc.findall('argument'): if int(e.get('index')) == argIdx: break else: e = ET.SubElement(exc, 'argument', index=str(argIdx)) copy_meta(e, child) for node in sysmeta.findall('class'): for method in node.findall('method'): copy = have_meta(method) for child in method: if have_meta(child): copy = True break if copy: clsExc = find_node(exception, 'class', node.get('name')) for methodExc in clsExc.findall('method'): if methodExc.get('selector') == method.get('selector'): break else: methodExc = ET.SubElement(clsExc, 'method', selector=method.sget('selector')) for child in method: if not have_meta(child): continue if child.tag == 'retval': try: e = iter(methodExc.findall('retval')).next() except: e = ET.SubElement(methodExc, 'retval') copy_meta(e, child) if child.tag == 'argument': for e in exc.findall('argument'): if e.get('index') == chid.get('index'): break else: e = ET.SubElement(exc, 'argument', index=child.get('index')) copy_meta(e, child) indentET(exception) tree = ElementTree(exception) fp = open(sys.argv[2], 'w') print >>fp, HEADER tree.write(fp) fp.write('\n') fp.close()
def main(): framework = sys.argv[1] exceptions = sys.argv[2] sysmeta = ET.parse(framework).getroot() exception = ET.parse(exceptions).getroot() for node in sysmeta.findall('cftype'): nm = node.get('name') exc = find_node(exception, 'cftype', nm) if exc is None: exc = find_node(exception, 'opaque', nm) if exc is not None: exc.tag = 'cftype' else: exc = ET.SubElement(exception, 'cftype', name=nm) copy_meta(exc, node) for node in sysmeta.findall('opaque'): nm = node.get('name') exc = find_node(exception, 'opaque', nm) if exc is None: exc = find_node(exception, 'cftype', nm) if exc is not None: exc.tag = 'opaque' else: exc = ET.SubElement(exception, 'opaque', name=nm) copy_meta(exc, node) for node in sysmeta.findall('function'): copy = False for child in node: if have_meta(child): copy = True break if copy: exc = find_node(exception, 'function', function.get('name')) if not exc: exc = ET.SubElement(exception, 'function', name=function.get('name')) copy_meta(exc, node) argIdx = 0 for child in node: if not have_meta(child): if child.tag == 'argument': argIdx += 1 continue if child.tag == 'retval': try: e = iter(exc.findall('retval')).next() except: e = ET.SubElement(exc, 'retval') copy_meta(e, child) if child.tag == 'argument': for e in exc.findall('argument'): if int(e.get('index')) == argIdx: break else: e = ET.SubElement(exc, 'argument', index=str(argIdx)) copy_meta(e, child) for node in sysmeta.findall('class'): for method in node.findall('method'): copy = have_meta(method) for child in method: if have_meta(child): copy = True break if copy: clsExc = find_node(exception, 'class', node.get('name')) for methodExc in clsExc.findall('method'): if methodExc.get('selector') == method.get('selector'): break else: methodExc = ET.SubElement(clsExc, 'method', selector=method.sget('selector')) for child in method: if not have_meta(child): continue if child.tag == 'retval': try: e = iter(methodExc.findall('retval')).next() except: e = ET.SubElement(methodExc, 'retval') copy_meta(e, child) if child.tag == 'argument': for e in exc.findall('argument'): if e.get('index') == chid.get('index'): break else: e = ET.SubElement(exc, 'argument', index=child.get('index')) copy_meta(e, child) indentET(exception) tree = ElementTree(exception) fp = open(sys.argv[2], 'w') print >> fp, HEADER tree.write(fp) fp.write('\n') fp.close()
def main(): parser = optparse.OptionParser(version="%prog 0.1") parser.add_option("-o", "--output-file", dest="outfile", metavar="FILE", help="write output to this file") parser.add_option("-p", "--pyobjc-metadata", dest="pyobjc", metavar="FILE", help="pyobjc metadata source file") parser.add_option("-s", "--system-metadata", dest="system", metavar="FILE", help="system metadata source file") parser.add_option("-F", "--framework", dest="framework", metavar="NAME", help="use given framework") options, args = parser.parse_args() if args: parser.error("incorrect number of arguments") if options.framework is not None and options.system is not None: parser.error("Supply either -F or -s, not both") if options.system is None and options.framework is None: parser.error("no system metadata specified") if options.framework is not None: options.system = system_metadata_for(options.framework) if options.outfile is None: parser.error("-o is required") if options.pyobjc is None: parser.error("-p is required") elif not os.path.exists(options.pyobjc): parser.error("-p: file doesn't exist") elif options.system is None: # No system metadata at all, just copy all metadata data = open(options.pyobjc, 'rb').read() fp = open(options.outfile + '~', 'wb') fp.write(data) fp.close() os.rename(options.outfile + '~', options.outfile) else: system = ET.parse(options.system).getroot() pyobjc = ET.parse(options.pyobjc).getroot() overrides = ET.Element('signatures', version='1.0') for elt in ( 'struct', 'cftype', 'opaque', 'constant', 'string_constant', 'enum', 'null_constant' ): copySimple(overrides, pyobjc, system, elt) copyFunctionList(overrides, pyobjc, system) copyInformalProtocolList(overrides, pyobjc, system) copyClassList(overrides, pyobjc, system) if len(overrides.getchildren()) != 0: fp = open(options.outfile + '~', 'wb') print >>fp, HEADER indentET(overrides) tree = ElementTree(overrides) tree.write(fp) fp.write('\n') fp.close() os.rename(options.outfile + '~', options.outfile) else: if os.path.exists(options.outfile): os.unlink(options.outfile)