def main(): parser = argparse.ArgumentParser(description="Generate a family of Eagle Devices") parser.add_argument("--db", required=True, type=str, nargs=1, dest='db', help="Spec for device list to build") parser.add_argument("--lbrin", required=True, type=str, nargs=1, dest='lbrin', help="Library containing the symbol and the package.") parser.add_argument("--lbrout", required=True, type=str, nargs=1, dest='lbrout', help="Output Library.") args = parser.parse_args() db = ET.parse(args.db[0]) v = gcomVisitor() v.visit(db.getroot()) lbrIn = EagleLibrary(args.lbrin[0]) # ET.dump(db.getroot()) for j in v.getVariants(): #ET.dump(j) devset = lbrIn.findDeviceSet(j.find("devset").text.upper()) # ET.dump(devset) # sys.exit(0) assert(devset is not None) for a in j.findall("attr"): j.set(a.get("key"), a.get("value")) device = ET.SubElement(devset.find("devices"), "device", name=(j.find("format").text % j.attrib).upper(), package=j.find("package").text.upper()) connects = ET.SubElement(device, "connects"); connections = eval(j.find("pinmapping").text) for c in connections: ET.SubElement(connects, "connect", gate="G$1", pin=c, pad=connections[c]) t = ET.SubElement(device,"technologies") tech =ET.SubElement(t,"technology",name="") for a in j.attrib: ET.SubElement(tech, "attribute", name=a.upper(), value=j.attrib[a])
def main(): parser = argparse.ArgumentParser(description="Tool for moving symbols, packages, and devices betweens brd, sch, and lbr files. For instance, to build a library from a brd and sch, do something like './extractLibraries.py --src foo.sch bar.brd --dst Empty.lbr'") parser.add_argument("--src", required=True, type=str, nargs='+', dest='srcFile', help="source .brd, .sch, or .lbr file") parser.add_argument("--dst", required=True, type=str, nargs=1, dest='dstFile', help="destination .brd, .sch, or .lbr file") # parser.add_argument("--targets", required=False, type=str, nargs='*', dest='targets', help="Items to copy") args = parser.parse_args() if re.match(".*\.sch", args.dstFile[0]): dstF = EagleSchematic(args.dstFile[0]) elif re.match(".*\.brd", args.dstFile[0]): dstF = EagleBoard(args.dstFile[0]) elif re.match(".*\.lbr", args.dstFile[0]): dstF = EagleLibrary(args.dstFile[0]) else: raise EagleError("Unknown type: " + args.dstFile[0]) dst = dstF.getLibraryContainer().find("library") dstLib = EagleLibrary(dst) for f in args.srcFile: if re.match(".*\.sch", f): src = EagleSchematic(f).getLibraryContainer() elif re.match(".*\.brd", f): src = EagleBoard(f).getLibraryContainer() elif re.match(".*\.lbr", f): src = EagleLibrary(f).getLibraryContainer() else: raise EagleError("Unknown type: " + f) for library in src.findall("library"): srcLib = EagleLibrary(library) if srcLib.getPackages() is not None: for i in srcLib.getPackages(): dstLib.addItem(i) if srcLib.getSymbols() is not None: for i in srcLib.getSymbols(): dstLib.addItem(i) if srcLib.getDevicesets() is not None: for i in srcLib.getDevicesets(): dstLib.addItem(i) f = args.dstFile[0] # write it out. Eagle has trouble reading xml with no newlines. Run it through xmllint to make it pretty. t = pipes.Template() t.append("xmllint --format $IN", "f-") dstF.write(t.open(f, 'w'))
else: inputDotsPerInch = float(args.dpi[0]) threshold = 128 maxBoxHeight = 0.1 if args.package is None: f = inFile.split("/")[-1] name = f.replace(".png","").replace(".PNG","") else: name = args.package[0] input = io.open(inFile,mode='rb') lbr = EagleLibrary(args.lbrFile[0]) layers = EagleLayers(lbr.getLayers()) if args.layer is None: layer = "tPlace" else: layer = args.layer[0] if args.width is None: width = "0.1" else: width = args.width[0] package = ET.Element("package", name=name) RenderLineArt(input, name.upper(), inputDotsPerInch, threshold, maxBoxHeight, str(layers.nameToNumber(layer)), width, mode="brd", state=package)