def jb_harmonize(self, item): ident = ident_transform(item.data['device'], item.data['value'], item.data['footprint']) jb_tools = jb_tools_for_ident(ident) if not jb_tools: return item item.data['footprint'] = self.preconform_footprint( item.data['footprint']) # noqa item.data['device'] = self.preconform_footprint(item.data['device']) context = { 'device': item.data['device'], 'footprint': item.data['footprint'] } params = jb_tools.parse(item.data['value'], context)._asdict() typevalue = params.pop(jb_tools.defs()[0].code) try: jb = self.find_jellybean(jb_tools, item.data['device'], item.data['footprint'], typevalue, **params) item.data['value'] = jb.value except self._exc_class: pass return item
def __getattr__(self, item): if item in self.data.keys(): return self.data[item] elif item == 'ident': return ident_transform(self.data['device'], self.data['value'], self.data['footprint']) else: raise AttributeError
def idents(self): if not self.is_generator: raise AttributeError if not self.generator.values: return None return [ ident_transform(self.device, v, self.footprint) for v in self.generator.values ]
def __getattr__(self, item): if item in self.data.keys(): return self.data[item] elif item == 'ident': return ident_transform( self.data['device'], self.data['value'], self.data['footprint'] ) else: raise AttributeError
def check(self, item): group = item.data['group'] if not group or group == 'unknown': group = 'default' if group not in self._known_groups: raise BomGroupError(self, group, item.data['refdes'], ident_transform(item.data['device'], item.data['value'], item.data['footprint']) ) return group
def find_capacitor(device, footprint, capacitance, voltage=None, tolerance=None, tcc=None): if footprint[0:3] == "MY-": footprint = footprint[3:] if isinstance(capacitance, str): try: capacitance = Capacitance(capacitance) except ParseException: tident = ident_transform(device, capacitance, footprint) symbol = get_symbol(tident) return symbol tcapacitor = jb_capacitor(capacitance, voltage=voltage, tolerance=tolerance, tcc=tcc, context={ 'device': device, 'footprint': footprint }) candidates = [] for symbol in gsymlib: # TODO Don't search _everything_ here # TODO Handle special resistors? if symbol.device == device and symbol.footprint == footprint: try: scapacitor = parse_capacitor(symbol.value) except ParseException: continue symscore = match_capacitor(tcapacitor, scapacitor) if symscore: candidates.append((symbol, symscore)) if not len(candidates): raise NoGedaSymbolException(capacitance) candidates = sorted(candidates, key=lambda c: c[1], reverse=True) maxscore = candidates[0][1] candidates = [x for x in candidates if x[1] == maxscore] return bestmatch_capacitor(tcapacitor, candidates)
def check(self, item): group = item.data['group'] schfile = item.data['schfile'] if not schfile or schfile == 'unknown': schfiles = [] else: schfiles = schfile.split(';') done = False if not group or group == 'unknown': for f in schfiles: if f in self.file_groups.keys(): group = self.file_groups[f] done = True if not done: group = 'default' if group not in self._known_groups: raise BomGroupError( self, group, item.data['refdes'], ident_transform(item.data['device'], item.data['value'], item.data['footprint'])) return group
def find_jellybean(self, jb_tools, device, footprint, typevalue, **kwargs): footprint = self.preconform_footprint(footprint) device = self.preconform_device(device) if isinstance(typevalue, str): try: typevalue = jb_tools.defs()[0].typeclass(typevalue) except ParseException: tident = ident_transform(device, typevalue, footprint) return self.get_symbol(tident) tjb = jb_tools.pack(typevalue, context={ 'device': device, 'footprint': footprint }, **kwargs) candidates = [] for symbol in self.symbols: # TODO Don't search _everything_ here # TODO Handle special resistors? if symbol.device == device and symbol.footprint == footprint: try: sjb = jb_tools.parse(symbol.value) except ParseException: continue symscore = jb_tools.match(tjb, sjb) if symscore: candidates.append((symbol, symscore)) if not len(candidates): raise self._exc_class(typevalue) candidates = sorted(candidates, key=lambda c: c[1], reverse=True) maxscore = candidates[0][1] candidates = [x for x in candidates if x[1] == maxscore] return jb_tools.bestmatch(tjb, candidates)
def get_symbol(self, value, device=None, footprint=None): from tendril.libraries import edasymbols if device is None: device = self._device if footprint is None: footprint = self._footprint # TODO Handle other parameters such as wattage, voltage? if self._stype == 'resistor': if isinstance(value, (str, Resistance)): try: return edasymbols.find_resistor(device, footprint, value) except (edasymbols.nosymbolexception, InvalidOperation): pass if self._stype == 'capacitor': if isinstance(value, (str, Capacitance)): try: return edasymbols.find_capacitor(device, footprint, value) except (edasymbols.nosymbolexception, InvalidOperation): pass ident = ident_transform(device, value, footprint) return edasymbols.get_symbol(ident)
def get_symbol(self, value, device=None, footprint=None): from tendril.gedaif import gsymlib if device is None: device = self._device if footprint is None: footprint = self._footprint # TODO Handle other parameters such as wattage, voltage if self._stype == 'resistor': if isinstance(value, (str, Resistance)): try: return gsymlib.find_resistor(device, footprint, value) except (gsymlib.NoGedaSymbolException, InvalidOperation): pass if self._stype == 'capacitor': if isinstance(value, (str, Capacitance)): try: return gsymlib.find_capacitor(device, footprint, value) except (gsymlib.NoGedaSymbolException, InvalidOperation): pass ident = electronics.ident_transform(device, value, footprint) return gsymlib.get_symbol(ident)
def get_symbol(self, value, device=None, footprint=None): from tendril.gedaif import gsymlib if device is None: device = self._device if footprint is None: footprint = self._footprint if self._stype == 'resistor': if isinstance(value, (str, Resistance)): try: return gsymlib.find_resistor(value, footprint, device) except (gsymlib.NoGedaSymbolException, InvalidOperation): pass if self._stype == 'capacitor': if isinstance(value, (str, Capacitance)): try: return gsymlib.find_capacitor(value, footprint, device) except (gsymlib.NoGedaSymbolException, InvalidOperation): pass ident = electronics.ident_transform(device, value, footprint) return gsymlib.get_symbol(ident)
def _get_generator_idents(self, pricegen): return [ident_transform(pricegen['device'], x, pricegen['footprint']) for x in self._get_generator_values(pricegen)]
def ident_generic(self): return ident_transform(self.device, self.value, self.footprint, generic=True)
def ident(self): return ident_transform(self.device, self.value, self.footprint)
def _get_generator_idents(self, pricegen): return [ ident_transform(pricegen['device'], x, pricegen['footprint']) for x in self._get_generator_values(pricegen) ]
def idents(self): if not self.is_generator: raise AttributeError if not self.generator.values: return None return [ident_transform(self.device, v, self.footprint) for v in self.generator.values]