How to use the kicost.edas.tools.field_name_translations.get 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 / eda_altium.py View on Github external
def extract_fields_row(row, variant, header):
        '''Extract XML fields from the part in a library or schematic.'''
        
        # First get the references and the quantities of elements in each rwo group.
        header_translated = [field_name_translations.get(hdr.lower(),hdr.lower()) for hdr in header]
        hdr_refs = [i for i, x in enumerate(header_translated) if x == "refs"]
        if not hdr_refs:
            raise ValueError('Not founded the part designators/references in the BOM.\nTry to generate the file again at Altium.')
        else:
            hdr_refs = hdr_refs[0]
        refs = re.split(ALTIUM_PART_SEPRTR, extract_field(row, header[hdr_refs].lower()) )
        if sys.version_info >= (3,0):
            header_valid = header.copy()
        else:
            header_valid = copy.copy(header)
        header_valid.remove(header[hdr_refs])
        try:
            hdr_qty = [i for i, x in enumerate(header_translated) if x == "qty"][0]
            qty = int( extract_field(row, header[hdr_qty].lower()) )
            header_valid.remove(header[hdr_qty])
            if qty!=len(refs):
github xesscorp / KiCost / kicost / edas / eda_altium.py View on Github external
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()
            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()