kifield/kifield.py
def extract_part_fields(
    filenames, inc_field_names=None, exc_field_names=None, recurse=False
):
    """Return a dictionary of part fields extracted from a spreadsheet, part library, DCM, or schematic."""

    logger.log(
        DEBUG_OVERVIEW,
        "Extracting fields +{}, -{} from files {}.".format(
            inc_field_names, exc_field_names, filenames
        ),
    )

    # Table of extraction functions for each file type.
    extraction_functions = {
        ".xlsx": extract_part_fields_from_xlsx,
        ".tsv": extract_part_fields_from_csv,
        ".csv": extract_part_fields_from_csv,
        ".sch": extract_part_fields_from_sch,
        ".kicad_sch": extract_part_fields_from_sch_V6,
        ".lib": extract_part_fields_from_lib,
        ".kicad_sym": extract_part_fields_from_lib_V6,
        ".dcm": extract_part_fields_from_dcm,
    }

    part_fields_dict = {}  # Start with empty part field dictionary.

    # If extracting from only a single file, make a one-entry list.
    if type(filenames) == str:
        filenames = [filenames]

    # Extract the fields from the parts in each file.
    for f in filenames:
        try:
            logger.log(DEBUG_DETAILED, "Extracting fields from {}.".format(f))

            # Set the extraction function based on the file extension.
            f_extension = os.path.splitext(f)[1].lower()
            extraction_function = extraction_functions[f_extension]

        except KeyError:
            logger.warn("Unknown file type for field extraction: {}.".format(f))

        else:
            # Call the extraction function.
            try:
                f_part_fields_dict = extraction_function(
                    f, inc_field_names, exc_field_names, recurse
                )

            except IOError:
                logger.warn("File not found: {}.".format(f))

            else:
                # Add the extracted fields to the total part dictionary.
                part_fields_dict = combine_part_field_dicts(
                    f_part_fields_dict, part_fields_dict
                )

    if logger.isEnabledFor(DEBUG_DETAILED):
        print("Total Extracted Part Fields:")
        pprint(part_fields_dict)

    if part_fields_dict is None or len(part_fields_dict) == 0:
        logger.warn(
            "No part fields were extracted from these files: {}\n  * Did you provide a list of files?\n  * Do these files exist?\n  * Did you annotate your components in the schematic?".format(
                ", ".join(filenames)
            )
        )
        return

    return part_fields_dict
Return a dictionary of part fields extracted from a spreadsheet, part library, DCM, or schematic.
Return a dictionary of part fields extracted from a spreadsheet, part library, DCM, or schematic.
Return a dictionary of part fields extracted from a spreadsheet part library DCM or schematic .
def extract_part_fields(
    filenames, inc_field_names=None, exc_field_names=None, recurse=False
):
    logger.log(
        DEBUG_OVERVIEW,
        "Extracting fields +{}, -{} from files {}.".format(
            inc_field_names, exc_field_names, filenames
        ),
    )
    extraction_functions = {
        ".xlsx": extract_part_fields_from_xlsx,
        ".tsv": extract_part_fields_from_csv,
        ".csv": extract_part_fields_from_csv,
        ".sch": extract_part_fields_from_sch,
        ".kicad_sch": extract_part_fields_from_sch_V6,
        ".lib": extract_part_fields_from_lib,
        ".kicad_sym": extract_part_fields_from_lib_V6,
        ".dcm": extract_part_fields_from_dcm,
    }
    part_fields_dict = {}  
    if type(filenames) == str:
        filenames = [filenames]
    for f in filenames:
        try:
            logger.log(DEBUG_DETAILED, "Extracting fields from {}.".format(f))
            f_extension = os.path.splitext(f)[1].lower()
            extraction_function = extraction_functions[f_extension]
        except KeyError:
            logger.warn("Unknown file type for field extraction: {}.".format(f))
        else:
            try:
                f_part_fields_dict = extraction_function(
                    f, inc_field_names, exc_field_names, recurse
                )
            except IOError:
                logger.warn("File not found: {}.".format(f))
            else:
                part_fields_dict = combine_part_field_dicts(
                    f_part_fields_dict, part_fields_dict
                )
    if logger.isEnabledFor(DEBUG_DETAILED):
        print("Total Extracted Part Fields:")
        pprint(part_fields_dict)
    if part_fields_dict is None or len(part_fields_dict) == 0:
        logger.warn(
            "No part fields were extracted from these files: {}\n  * Did you provide a list of files?\n  * Do these files exist?\n  * Did you annotate your components in the schematic?".format(
                ", ".join(filenames)
            )
        )
        return
    return part_fields_dict
def extract_part_fields ( filenames , inc_field_names = None , exc_field_names = None , recurse = False ) : logger . log ( DEBUG_OVERVIEW , "Extracting fields +{}, -{} from files {}." . format ( inc_field_names , exc_field_names , filenames ) , ) extraction_functions = { ".xlsx" : extract_part_fields_from_xlsx , ".tsv" : extract_part_fields_from_csv , ".csv" : extract_part_fields_from_csv , ".sch" : extract_part_fields_from_sch , ".kicad_sch" : extract_part_fields_from_sch_V6 , ".lib" : extract_part_fields_from_lib , ".kicad_sym" : extract_part_fields_from_lib_V6 , ".dcm" : extract_part_fields_from_dcm , } part_fields_dict = { } if type ( filenames ) == str : filenames = [ filenames ] for f in filenames : try : logger . log ( DEBUG_DETAILED , "Extracting fields from {}." . format ( f ) ) f_extension = os . path . splitext ( f ) [ 1 ] . lower ( ) extraction_function = extraction_functions [ f_extension ] except KeyError : logger . warn ( "Unknown file type for field extraction: {}." . format ( f ) ) else : try : f_part_fields_dict = extraction_function ( f , inc_field_names , exc_field_names , recurse ) except IOError : logger . warn ( "File not found: {}." . format ( f ) ) else : part_fields_dict = combine_part_field_dicts ( f_part_fields_dict , part_fields_dict ) if logger . isEnabledFor ( DEBUG_DETAILED ) : print ( "Total Extracted Part Fields:" ) pprint ( part_fields_dict ) if part_fields_dict is None or len ( part_fields_dict ) == 0 : logger . warn ( "No part fields were extracted from these files: {}\n  * Did you provide a list of files?\n  * Do these files exist?\n  * Did you annotate your components in the schematic?" . format ( ", " . join ( filenames ) ) ) return return part_fields_dict
Return a dictionary of part fields extracted from a spreadsheet, part library, DCM, or schematic.
Return a dictionary of part fields extracted from a spreadsheet part library DCM or schematic .
"""Return a dictionary of part fields extracted from a spreadsheet, part library, DCM, or schematic.""" # Table of extraction functions for each file type. # Start with empty part field dictionary. # If extracting from only a single file, make a one-entry list. # Extract the fields from the parts in each file. # Set the extraction function based on the file extension. # Call the extraction function. # Add the extracted fields to the total part dictionary.
filenames
inc_field_names
exc_field_names
recurse