def _get_isinfo(self): # qty = electronics_qty.get_compliant_qty(self.ident, self.quantity) if self.ident.startswith("PCB"): from tendril.entityhub.modules import get_pcb_lib pcblib = get_pcb_lib() ident = self.ident[len("PCB ") :] if ident in pcblib.keys(): symbol = pcblib[ident] else: self._isinfo = None self._sourcing_exception = SourcingIdentNotRecognized( self.parent.sourcing_policy, self.ident, self.refdeslist ) return else: try: symbol = get_symbol(self.ident) except NoGedaSymbolException: self._isinfo = None self._sourcing_exception = SourcingIdentNotRecognized( self.parent.sourcing_policy, self.ident, self.refdeslist ) return try: self._isinfo = symbol.indicative_sourcing_info[0] except IndexError: self._isinfo = None self._sourcing_exception = SourcingIdentNotSourceable( self.parent.sourcing_policy, self.ident, self.refdeslist )
def main(): """ The tendril-gedaif script entry point. """ parser = _get_parser() args = parser.parse_args() done = False verbose = args.verbose or args.pricing or args.utilization idents = gsymlib.gsymlib_idents if args.search: if args.regex: rex = re.compile(args.search) ridents = [ident for ident in idents if rex.search(ident)] else: ridents = [ident for ident in idents if args.search in ident] rsymbols = [gsymlib.get_symbol(ident) for ident in ridents] if len(rsymbols): terminal.render_hline() if args.pricing is True: pricing = args.quantity else: pricing = False for symbol in rsymbols: render_symbol(symbol, verbose, args.utilization, pricing) if not verbose: terminal.render_hline() done = True if not done: parser.print_help()
def render_search_results(): form = SourcingIdentSearch() if form.validate_on_submit(): ident = form.ident.data qty = form.qty.data if not qty: qty = electronics_qty.get_compliant_qty(ident, 1) form.qty.data = qty try: qty = int(qty) except ValueError: qty = Length(qty) vl = [] for vname in form.vendors.data: v = get_vendor_by_name(vname) if not v: raise ValueError vl.append(v) try: vsi = get_sourcing_information(ident, qty, avendors=vl, allvendors=True, get_all=form.get_all.data) except SourcingException: vsi = [] symbol = get_symbol(ident) stage = { 'crumbroot': '/sourcing', 'breadcrumbs': [ Crumb(name="Sourcing", path=""), Crumb(name="Vendors", path="vendors/"), Crumb(name="Search Results", path="vendors/results") ], 'isinfos': vsi, 'ident': ident, 'symbol': symbol, } return render_template('vendors_search_results.html', stage=stage, form=form, pagetitle='Sourcing Search Results') else: return redirect(url_for('.main'))
def render_search_results(): form = SourcingIdentSearch() if form.validate_on_submit(): ident = form.ident.data qty = form.qty.data if not qty: qty = electronics_qty.get_compliant_qty(ident, 1) form.qty.data = qty try: qty = int(qty) except ValueError: qty = Length(qty) vl = [] for vname in form.vendors.data: v = get_vendor_by_name(vname) if not v: raise ValueError vl.append(v) try: vsi = get_sourcing_information( ident, qty, avendors=vl, allvendors=True, get_all=form.get_all.data ) except SourcingException: vsi = [] symbol = get_symbol(ident) stage = {'crumbroot': '/sourcing', 'breadcrumbs': [ Crumb(name="Sourcing", path=""), Crumb(name="Vendors", path="vendors/"), Crumb(name="Search Results", path="vendors/results")], 'isinfos': vsi, 'ident': ident, 'symbol': symbol, } return render_template('vendors_search_results.html', stage=stage, form=form, pagetitle='Sourcing Search Results') else: return redirect(url_for('.main'))
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_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)