def _compose_attribute_file(attributes):
    """Make the contents of an osg attributes file"""

    def islist(var):
        return isinstance(var, list)

    variable_string = ""
    export_string = ""
    # keep a list of array variables
    array_vars = {}
    keys = sorted(attributes.keys())
    for key in keys:
        value = attributes[key]
        if value is None:
            variable_string += "# " + key + " is undefined\n"
            continue
        # Special case for SOFTWARE-1567 (let user explicitly unset OSG_APP)
        if key == 'OSG_APP' and (value == 'UNSET' or (islist(value) and 'UNSET' in value)):
            variable_string += 'unset OSG_APP\n'
        elif islist(value):
            for item in value:
                variable_string += '%s="%s"\n' % (key, item)
        else:
            variable_string += '%s="%s"\n' % (key, value)
        if len(key.split('[')) > 1:
            real_key = key.split('[')[0]
            if real_key not in array_vars:
                export_string += "export %s\n" % key.split('[')[0]
                array_vars[real_key] = ""
        else:
            # 'OSG_APP' is a special case for SOFTWARE-1567
            if value is not None and not (key == 'OSG_APP' and value == 'UNSET'):
                export_string += "export %s\n" % key

    file_contents = """\
#!/bin/sh
#---------- This file automatically generated by osg-configure
#---------- This is periodically overwritten.  DO NOT HAND EDIT
#---------- Instead, write any environment variable customizations into
#---------- the config.ini [Local Settings] section, as documented here:
#---------- https://opensciencegrid.github.io/docs/other/configuration-with-osg-configure/#local-settings
#---  variables -----
%s
#--- export variables -----
%s
""" % (variable_string, export_string)
    return file_contents