kifield/kifield.py
def insert_part_fields(part_fields_dict, filenames, recurse, group_components, backup, no_range):
    """Insert part fields from a dictionary into a spreadsheet, part library, or schematic."""

    # No files backed-up yet, so clear list of file names.
    global backedup_files
    backedup_files = []

    logger.log(
        DEBUG_OVERVIEW, "Inserting extracted fields into files {}.".format(filenames)
    )

    # Table of insertion functions for each file type.
    insertion_functions = {
        ".xlsx": insert_part_fields_into_xlsx,
        ".tsv": insert_part_fields_into_csv,
        ".csv": insert_part_fields_into_csv,
        ".sch": insert_part_fields_into_sch,
        ".kicad_sch": insert_part_fields_into_sch_V6,
        ".lib": insert_part_fields_into_lib,
        ".kicad_sym": insert_part_fields_into_lib_V6,
        ".dcm": insert_part_fields_into_dcm,
    }

    if part_fields_dict is None or len(part_fields_dict) == 0:
        logger.warn("There are no part field values to insert!")
        return

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

    # Insert the part fields into each file.
    for f in filenames:
        try:
            logger.log(DEBUG_DETAILED, "Inserting fields into {}.".format(f))

            # Set the insertion function based on the file extension.
            f_extension = os.path.splitext(f)[1].lower()
            insertion_function = insertion_functions[f_extension]

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

        else:
            try:
                insertion_function(
                    part_fields_dict, f, recurse, group_components, backup, no_range
                )

            except IOError:
                logger.warn("Unable to write to file: {}.".format(f))
Insert part fields from a dictionary into a spreadsheet, part library, or schematic.
Insert part fields from a dictionary into a spreadsheet, part library, or schematic.
Insert part fields from a dictionary into a spreadsheet part library or schematic .
def insert_part_fields(part_fields_dict, filenames, recurse, group_components, backup, no_range):
    global backedup_files
    backedup_files = []
    logger.log(
        DEBUG_OVERVIEW, "Inserting extracted fields into files {}.".format(filenames)
    )
    insertion_functions = {
        ".xlsx": insert_part_fields_into_xlsx,
        ".tsv": insert_part_fields_into_csv,
        ".csv": insert_part_fields_into_csv,
        ".sch": insert_part_fields_into_sch,
        ".kicad_sch": insert_part_fields_into_sch_V6,
        ".lib": insert_part_fields_into_lib,
        ".kicad_sym": insert_part_fields_into_lib_V6,
        ".dcm": insert_part_fields_into_dcm,
    }
    if part_fields_dict is None or len(part_fields_dict) == 0:
        logger.warn("There are no part field values to insert!")
        return
    if type(filenames) == str:
        filenames = [filenames]
    for f in filenames:
        try:
            logger.log(DEBUG_DETAILED, "Inserting fields into {}.".format(f))
            f_extension = os.path.splitext(f)[1].lower()
            insertion_function = insertion_functions[f_extension]
        except KeyError:
            logger.warn("Unknown file type for field insertion: {}".format(f))
        else:
            try:
                insertion_function(
                    part_fields_dict, f, recurse, group_components, backup, no_range
                )
            except IOError:
                logger.warn("Unable to write to file: {}.".format(f))
def insert_part_fields ( part_fields_dict , filenames , recurse , group_components , backup , no_range ) : global backedup_files backedup_files = [ ] logger . log ( DEBUG_OVERVIEW , "Inserting extracted fields into files {}." . format ( filenames ) ) insertion_functions = { ".xlsx" : insert_part_fields_into_xlsx , ".tsv" : insert_part_fields_into_csv , ".csv" : insert_part_fields_into_csv , ".sch" : insert_part_fields_into_sch , ".kicad_sch" : insert_part_fields_into_sch_V6 , ".lib" : insert_part_fields_into_lib , ".kicad_sym" : insert_part_fields_into_lib_V6 , ".dcm" : insert_part_fields_into_dcm , } if part_fields_dict is None or len ( part_fields_dict ) == 0 : logger . warn ( "There are no part field values to insert!" ) return if type ( filenames ) == str : filenames = [ filenames ] for f in filenames : try : logger . log ( DEBUG_DETAILED , "Inserting fields into {}." . format ( f ) ) f_extension = os . path . splitext ( f ) [ 1 ] . lower ( ) insertion_function = insertion_functions [ f_extension ] except KeyError : logger . warn ( "Unknown file type for field insertion: {}" . format ( f ) ) else : try : insertion_function ( part_fields_dict , f , recurse , group_components , backup , no_range ) except IOError : logger . warn ( "Unable to write to file: {}." . format ( f ) )
Insert part fields from a dictionary into a spreadsheet, part library, or schematic.
Insert part fields from a dictionary into a spreadsheet part library or schematic .
"""Insert part fields from a dictionary into a spreadsheet, part library, or schematic.""" # No files backed-up yet, so clear list of file names. # Table of insertion functions for each file type. # If inserting into a single file, make a one-entry list. # Insert the part fields into each file. # Set the insertion function based on the file extension.
part_fields_dict
filenames
recurse
group_components
backup
no_range