Method: Puppet::Util::Plist.read_plist_file
- Defined in:
- lib/puppet/util/plist.rb
.read_plist_file(file_path) ⇒ Object
Read a plist file, whether its format is XML or in Apple’s “binary1” format, using the CFPropertyList gem.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppet/util/plist.rb', line 31 def read_plist_file(file_path) # We can't really read the file until we know the source encoding in # Ruby 1.9.x, so we use the magic number to detect it. # NOTE: We used IO.read originally to be Ruby 1.8.x compatible. if read_file_with_offset(file_path, binary_plist_magic_number.length) == binary_plist_magic_number plist_obj = new_cfpropertylist(:file => file_path) return convert_cfpropertylist_to_native_types(plist_obj) else plist_data = open_file_with_args(file_path, "r:UTF-8") plist = parse_plist(plist_data, file_path) return plist if plist Puppet.debug "Plist #{file_path} ill-formatted, converting with plutil" begin plist = Puppet::Util::Execution.execute(['/usr/bin/plutil', '-convert', 'xml1', '-o', '-', file_path], { :failonfail => true, :combine => true }) return parse_plist(plist) rescue Puppet::ExecutionFailure => detail = _("Cannot read file %{file_path}; Puppet is skipping it.") % { file_path: file_path } += '\n' + _("Details: %{detail}") % { detail: detail } Puppet.warning() end end nil end |