How to use the kicost.distributors.global_vars.distributor_dict function in kicost

To help you get started, we’ve selected a few kicost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xesscorp / KiCost / kicost / edas / tools.py View on Github external
def subpartqty_split(components):
    '''@brief Split the components with subparts in different components.
       
       Take each part and the all manufacture/distributors combination
       possibility to split in subpart the components part that have
       more than one manufacture/distributors code.
       For each designator...
       For designator with a "single subpart" check with the quantity
       is more than one.
       
       @param components Part components in a `list()` of `dict()`, format given by the EDA modules.
       @return Same as the input.
    '''
    logger.log(DEBUG_OVERVIEW, 'Splitting subparts in the manufacture / distributors codes...')

    FIELDS_MANF = [d+'#' for d in distributor_dict]
    FIELDS_MANF.append('manf#')

    split_components = {}
    for part_ref, part in components.items():
        try:
            # Divide the subparts in different parts keeping the other fields
            # (reference, description, ...).
            # First search for the used fields to manufacture/distributor numbers
            # and how many subparts are in them. Use the loop also to extract the
            # manufacture/distributor codes in list. Use the maximum of them.
            founded_fields = []
            subparts_qty = 0
            subparts_manf_code = dict()
            for field_code in FIELDS_MANF:
                if field_code in part:
                    subparts_qty_field = len( subpart_list(part[field_code]) )
github xesscorp / KiCost / kicost / edas / eda_altium.py View on Github external
else:
                # Now look for fields that start with 'kicost' and possibly
                # another dot-separated variant field and store their values.
                # Anything else is in a non-kicost namespace.
                key_re = 'kicost(\.{})?:(?P.*)'.format(variant)
                mtch = re.match(key_re, name, flags=re.IGNORECASE)
                if mtch:
                    # The field name is anything that came after the leading
                    # 'kicost' and variant field.
                    name = mtch.group('name')
                    name = field_name_translations.get(name, name)
                    # If the field name isn't for a manufacturer's part
                    # number or a distributors catalog number, then add
                    # it to 'local' if it doesn't start with a distributor
                    # name and colon.
                    if name not in ('manf#', 'manf') and name[:-1] not in distributor_dict:
                        if SEPRTR not in name: # This field has no distributor.
                            name = 'local:' + name # Assign it to a local distributor.
                    for i in range(qty):
                        if len(value)==qty:
                            v = value[i]
                        else:
                            v = value[0] # Footprint is just one for group.
                        # Do not create empty fields. This is useful
                        # when used more than one `manf#` alias in one designator.
                        if v and v!=ALTIUM_NONE:
                            fields[i][field_name_translations.get(hdr.lower(),hdr.lower())] = v.strip()
        return refs, fields
github xesscorp / KiCost / kicost / distributors / mouser / mouser.py View on Github external
def __init__(self, name, scrape_retries, throttle_delay):
        super(dist_mouser, self).__init__(name, distributor_dict[name]['site']['url'],
            scrape_retries, throttle_delay)
        self.browser.start_new_session()
github xesscorp / KiCost / kicost / kicost_gui.py View on Github external
if self.m_listBox_edatool.GetStringSelection():
            for k,v in eda_dict.items():
               if v['label']==self.m_listBox_edatool.GetStringSelection():
                  args.eda_name = v['module'] # The selected EDA module on GUI.
                  break

        # Get the current distributors to scrape.
        #choisen_dist = list(self.m_checkList_dist.GetCheckedItems()) # Only valid on wxPy4.
        choisen_dist = [i for i in range(self.m_checkList_dist.GetCount()) if self.m_checkList_dist.IsChecked(i)]
        if choisen_dist:
            dist_list = []
            #choisen_dist = [self.m_checkList_dist.GetString(idx) for idx in choisen_dist]
            for idx in choisen_dist:
                label = self.m_checkList_dist.GetString(idx)
                for k,v in distributor_dict.items():
                    if v['label']['name']==label:
                        dist_list.append(k)
                        break
        else:
            dist_list = None
        args.include = dist_list

        # Run KiCost main function and print in the log the elapsed time.
        start_time = time.time()
        try:
            #print(args.input, '\n', args.eda_name, '\n', args.output, '\n', args.collapse_refs,
            #    '\n', args.fields, '\n', args.ignore_fields, '\n', args.include, '\n', args.currency)
            kicost(in_file=args.input, eda_name=args.eda_name,
                out_filename=args.output, collapse_refs=args.collapse_refs,
                user_fields=args.fields, ignore_fields=args.ignore_fields,
                group_fields=args.group_fields, translate_fields=args.translate_fields,
github xesscorp / KiCost / kicost / spreadsheet.py View on Github external
# Define the named cell where the total cost can be found.
            workbook.define_name('TotalCost', '={wks_name}!{cell_ref}'.format(
                            wks_name="'" + WORKSHEET_NAME + "'",
                            cell_ref=xl_rowcol_to_cell(next_row, next_col - 1,
                                       row_abs=True,
                                       col_abs=True)))
        next_row += 1

        # Freeze view of the global information and the column headers, but
        # allow the distributor-specific part info to scroll.
        wks.freeze_panes(COL_HDR_ROW, next_col)

        # Make a list of alphabetically-ordered distributors with web distributors before locals.
        logger.log(DEBUG_OVERVIEW, 'Sorting the distributors...')
        web_dists = sorted([d for d in distributor_dict if distributor_dict[d]['type'] != 'local'])
        local_dists = sorted([d for d in distributor_dict if distributor_dict[d]['type'] == 'local'])
        dist_list = web_dists + local_dists

        # Load the part information from each distributor into the sheet.
        logger.log(DEBUG_OVERVIEW, 'Writing the distributor part information...')
        for dist in dist_list:
            dist_start_col = next_col
            next_col = add_dist_to_worksheet(wks, wrk_formats, columns_global,
                                            START_ROW, dist_start_col,
                                            UNIT_COST_ROW, TOTAL_COST_ROW,
                                             refs_col, qty_col, dist, parts, suppress_cat_url)
            # Create a defined range for each set of distributor part data.
            workbook.define_name(
                '{}_part_data'.format(dist), '={wks_name}!{data_range}'.format(
                    wks_name="'" + WORKSHEET_NAME + "'",
                    data_range=xl_range_abs(START_ROW, dist_start_col,
                                            LAST_PART_ROW, next_col - 1)))
github xesscorp / KiCost / kicost / distributors / mouser / mouser.py View on Github external
'''@brief Find the Mouser HTML page for a part number and return the URL and parse tree.
           @param pn Part number `str()`.
           @param extra_search_terms
           @param url
           @param descend
           @return (html `str()` of the page, url)
        '''

        # Use the part number to lookup the part using the site search function, unless a starting url was given.
        if url is None:
            url = distributor_dict[self.name]['site']['url'] + \
                '/Search/Refine.aspx?Keyword=' + urlquote(pn, safe='')
            if extra_search_terms:
                url = url + urlquote(' ' + extra_search_terms, safe='')
        elif url[0] == '/':
            url = distributor_dict[self.name]['site']['url']  + url
        elif url.startswith('..'):
            url = distributor_dict[self.name]['site']['url']  + '/Search/' + url

        # Open the URL, read the HTML from it, and parse it into a tree structure.
        try:
            html = self.browser.scrape_URL(url)
        except Exception as ex:
            self.logger.log(DEBUG_OBSESSIVE,'No HTML page for {} from {}'.format(pn, self.name))
            raise PartHtmlError

        # Abort if the part number isn't in the HTML somewhere.
        # (Only use the numbers and letters to compare PN to HTML.)
        if re.sub('[\W_]','',str.lower(pn)) not in re.sub('[\W_]','',str.lower(str(html))):
            self.logger.log(DEBUG_OBSESSIVE,'No part number {} in HTML page from {}'.format(pn, self.name))
            raise PartHtmlError