providers/atypical_plist.rb
# Attempt to read the orderedItems from the Spotlight plist config file.
# Verify that the version matches the expected value.
# If it exists, check to see if it needs to be updated to match the
# changelist passed in.
#
# Note that while orderedItems may kinda sorta look like JSON, it is not.
#
# Params:
#    changelist (Hash) - Key value pairs of attributes that caller wants
#        to have specified values
# Returns:
#    generate_times: True if orderedItems needs to be created
#    update_spotlight: True if orderedItems needs updating to the 'changelist'
#        values
#    write_version: write version attribute
#    items_hash: hash of ordredItems read (if any)
Attempt to read the orderedItems from the Spotlight plist config file.
Verify that the version matches the expected value.
If it exists, check to see if it needs to be updated to match the
changelist passed in.

Note that while orderedItems may kinda sorta look like JSON, it is not.


Attempt to read the orderedItems from the Spotlight plist config file . Verify that the version matches the expected value . If it exists check to see if it needs to be updated to match the changelist passed in . Note that while orderedItems may kinda sorta look like JSON it is not .
def read_spotlight_config(changelist)
    items_hash = nil
    write_version = false
    update_spotlight = false
    generate_items = false
    filename = get_spotlight_plist_filename()
    if filename
        do_log("File is: " + filename)
    else
        do_log("File name is not known")
    end
    if filename && ::File.file?(filename)
        do_log("File exists\n")
        version_cmd = "defaults read #{filename} version"
        version_output = Mixlib::ShellOut.new(version_cmd)
        version_output.run_command
        unless version_output.error? 
            if version_output.stdout.strip != $spotlight_plist_version
                raise "Spotlight pref version mismatch: saw" \
                      "#{version_output}, expected #{$spotlight_plist_version}"
            end
        else 
            generate_items = true
            write_version = true
        end
        key_cmd = "defaults read #{filename} #{$spotlight_key}"
        key_output = Mixlib::ShellOut.new(key_cmd)
        key_output.run_command
        unless key_output.error? 
            do_log("OrderedItems found\n")
            items_hash = key_value_str_to_hash(key_output.stdout)
            update_spotlight = false
            changelist.each do | key, value |
                if items_hash[key] != value
                    update_spotlight = true
                    break
                end
            end
        else
            do_log("OrderedItems not found\n")
            update_spotlight = true
        end
    elsif filename
        do_log("Plist file does not exist\n")
        update_spotlight = true
    end
    do_log(("Update: #{update_spotlight}; Write version #{write_version}\n"))
    return generate_items, update_spotlight, write_version, items_hash
end
def read_spotlight_config ( changelist ) items_hash = nil write_version = false update_spotlight = false generate_items = false filename = get_spotlight_plist_filename ( ) if filename do_log ( "File is: " + filename ) else do_log ( "File name is not known" ) end if filename && :: File . file? ( filename ) do_log ( "File exists\n" ) version_cmd = "defaults read #{filename} version" version_output = Mixlib :: ShellOut . new ( version_cmd ) version_output . run_command unless version_output . error? if version_output . stdout . strip != $spotlight_plist_version raise "Spotlight pref version mismatch: saw" "#{version_output}, expected #{$spotlight_plist_version}" end else generate_items = true write_version = true end key_cmd = "defaults read #{filename} #{$spotlight_key}" key_output = Mixlib :: ShellOut . new ( key_cmd ) key_output . run_command unless key_output . error? do_log ( "OrderedItems found\n" ) items_hash = key_value_str_to_hash ( key_output . stdout ) update_spotlight = false changelist . each do | key , value | if items_hash [ key ] != value update_spotlight = true break end end else do_log ( "OrderedItems not found\n" ) update_spotlight = true end elsif filename do_log ( "Plist file does not exist\n" ) update_spotlight = true end do_log ( ( "Update: #{update_spotlight}; Write version #{write_version}\n" ) ) return generate_items , update_spotlight , write_version , items_hash end
Attempt to read the orderedItems from the Spotlight plist config file.
Attempt to read the orderedItems from the Spotlight plist config file .
# Make sure version matches. # Will only return stdout if no error # Will only return stdout if no error # If user hasn't changed Spotlight prefs, orderedItems # may not exist
changelist
<not_specific>