Example #1
0
def main():
    """
    The tendril-genvmaps script entry point.
    """
    parser = _get_parser()
    args = parser.parse_args()
    if args.all:
        run(force=args.force, lazy=args.lazy)
        return

    if not args.vendor_name:
        parser.print_help()
        return

    from tendril.sourcing.electronics import get_vendor_by_name
    from tendril.sourcing.electronics import vendor_list
    v = get_vendor_by_name(args.vendor_name)
    if not v:
        parser.print_help()
        print("")
        print("recognized vendors: ")

        for v in vendor_list:
            print("  {0:<20} {1}".format(v._name, v.name))
        return

    run(v, args.force, args.lazy)
Example #2
0
def main():
    """
    The tendril-genvmaps script entry point.
    """
    parser = _get_parser()
    args = parser.parse_args()
    if args.all:
        run()
        return

    if not args.vendor_name:
        parser.print_help()
        return

    from tendril.sourcing.electronics import get_vendor_by_name
    from tendril.sourcing.electronics import vendor_list
    v = get_vendor_by_name(args.vendor_name)
    if not v:
        parser.print_help()
        print("")
        print("recognized vendors: ")

        for v in vendor_list:
            print("  {0:<20} {1}".format(v._name, v.name))
        return

    run(v)
Example #3
0
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'))
Example #4
0
def main():
    parser = argparse.ArgumentParser(
        description='(Re)generate vendor map audits.',
        prog='tendril-genvmapaudit')
    add_base_options(parser)
    parser.add_argument('vendor_name',
                        metavar='VENDOR_NAME',
                        type=str,
                        nargs='?',
                        help='Name of the vendor.')
    parser.add_argument(
        '--all',
        '-a',
        action='store_true',
        default=False,
        help='Run for all vendors. If used, will ignore VENDOR_NAME.')
    parser.add_argument(
        '--force',
        '-f',
        action='store_true',
        default=False,
        help='Regenerate for all parts, even if they are not stale.')
    parser.add_argument(
        '--lazy',
        '-l',
        action='store_true',
        default=False,
        help="Don't regenerate for parts which exist, even if they are stale.")

    args = parser.parse_args()
    if args.all:
        run(force=args.force)
        return

    if not args.vendor_name:
        parser.print_help()
        return

    from tendril.sourcing.electronics import get_vendor_by_name
    from tendril.sourcing.electronics import vendor_list
    v = get_vendor_by_name(args.vendor_name)
    if not v:
        parser.print_help()
        print("")
        print("recognized vendors: ")

        for v in vendor_list:
            print("  {0:<20} {1}".format(v.cname, v.name))
        return

    run(v, args.force, args.lazy)
Example #5
0
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'))
Example #6
0
def get_customs_invoice(serialno):
    documents = docstore.controller.get_sno_documents(serialno=serialno)
    inv_yaml = None
    for document in documents:
        if document.doctype == 'INVOICE-DATA-YAML':
            inv_yaml = document.docpath
    if not inv_yaml:
        raise ValueError('Invoice data not found for : ' + serialno)
    with docstore.docstore_fs.open(inv_yaml, 'r') as f:
        inv_data = yaml.load(f)

    inv_format = inv_data['invoice_format']

    if inv_format == 'analogdevices':
        from tendril.sourcing import pricelist
        invoice_class = pricelist.AnalogDevicesInvoice
    elif inv_format == 'digikey':
        from tendril.sourcing.vendors import digikey
        invoice_class = digikey.DigiKeyInvoice
    else:
        raise ValueError('Unrecognized Customs Invoice Format : ' +
                         inv_format)

    from tendril.sourcing import electronics
    vobj = electronics.get_vendor_by_name(inv_format)

    workspace_name = get_tempname()
    docstore.copy_docs_to_workspace(serialno=serialno,
                                    workspace=workspace_name,
                                    clearws=True,
                                    fs=temp_fs)

    invoice = invoice_class(
        vobj,
        temp_fs.getsyspath(
            fs.path.join(workspace_name, 'inv_data.yaml')
        )
    )

    temp_fs.removedir(workspace_name, recursive=True, force=True)
    return invoice
Example #7
0
def get_customs_invoice(serialno):
    documents = docstore.controller.get_sno_documents(serialno=serialno)
    inv_yaml = None
    for document in documents:
        if document.doctype == 'INVOICE-DATA-YAML':
            inv_yaml = document.docpath
    if not inv_yaml:
        raise ValueError('Invoice data not found for : ' + serialno)
    with docstore.docstore_fs.open(inv_yaml, 'r') as f:
        inv_data = yaml.load(f)

    inv_format = inv_data['invoice_format']

    if inv_format == 'analogdevices':
        from tendril.sourcing import pricelist
        invoice_class = pricelist.AnalogDevicesInvoice
    elif inv_format == 'digikey':
        from tendril.sourcing import digikey
        invoice_class = digikey.DigiKeyInvoice
    else:
        raise ValueError('Unrecognized Customs Invoice Format : ' +
                         inv_format)

    from tendril.sourcing import electronics
    vobj = electronics.get_vendor_by_name(inv_format)

    workspace_name = get_tempname()
    docstore.copy_docs_to_workspace(serialno=serialno,
                                    workspace=workspace_name,
                                    clearws=True,
                                    fs=temp_fs)

    invoice = invoice_class(
        vobj,
        temp_fs.getsyspath(
            fs.path.join(workspace_name, 'inv_data.yaml')
        )
    )

    temp_fs.removedir(workspace_name, recursive=True, force=True)
    return invoice
Example #8
0
def main():
    parser = argparse.ArgumentParser(
        description='(Re)generate vendor map audits.',
        prog='tendril-genvmapaudit'
    )
    parser.add_argument(
        'vendor_name', metavar='VENDOR_NAME', type=str, nargs='?',
        help='Name of the vendor.'
    )
    parser.add_argument(
        '--all', '-a', action='store_true', default=False,
        help='Run for all vendors. If used, will ignore VENDOR_NAME.'
    )

    args = parser.parse_args()
    if args.all:
        run()
        return

    if not args.vendor_name:
        parser.print_help()
        return

    from tendril.sourcing.electronics import get_vendor_by_name
    from tendril.sourcing.electronics import vendor_list
    v = get_vendor_by_name(args.vendor_name)
    if not v:
        parser.print_help()
        print("")
        print("recognized vendors: ")

        for v in vendor_list:
            print("  {0:<20} {1}".format(v._name, v.name))
        return

    run(v)