summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-27 17:50:21 -0600
committerLuke Kanies <luke@madstop.com>2009-01-27 18:06:00 -0600
commit1f1fa9bcecfb6d137219819c9aeefdc41f3f9dce (patch)
tree2e9a905fd427c82bf5a9963dda5f290461a763ca /lib
parent5f202c9aaa24581b235d3d9613b3e6ec6ac91d34 (diff)
downloadfacter-1f1fa9bcecfb6d137219819c9aeefdc41f3f9dce.tar.gz
facter-1f1fa9bcecfb6d137219819c9aeefdc41f3f9dce.tar.xz
facter-1f1fa9bcecfb6d137219819c9aeefdc41f3f9dce.zip
Fixing #1838 - profiler failures don't throw exceptions
Also added tests to the macosx code; it's much cleaner and actually tested now. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/util/macosx.rb34
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/facter/util/macosx.rb b/lib/facter/util/macosx.rb
index 2704a7c..d32d257 100644
--- a/lib/facter/util/macosx.rb
+++ b/lib/facter/util/macosx.rb
@@ -19,24 +19,38 @@
module Facter::Macosx
require 'thread'
require 'facter/util/plist'
+ require 'facter/util/resolution'
# JJM I'd really like to dynamically generate these methods
# by looking at the _name key of the _items dict for each _dataType
+ def self.profiler_xml(data_field)
+ Facter::Util::Resolution.exec("/usr/sbin/system_profiler -xml #{data_field}")
+ end
+
+ def self.intern_xml(xml)
+ return nil unless xml
+ Plist::parse_xml(xml)
+ end
+
+ # Return an xml result, modified as we need it.
+ 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
+
def self.hardware_overview
- # JJM Perhaps we should cache the XML data in a "class" level object.
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPHardwareDataType}
- system_hardware = top_level_plist[0]['_items'][0]
- system_hardware.delete '_name'
- system_hardware
+ profiler_data("SPHardwareDataType")
end
- # SPSoftwareDataType
def self.os_overview
- top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPSoftwareDataType}
- os_stuff = top_level_plist[0]['_items'][0]
- os_stuff.delete '_name'
- os_stuff
+ profiler_data("SPSoftwareDataType")
end
def self.sw_vers