Module: Facter::Util::Macosx

### Home Classes Methods

### In Files

- lib/facter/util/macosx.rb

### Methods

- ::hardware_overview
- ::intern_xml
- ::os_overview
- ::profiler_data
- ::profiler_xml
- ::sw_vers

### Files

- LICENSE
- Rakefile
- THANKS

### Class/Module Index

Quicksearch

- Facter
- Facter::Application
- Facter::Manufacturer
- Facter::Memory
- Facter::NetMask
- Facter::Util
- Facter::Util::CFPropertyList
- Facter::Util::CFPropertyList::CFArray
- Facter::Util::CFPropertyList::CFBoolean
- Facter::Util::CFPropertyList::CFData
- Facter::Util::CFPropertyList::CFDate
- Facter::Util::CFPropertyList::CFDictionary
- Facter::Util::CFPropertyList::CFInteger
- Facter::Util::CFPropertyList::CFReal
- Facter::Util::CFPropertyList::CFString
- Facter::Util::CFPropertyList::CFType
- Facter::Util::CFPropertyList::XML
- Facter::Util::Collection
- Facter::Util::CompositeLoader
- Facter::Util::Config
- Facter::Util::Confine
- Facter::Util::DirectoryLoader
- Facter::Util::DirectoryLoader::NoSuchDirectoryError
- Facter::Util::EC2
- Facter::Util::Fact
- Facter::Util::FileRead
- Facter::Util::IP
- Facter::Util::IP::Windows
- Facter::Util::IP::Windows::Bindings4
- Facter::Util::IP::Windows::Bindings6
- Facter::Util::Loader
- Facter::Util::Macaddress
- Facter::Util::Macaddress::Darwin
- Facter::Util::Macaddress::Windows
- Facter::Util::Macosx
- Facter::Util::MonkeyPatches
- Facter::Util::MonkeyPatches::Lines
- Facter::Util::NothingLoader
- Facter::Util::Parser
- Facter::Util::Parser::Base
- Facter::Util::Parser::JsonParser
- Facter::Util::Parser::KeyValuePairOutputFormat
- Facter::Util::Parser::NothingParser
- Facter::Util::Parser::PowershellParser
- Facter::Util::Parser::ScriptParser
- Facter::Util::Parser::TextParser
- Facter::Util::Parser::YamlParser
- Facter::Util::Processor
- Facter::Util::Registry
- Facter::Util::Resolution
- Facter::Util::SolarisZones
- Facter::Util::Uptime
- Facter::Util::Values
- Facter::Util::Virtual
- Facter::Util::Vlans
- Facter::Util::WMI
- Facter::Util::Xendomains
- Plist
- Plist::Emit
- Plist::Listener
- Plist::PArray
- Plist::PData
- Plist::PDate
- Plist::PDict
- Plist::PFalse
- Plist::PInteger
- Plist::PKey
- Plist::PList
- Plist::PReal
- Plist::PString
- Plist::PTag
- Plist::PTrue
- Plist::StreamParser
- CFFormatError
- CFPlistError
- CFTypeError
- IO
- Object
- String

No matching classes.

# Facter::Util::Macosx

macosx.rb Support methods for Apple OSX facts

Copyright (C) 2007 Jeff McCune Author: Jeff McCune <jeff.mccune@northstarlabs.net>

### Constants

Plist_Xml_Doctype

### Public Class Methods

hardware_overview() click to toggle source

    # File lib/facter/util/macosx.rb, line 50
    def self.hardware_overview
      profiler_data("SPHardwareDataType")
    end

intern_xml(xml) click to toggle source

    # File lib/facter/util/macosx.rb, line 22
    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 = Facter::Util::CFPropertyList::List.new
      begin
        plist.load_str(xml)
      rescue => e
        fail("A plist file could not be properly read by Facter::Util::CFPropertyList: #{e.inspect}")
      end
      Facter::Util::CFPropertyList.native_types(plist.value)
    end

os_overview() click to toggle source

    # File lib/facter/util/macosx.rb, line 54
    def self.os_overview
      profiler_data("SPSoftwareDataType")
    end

profiler_data(data_field) click to toggle source

Return an xml result, modified as we need it.

    # File lib/facter/util/macosx.rb, line 39
    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) click to toggle source

JJM I'd really like to dynamically generate these methods by looking at the _name key of the _items dict for each _dataType

    # File lib/facter/util/macosx.rb, line 18
    def self.profiler_xml(data_field)
      Facter::Util::Resolution.exec("/usr/sbin/system_profiler -xml #{data_field}")
    end

sw_vers() click to toggle source

    # File lib/facter/util/macosx.rb, line 58
    def self.sw_vers
      ver = Hash.new
      [ "productName", "productVersion", "buildVersion" ].each do |option|
        ver["macosx_#{option}"] = Facter::Util::Resolution.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

[Validate]

Generated with the Darkfish Rdoc Generator 2.