Module: Facter::Util::Macosx
- Defined in:
- lib/facter/util/macosx.rb
Overview
macosx.rb Support methods for Apple OSX facts
Copyright © 2007 Jeff McCune Author: Jeff McCune <[email protected]>
Constant Summary collapse
- Plist_Xml_Doctype =
'<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
Class Method Summary collapse
- .hardware_overview ⇒ Object
- .intern_xml(xml) ⇒ Object
- .os_overview ⇒ Object
-
.profiler_data(data_field) ⇒ Object
Return an xml result, modified as we need it.
-
.profiler_xml(data_field) ⇒ Object
JJM I’d really like to dynamically generate these methods by looking at the _name key of the _items dict for each _dataType.
- .sw_vers ⇒ Object
Class Method Details
.hardware_overview ⇒ Object
49 50 51 |
# File 'lib/facter/util/macosx.rb', line 49 def self.hardware_overview profiler_data("SPHardwareDataType") end |
.intern_xml(xml) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/facter/util/macosx.rb', line 21 def self.intern_xml(xml) return nil unless xml bad_xml_doctype = /^.*<!DOCTYPE plist PUBLIC -\/\/Apple Computer.*$/ if xml =~ bad_xml_doctype xml.gsub!( bad_xml_doctype, Plist_Xml_Doctype ) Facter.debug("Had to fix plist with incorrect DOCTYPE declaration") end plist = CFPropertyList::List.new begin plist.load_str(xml) rescue CFFormatError => e raise RuntimeError, "A plist file could not be properly read by CFPropertyList: #{e.}", e.backtrace end CFPropertyList.native_types(plist.value) end |
.os_overview ⇒ Object
53 54 55 |
# File 'lib/facter/util/macosx.rb', line 53 def self.os_overview profiler_data("SPSoftwareDataType") end |
.profiler_data(data_field) ⇒ Object
Return an xml result, modified as we need it.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/facter/util/macosx.rb', line 38 def self.profiler_data(data_field) begin return nil unless parsed_xml = intern_xml(profiler_xml(data_field)) return nil unless data = parsed_xml[0]['_items'][0] data.delete '_name' data rescue return nil end end |
.profiler_xml(data_field) ⇒ Object
JJM I’d really like to dynamically generate these methods by looking at the _name key of the _items dict for each _dataType
17 18 19 |
# File 'lib/facter/util/macosx.rb', line 17 def self.profiler_xml(data_field) Facter::Core::Execution.exec("/usr/sbin/system_profiler -xml #{data_field} 2>/dev/null") end |
.sw_vers ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/facter/util/macosx.rb', line 57 def self.sw_vers ver = Hash.new [ "productName", "productVersion", "buildVersion" ].each do |option| ver["macosx_#{option}"] = Facter::Core::Execution.exec("/usr/bin/sw_vers -#{option}").strip end productversion = ver["macosx_productVersion"] if not productversion.nil? versions = productversion.scan(/(\d+)\.(\d+)\.*(\d*)/)[0] ver["macosx_productversion_major"] = "#{versions[0]}.#{versions[1]}" if versions[2].empty? # 10.x should be treated as 10.x.0 versions[2] = "0" end ver["macosx_productversion_minor"] = versions[2] end ver end |