def __analyze_categories(devices): from tendril.gedaif.gsymlib import gsymlib_idents catstrings = {} for ident in gsymlib_idents: try: d, v, f = parse_ident(ident) except IndexError: print "Malformed Ident {0}".format(ident) continue if not d: print "Device Not Extracted for {0}".format(ident) continue if d not in devices: continue if d not in dvobj._devices: continue if not v: print "Value Not Extracted for {0}".format(ident) continue # print "Searching for {0}".format(v) r = dvobj.api_client.service.SearchByKeyword( keyword=v, records=50, startingRecord=0, searchOptions=4 ) if not r.NumberOfResult: print " No results for {0}".format(v) continue for part in r.Parts[0]: if part.Category not in catstrings: print "Found new category : {0}".format(part.Category) catstrings[part.Category] = [] catstrings[part.Category].append(v) return catstrings
def _process_resultpage_row(self, row, ident): d, v, f = parse_ident(ident) sanitycheck = self._get_device_searchparams(d)[1] name_cell = row.find(attrs={'class': 'name'}) link = name_cell.find('a') name = link.contents[0] if not sanitycheck(name, d, v, f): return None o = urlparse(link.attrs['href']) uri = o.scheme + "://" + o.netloc + o.path try: part = self._partclass(vpno=None, ident=ident, vendor=self, shell_only=True) response = get_soup(uri) part.load_from_response(response) except: raise if part.vqtyavail is None: ns = False else: ns = True unitp = part.prices[0].unit_price minqty = part.abs_moq raw = part.raw return SearchPart(part.vpno, part.mpartno, None, ns, unitp, minqty, raw)
def __analyze_categories(devices): from tendril.gedaif.gsymlib import gsymlib_idents catstrings = {} for ident in gsymlib_idents: try: d, v, f = parse_ident(ident) except IndexError: print("Malformed Ident {0}".format(ident)) continue if not d: print("Device Not Extracted for {0}".format(ident)) continue if d not in devices: continue if d not in dvobj._devices: continue if not v: print("Value Not Extracted for {0}".format(ident)) continue # print "Searching for {0}".format(v) r = dvobj.api_client.service.SearchByKeyword(keyword=v, records=50, startingRecord=0, searchOptions=4) if not r.NumberOfResult: print(" No results for {0}".format(v)) continue for part in r.Parts[0]: if part.Category not in catstrings: print("Found new category : {0}".format(part.Category)) catstrings[part.Category] = [] catstrings[part.Category].append(v) return catstrings
def check(self, ident, refdeslist, cstatus): d, v, f = parse_ident(ident) if d not in DEVICE_CLASSES: self.is_error = True raise DeviceNotRecognized(self, ident, refdeslist) if not self._rfunc(ident): self.is_error = False raise IdentNotRecognized(self, ident, refdeslist)
def rewrite_schematic(inpath, obom, gpf, outpath): fbase = os.path.split(inpath)[1] try: f = gschf.GschFile(inpath) except: print("Error parsing file {0}".format(inpath)) raise # Replace value strings with whatever the bom says for c in f.components: # TODO Review possibility of reconstructing from the BOM instead # of the relatively more expensive OBOM parsing. item = obom.get_item_for_refdes(c.refdes) if not item: result = c.set_attribute('fillstatus', 'DNP') if not result: c.set_attribute('value', 'DNP') continue fstatus = c.get_attribute('fillstatus') if fstatus == 'CONF': c.remove_attribute('fillstatus') d, v, fp = parse_ident(item.ident) c.value = v # Handle Titleblocks tbs = f.get_meta_components(rex_titleblocks) if len(tbs): tb = tbs[0] tb._selectable = 1 tb.set_attribute('PN', obom.descriptor.pcbname) tb.set_attribute('CN', obom.descriptor.configname) tb.set_attribute('MAINTAINER', obom.descriptor.configurations.maintainer( obom.descriptor.configname) ) tb.set_attribute('DGR', obom.descriptor.configurations.file_groups.get( fbase, 'default') ) tb.set_attribute('NP', len(gpf.schfiles)) tb.set_attribute('P', gpf.schfiles.index(fbase) + 1) wcroot = vcs.get_path_wcroot(inpath) rev = vcs.get_file_revision(inpath) fpath = os.path.relpath(inpath, wcroot) frev = vcs.get_path_revision(inpath) tb.set_attribute('RR', '{0}:r{1}'.format( os.path.relpath(wcroot, PROJECTS_ROOT), rev)) tb.set_attribute('RP', '{0}:r{1}'.format(fpath, frev)) lx, ly, lw, lh = map(int, tb.get_attribute('logo')[1:-1].split(',')) lx += getattr(tb, '_x') ly += getattr(tb, '_y') tb.remove_attribute('logo') lines = gschf.GschFakeLines([ os.path.join(INSTANCE_ROOT, COMPANY_SQUARE_LOGO_PATH) ]) logo = gschf.GschElementPicture(f, lines, lx, ly, lw, lh, 0, 0, 0) f.add_element(logo) f.write_out(outpath)
def search_vpnos(self, ident): device, value, footprint = parse_ident(ident) if device not in self._devices: return None, "NODEVICE" try: return self._get_search_vpnos(device, value, footprint) except Exception: logger.error(traceback.format_exc()) logger.error("Fatal Error searching for : " + ident) return None, None
def search_vpnos(self, ident): device, value, footprint = parse_ident(ident) if device not in self._devices: return None, 'NODEVICE' try: return self._get_search_vpnos(device, value, footprint) except (KeyboardInterrupt, SystemExit): raise except Exception: logger.error(traceback.format_exc()) logger.error('Fatal Error searching for : ' + ident) return None, None
def collapse_wires(self): for line in self.lines: device, value, footprint = parse_ident(line.ident) if device is None: continue if fpiswire(device): newident = device + ' ' + value newline = self.find_by_ident(newident) if newline is None: line.ident = newident else: newline.merge_line(line) self.lines.remove(line)
def get_guideline(self, ident): device, value, footprint = parse_ident(ident) if ident in self._idents.keys(): gldict = self._idents[ident] elif device in self._devices.keys(): gldict = self._devices[device] else: gldict = self._default if gldict is None: return None if 'filter_std_vals_only' in gldict.keys() and \ gldict['filter_std_vals_only'] is True: is_std_val = check_for_std_val(ident) if not is_std_val: gldict = self._default return self._get_full_guideline(gldict, device)
def uquantity(self): device, value, footprint = parse_ident(self.ident) if device is None: logger.warning("Device not identified : " + self.ident) elif fpiswire(device): try: elen = Length(footprint) * Decimal(0.1) if elen < Length('5mm'): elen = Length('5mm') elif elen > Length('1inch'): elen = Length('1inch') return len(self.refdeslist) * (Length(footprint) + elen) except ValueError: logger.error( "Problem parsing length for ident : " + self.ident ) raise return len(self.refdeslist)
def uquantity(self): device, value, footprint = parse_ident(self.ident) if device is None: # TODO # logger.warning("Device not identified : " + self.ident) pass elif fpiswire(device): try: elen = Length(footprint) * Decimal(0.1) if elen < Length('5mm'): elen = Length('5mm') elif elen > Length('1inch'): elen = Length('1inch') return len(self.refdeslist) * (Length(footprint) + elen) except ValueError: logger.error( "Problem parsing length for ident : " + self.ident ) raise return len(self.refdeslist)
def _search_vpnos(self, ident): device, value, footprint = parse_ident(ident) if device not in self._devices: return None, 'NODEVICE' try: if check_for_std_val(ident): try: return self._get_pas_vpnos(device, value, footprint) except NotImplementedError: return None, 'NOT_IMPL' if device in self._devices: return self._get_search_vpnos(device, value, footprint) else: return None, 'FILTER_NODEVICE' except (KeyboardInterrupt, SystemExit): raise except Exception: logger.error(traceback.format_exc()) logger.error('Fatal Error searching for : ' + ident) return None, None
def _search_vpnos(self, ident): device, value, footprint = parse_ident(ident) if device not in self._devices: return None, 'NODEVICE' try: if device.startswith('RES') or device.startswith('POT') or \ device.startswith('CAP') or device.startswith('CRYSTAL'): if check_for_std_val(ident) is False: return self._get_search_vpnos(device, value, footprint) try: return self._get_pas_vpnos(device, value, footprint) except NotImplementedError: return None, 'NOT_IMPL' if device in self._devices: return self._get_search_vpnos(device, value, footprint) else: return None, 'FILTER_NODEVICE' except Exception: logger.error(traceback.format_exc()) logger.error('Fatal Error searching for : ' + ident) return None, None
def create_obom_from_listing(component_list, head): obom_descriptor = OutputElnBomDescriptor(head, None, head, None) obom = OutputBom(obom_descriptor) for line in component_list: device, value, footprint = parse_ident(line['ident']) from tendril.boms.electronics import EntityElnComp item = EntityElnComp() item.define('Undef', device, value, footprint) if device and fpiswire(device): length = Length(line['qty']) if length > 0: wireitem = EntityElnComp() wireitem.define( 'Undef', device, value, str(length) ) obom.insert_component(wireitem) else: num = int(line['qty']) if num > 0: for i in range(num): obom.insert_component(item) return obom
def insert(self, ident, cost): d, v, f = parse_ident(ident) if d not in self._devices.keys(): self._devices[d] = [] self._devices[d].append({'name': ident, 'size': cost.native_value}) self._total_cost += cost
def insert(self, ident, cost): d, v, f = parse_ident(ident) if d not in self._devices.keys(): self._devices[d] = [] self._devices[d].append({"name": ident, "size": cost.native_value}) self._total_cost += cost
def load_cobom_from_file(f, name, tf=None, verbose=True, generic=False): bomlist = [] header = [] reader = csv.reader(f) for line in reader: line = [elem.strip() for elem in line] if line[0] == 'device': header = line break if verbose: logger.info('Inserting External Boms') oboms = [] for head in header[1:-1]: if verbose: logger.info('Creating Bom : ' + head) obom_descriptor = OutputElnBomDescriptor(head, None, head, None) obom = OutputBom(obom_descriptor) oboms.append(obom) for line in reader: line = [elem.strip() for elem in line] if line[0] == '': continue if line[0] == 'END': break if tf and not tf.has_contextual_repr(line[0]): logger.warn('{0} Possibly not recognized'.format(line[0])) if tf: device, value, footprint = parse_ident( tf.get_canonical_repr(line[0]), generic=generic ) else: device, value, footprint = parse_ident(line[0], generic=generic) logger.debug("Trying to insert line : " + line[0]) # print base_tf.get_canonical_repr(line[0]) from tendril.boms.electronics import EntityElnComp item = EntityElnComp() item.define('Undef', device, value, footprint) for idx, col in enumerate(line[1:-1]): if col != '': if device and fpiswire(device): length = Length(col) if length > 0: wireitem = EntityElnComp() wireitem.define( 'Undef', device, value, str(length) ) oboms[idx].insert_component(wireitem) else: num = int(col) if num > 0: for i in range(num): oboms[idx].insert_component(item) for obom in oboms: if verbose: logger.info('Inserting External Bom : ' + obom.descriptor.configname) bomlist.append(obom) cobom = CompositeOutputBom( bomlist, name=name ) return cobom