scripts/schema_reader.py
def duplicate_reusable_fieldsets(schema, fields_flat, fields_nested):
    """Copies reusable field definitions to their expected places"""
    # Note: across this schema reader, functions are modifying dictionaries passed
    # as arguments, which is usually a risk of unintended side effects.
    # Here it simplifies the nesting of 'group' under 'user',
    # which is in turn reusable in a few places.
    if 'reusable' in schema:
        for new_nesting in schema['reusable']['expected']:

            # List field set names expected under another field set.
            # E.g. host.nestings = [ 'geo', 'os', 'user' ]
            if 'nestings' not in fields_nested[new_nesting]:
                fields_nested[new_nesting]['nestings'] = []
            fields_nested[new_nesting]['nestings'].append(schema['name'])

            # Explicitly list all leaf fields coming from field set reuse.
            for (name, field) in schema['fields'].items():
                # Poor folks deepcopy, sorry -- A Rubyist
                copied_field = field.copy()
                if 'multi_fields' in copied_field:
                    copied_field['multi_fields'] = copied_field['multi_fields'].copy()

                destination_name = new_nesting + '.' + field['flat_name']
                copied_field['flat_name'] = destination_name
                copied_field['original_fieldset'] = schema['name']

                fields_flat[destination_name] = copied_field

                # Nested: use original flat name under the destination fieldset
                fields_nested[new_nesting]['fields'][field['flat_name']] = copied_field
Copies reusable field definitions to their expected places
Copies reusable field definitions to their expected places
Copies reusable field definitions to their expected places
def duplicate_reusable_fieldsets(schema, fields_flat, fields_nested):
    if 'reusable' in schema:
        for new_nesting in schema['reusable']['expected']:
            if 'nestings' not in fields_nested[new_nesting]:
                fields_nested[new_nesting]['nestings'] = []
            fields_nested[new_nesting]['nestings'].append(schema['name'])
            for (name, field) in schema['fields'].items():
                copied_field = field.copy()
                if 'multi_fields' in copied_field:
                    copied_field['multi_fields'] = copied_field['multi_fields'].copy()
                destination_name = new_nesting + '.' + field['flat_name']
                copied_field['flat_name'] = destination_name
                copied_field['original_fieldset'] = schema['name']
                fields_flat[destination_name] = copied_field
                fields_nested[new_nesting]['fields'][field['flat_name']] = copied_field
def duplicate_reusable_fieldsets ( schema , fields_flat , fields_nested ) : if 'reusable' in schema : for new_nesting in schema [ 'reusable' ] [ 'expected' ] : if 'nestings' not in fields_nested [ new_nesting ] : fields_nested [ new_nesting ] [ 'nestings' ] = [ ] fields_nested [ new_nesting ] [ 'nestings' ] . append ( schema [ 'name' ] ) for ( name , field ) in schema [ 'fields' ] . items ( ) : copied_field = field . copy ( ) if 'multi_fields' in copied_field : copied_field [ 'multi_fields' ] = copied_field [ 'multi_fields' ] . copy ( ) destination_name = new_nesting + '.' + field [ 'flat_name' ] copied_field [ 'flat_name' ] = destination_name copied_field [ 'original_fieldset' ] = schema [ 'name' ] fields_flat [ destination_name ] = copied_field fields_nested [ new_nesting ] [ 'fields' ] [ field [ 'flat_name' ] ] = copied_field
Copies reusable field definitions to their expected places
Copies reusable field definitions to their expected places
"""Copies reusable field definitions to their expected places""" # Note: across this schema reader, functions are modifying dictionaries passed # as arguments, which is usually a risk of unintended side effects. # Here it simplifies the nesting of 'group' under 'user', # which is in turn reusable in a few places. # List field set names expected under another field set. # E.g. host.nestings = [ 'geo', 'os', 'user' ] # Explicitly list all leaf fields coming from field set reuse. # Poor folks deepcopy, sorry -- A Rubyist # Nested: use original flat name under the destination fieldset
schema
fields_flat
fields_nested