kifield/kifield.py
def extract_part_fields_from_dcm(
    filename, inc_field_names=None, exc_field_names=None, recurse=False
):
    """Return a dictionary of part fields extracted from a part description file."""

    logger.log(
        DEBUG_OVERVIEW,
        "Extracting fields {}, -{} from part description file {}.".format(
            inc_field_names, exc_field_names, filename
        ),
    )

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

    try:
        dcm = Dcm(filename)
    except IOError:
        return part_fields_dict  # Return empty part fields dict if no DCM file found.

    # Start with DCM field names and keep the desired ones.
    field_names = deepcopy(dcm_field_names)
    cull_list(field_names, inc_field_names, exc_field_names)

    # Go through each component, extracting its fields.
    for component in dcm.components:
        component_name = component.name

        # Get the fields and their values from the component.
        part_fields = {}
        for name in field_names:
            value = getattr(component, name, None)
            if value is not None:
                logger.log(
                    DEBUG_OBSESSIVE,
                    "Extracted part description: {} {} {}.".format(
                        component_name, name, value
                    ),
                )
                part_fields[name] = value

        # Create a dictionary entry for this library component.
        part_fields_dict[component_name] = part_fields

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

    return part_fields_dict
Return a dictionary of part fields extracted from a part description file.
Return a dictionary of part fields extracted from a part description file.
Return a dictionary of part fields extracted from a part description file .
def extract_part_fields_from_dcm(
    filename, inc_field_names=None, exc_field_names=None, recurse=False
):
    logger.log(
        DEBUG_OVERVIEW,
        "Extracting fields {}, -{} from part description file {}.".format(
            inc_field_names, exc_field_names, filename
        ),
    )
    part_fields_dict = {}  
    try:
        dcm = Dcm(filename)
    except IOError:
        return part_fields_dict  
    field_names = deepcopy(dcm_field_names)
    cull_list(field_names, inc_field_names, exc_field_names)
    for component in dcm.components:
        component_name = component.name
        part_fields = {}
        for name in field_names:
            value = getattr(component, name, None)
            if value is not None:
                logger.log(
                    DEBUG_OBSESSIVE,
                    "Extracted part description: {} {} {}.".format(
                        component_name, name, value
                    ),
                )
                part_fields[name] = value
        part_fields_dict[component_name] = part_fields
    if logger.isEnabledFor(DEBUG_DETAILED):
        print("Extracted Part Fields:")
        pprint(part_fields_dict)
    return part_fields_dict
def extract_part_fields_from_dcm ( filename , inc_field_names = None , exc_field_names = None , recurse = False ) : logger . log ( DEBUG_OVERVIEW , "Extracting fields {}, -{} from part description file {}." . format ( inc_field_names , exc_field_names , filename ) , ) part_fields_dict = { } try : dcm = Dcm ( filename ) except IOError : return part_fields_dict field_names = deepcopy ( dcm_field_names ) cull_list ( field_names , inc_field_names , exc_field_names ) for component in dcm . components : component_name = component . name part_fields = { } for name in field_names : value = getattr ( component , name , None ) if value is not None : logger . log ( DEBUG_OBSESSIVE , "Extracted part description: {} {} {}." . format ( component_name , name , value ) , ) part_fields [ name ] = value part_fields_dict [ component_name ] = part_fields if logger . isEnabledFor ( DEBUG_DETAILED ) : print ( "Extracted Part Fields:" ) pprint ( part_fields_dict ) return part_fields_dict
Return a dictionary of part fields extracted from a part description file.
Return a dictionary of part fields extracted from a part description file .
"""Return a dictionary of part fields extracted from a part description file.""" # Start with an empty part dictionary. # Return empty part fields dict if no DCM file found. # Start with DCM field names and keep the desired ones. # Go through each component, extracting its fields. # Get the fields and their values from the component. # Create a dictionary entry for this library component.
filename
inc_field_names
exc_field_names
recurse