diff options
-rw-r--r-- | CHANGELOG | 46 | ||||
-rw-r--r-- | Rakefile | 36 | ||||
-rw-r--r-- | autotest/discover.rb | 4 | ||||
-rw-r--r-- | autotest/facter_rspec.rb | 20 | ||||
-rw-r--r-- | autotest/rspec.rb | 110 | ||||
-rwxr-xr-x | bin/facter | 50 | ||||
-rw-r--r-- | conf/osx/PackageInfo.plist | 60 | ||||
-rwxr-xr-x | conf/osx/createpackage.sh | 34 | ||||
-rwxr-xr-x | install.rb | 452 | ||||
-rw-r--r-- | lib/facter.rb | 22 | ||||
-rw-r--r-- | lib/facter/kernel.rb | 4 | ||||
-rw-r--r-- | lib/facter/lsb.rb | 10 | ||||
-rw-r--r-- | lib/facter/manufacturer.rb | 16 | ||||
-rw-r--r-- | lib/facter/memory.rb | 9 | ||||
-rw-r--r-- | lib/facter/netmask.rb | 8 | ||||
-rw-r--r-- | lib/facter/network.rb | 9 | ||||
-rw-r--r-- | lib/facter/operatingsystem.rb | 8 | ||||
-rw-r--r-- | lib/facter/operatingsystemrelease.rb | 4 | ||||
-rw-r--r-- | lib/facter/timezone.rb | 2 | ||||
-rw-r--r-- | lib/facter/uniqueid.rb | 2 | ||||
-rw-r--r-- | lib/facter/uptime.rb | 6 | ||||
-rw-r--r-- | lib/facter/util/ip.rb | 22 | ||||
-rw-r--r-- | lib/facter/util/manufacturer.rb | 74 | ||||
-rw-r--r-- | lib/facter/util/plist/generator.rb | 360 | ||||
-rw-r--r-- | lib/facter/util/plist/parser.rb | 325 | ||||
-rw-r--r-- | lib/facter/util/uptime.rb | 18 | ||||
-rw-r--r-- | tasks/rake/redlabpackage.rb | 18 | ||||
-rw-r--r-- | tasks/rake/reductive.rb | 12 |
28 files changed, 868 insertions, 873 deletions
@@ -1,4 +1,4 @@ -1.6.0: +1.5.x: Added EC2 facts Fixed #2032 - file.open hanging on /proc/uptime on some platform @@ -8,13 +8,13 @@ Fixed #1761 - changes to Solaris facts: operatingsystemrelease == kernel release or uname -r - kernelrelease == uname -r + kernelrelease == uname -r kernelversion == uname -v Added support for Oracle VM Server to operatingsystem and operatingsystemrelease - Added support for Oracle Enterprise Linux to operatingsystem + Added support for Oracle Enterprise Linux to operatingsystem and operatingsystemrelease Fixed #1927 - failing facts don't kill Facter @@ -47,19 +47,19 @@ Added ci namespace and Rake tasks - Fixed #1650 - OS X package creation script should be more selective + Fixed #1650 - OS X package creation script should be more selective about cleaning out prior versions Added Ubuntu to a variety of confines Fixed #1619 - Applying patch by seanmil, adding support for SLES. - - Fixed #1634 - Update virtual fact to differentiate OpenVZ + + Fixed #1634 - Update virtual fact to differentiate OpenVZ hardware nodes and virtual environments Fixed #1509 - Fixed version recognition for SLES. - Fixes #1582 - Fix MAC address reporting for Linux bonding + Fixes #1582 - Fix MAC address reporting for Linux bonding slave interfaces Fixed #1575 - CentOS fix for Facter SPEC file @@ -115,8 +115,8 @@ Fixes #1467 - macaddress not set on Ubuntu - Enabled a number of Windows facts - operating system, domain, ipaddress, macaddress, - kernel, ipconfig and others + Enabled a number of Windows facts - operating system, domain, ipaddress, macaddress, + kernel, ipconfig and others 1.5.0: Fixed Rakefile to include additional files including tests et al @@ -145,7 +145,7 @@ Add lsbmajdistrelease fact for CentOS and Red Hat - Updated Red Hat spec file for new version + Updated Red Hat spec file for new version The 'facter' executable now has an option (-p|--puppet) for loading the Puppet libraries, which gives it access to Puppet's facts. @@ -157,22 +157,22 @@ Significantly refactored Facter's internals, including creating tests for all internal classes. - A netmask fact has been added closing ticket #46. It only returns the - netmask of the primary interface (in the same behaviour as the ipaddress + A netmask fact has been added closing ticket #46. It only returns the + netmask of the primary interface (in the same behaviour as the ipaddress and macaddress facts). - Facts to return multiple interfaces on a host have also been updated. - If you have multiple interfaces on Linux, *BSD, or Solaris/SunOS you will - now get facts for each interface's IP address, MAC address and netmask. + Facts to return multiple interfaces on a host have also been updated. + If you have multiple interfaces on Linux, *BSD, or Solaris/SunOS you will + now get facts for each interface's IP address, MAC address and netmask. The facts will be structured like: ipaddress_int = 10.0.0.x macaddress_int = xx:xx:xx:xx netmask_int = 255.255.255.0 - Facter now identifies Ubuntu hosts and their releases using the + Facter now identifies Ubuntu hosts and their releases using the operatingsystem and operatingsystemrelease facts. - The Debian operatingsystemrelease fact now correctly returns the current + The Debian operatingsystemrelease fact now correctly returns the current Debian release. Fixed ticket #48 - ioperatingsystem and operatingsystemrelease for CentOS @@ -186,16 +186,16 @@ Fixed ticket #45 - Added netmask.rb closing ticket #46 + Added netmask.rb closing ticket #46 1.3.8: Fixed Rdoc::usage bug on CentOS 5 - closed Puppet #753 and Facter #40 - Added support to return multiple interfaces and their IP addresses and - MAC addressess as facts. Returns interface_interfacename and - macaddress_interfacename. Existing ipaddress and macaddress facts are + Added support to return multiple interfaces and their IP addresses and + MAC addressess as facts. Returns interface_interfacename and + macaddress_interfacename. Existing ipaddress and macaddress facts are unchanged and still returned. Currently Linux only. Closes #6. - + Added macaddress fact support for FreeBSD and OpenBSD - closes #37 Added hardwareisa support for *BSD platforms - closed #38 @@ -289,4 +289,4 @@ adding new fact resolution mechanisms at run-time. 1.0b1: - Initial release. + Initial release. @@ -2,7 +2,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), 'tasks') -begin +begin require 'rake/reductive' rescue LoadError $stderr.puts "You must have the Reductive build library in your RUBYLIB." @@ -12,16 +12,16 @@ end project = Rake::RedLabProject.new("facter") do |p| p.summary = "Facter collects Operating system facts." p.description = <<-EOF - Facter is a module for collecting simple facts about a host + Facter is a module for collecting simple facts about a host Operating system. EOF p.filelist = [ 'install.rb', '[A-Z]*', - 'bin/**/*', + 'bin/**/*', 'lib/facter.rb', - 'lib/**/*.rb', + 'lib/**/*.rb', 'test/**/*.rb', 'spec/**/*', 'conf/**/*', @@ -48,21 +48,19 @@ task :archive do end namespace :ci do + desc "Run the CI prep tasks" + task :prep do + require 'rubygems' + gem 'ci_reporter' + require 'ci/reporter/rake/rspec' + require 'ci/reporter/rake/test_unit' + ENV['CI_REPORTS'] = 'results' + end - desc "Run the CI prep tasks" - task :prep do - require 'rubygems' - gem 'ci_reporter' - require 'ci/reporter/rake/rspec' - require 'ci/reporter/rake/test_unit' - ENV['CI_REPORTS'] = 'results' - end - - desc "Run CI RSpec tests" - task :spec => [:prep, 'ci:setup:rspec'] do - sh "cd spec; rake all; exit 0" - end - + desc "Run CI RSpec tests" + task :spec => [:prep, 'ci:setup:rspec'] do + sh "cd spec; rake all; exit 0" + end end desc "Send patch information to the puppet-dev list" @@ -75,7 +73,7 @@ task :mail_patches do raise "Could not get branch from 'git status'" end branch = $1 - + unless branch =~ %r{^([^\/]+)/([^\/]+)/([^\/]+)$} raise "Branch name does not follow <type>/<parent>/<name> model; cannot autodetect parent branch" end diff --git a/autotest/discover.rb b/autotest/discover.rb index 7cf0916..030d07f 100644 --- a/autotest/discover.rb +++ b/autotest/discover.rb @@ -1,9 +1,9 @@ require 'autotest' Autotest.add_discovery do - "rspec" + "rspec" end Autotest.add_discovery do - "facter" + "facter" end diff --git a/autotest/facter_rspec.rb b/autotest/facter_rspec.rb index 0ec65b0..90e646d 100644 --- a/autotest/facter_rspec.rb +++ b/autotest/facter_rspec.rb @@ -16,25 +16,25 @@ Autotest.add_hook :initialize do |at| # force a complete re-run for all of these: - # main facter lib - at.add_mapping(%r!^lib/facter\.rb$!) { |filename, _| + # main facter lib + at.add_mapping(%r!^lib/facter\.rb$!) { |filename, _| at.files_matching %r!spec/(unit|integration)/.*\.rb! - } + } - # the spec_helper - at.add_mapping(%r!^spec/spec_helper\.rb$!) { |filename, _| + # the spec_helper + at.add_mapping(%r!^spec/spec_helper\.rb$!) { |filename, _| at.files_matching %r!spec/(unit|integration)/.*\.rb! - } + } # the facter spec libraries - at.add_mapping(%r!^spec/lib/spec.*!) { |filename, _| + at.add_mapping(%r!^spec/lib/spec.*!) { |filename, _| at.files_matching %r!spec/(unit|integration)/.*\.rb! - } + } # the monkey patches for rspec - at.add_mapping(%r!^spec/lib/monkey_patches/.*!) { |filename, _| + at.add_mapping(%r!^spec/lib/monkey_patches/.*!) { |filename, _| at.files_matching %r!spec/(unit|integration)/.*\.rb! - } + } end class Autotest::FacterRspec < Autotest::Rspec diff --git a/autotest/rspec.rb b/autotest/rspec.rb index ebafbfe..e395dfe 100644 --- a/autotest/rspec.rb +++ b/autotest/rspec.rb @@ -1,74 +1,74 @@ require 'autotest' Autotest.add_hook :initialize do |at| - at.clear_mappings - # watch out: Ruby bug (1.8.6): - # %r(/) != /\// - at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _| - filename - } - at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| - ["spec/#{m[1]}_spec.rb"] - } - at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) { - at.files_matching %r{^spec/.*_spec\.rb$} - } + at.clear_mappings + # watch out: Ruby bug (1.8.6): + # %r(/) != /\// + at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _| + filename + } + at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| + ["spec/#{m[1]}_spec.rb"] + } + at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) { + at.files_matching %r{^spec/.*_spec\.rb$} + } end class RspecCommandError < StandardError; end class Autotest::Rspec < Autotest - def initialize - super + def initialize + super - self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m - self.completed_re = /\Z/ # FIX: some sort of summary line at the end? - end + self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m + self.completed_re = /\Z/ # FIX: some sort of summary line at the end? + end - def consolidate_failures(failed) - filters = Hash.new { |h,k| h[k] = [] } - failed.each do |spec, failed_trace| - if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then - filters[f] << spec - break - end + def consolidate_failures(failed) + filters = Hash.new { |h,k| h[k] = [] } + failed.each do |spec, failed_trace| + if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then + filters[f] << spec + break + end + end + return filters end - return filters - end - def make_test_cmd(files_to_test) - return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}" - end - - def add_options_if_present - File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : "" - end + def make_test_cmd(files_to_test) + return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}" + end + + def add_options_if_present + File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : "" + end - # Finds the proper spec command to use. Precendence is set in the - # lazily-evaluated method spec_commands. Alias + Override that in - # ~/.autotest to provide a different spec command then the default - # paths provided. - def spec_command(separator=File::ALT_SEPARATOR) - unless defined? @spec_command then - @spec_command = spec_commands.find { |cmd| File.exists? cmd } + # Finds the proper spec command to use. Precendence is set in the + # lazily-evaluated method spec_commands. Alias + Override that in + # ~/.autotest to provide a different spec command then the default + # paths provided. + def spec_command(separator=File::ALT_SEPARATOR) + unless defined? @spec_command then + @spec_command = spec_commands.find { |cmd| File.exists? cmd } - raise RspecCommandError, "No spec command could be found!" unless @spec_command + raise RspecCommandError, "No spec command could be found!" unless @spec_command - @spec_command.gsub! File::SEPARATOR, separator if separator + @spec_command.gsub! File::SEPARATOR, separator if separator + end + @spec_command end - @spec_command - end - # Autotest will look for spec commands in the following - # locations, in this order: - # - # * bin/spec - # * default spec bin/loader installed in Rubygems - def spec_commands - [ - File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')), - File.join(Config::CONFIG['bindir'], 'spec') - ] - end + # Autotest will look for spec commands in the following + # locations, in this order: + # + # * bin/spec + # * default spec bin/loader installed in Rubygems + def spec_commands + [ + File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')), + File.join(Config::CONFIG['bindir'], 'spec') + ] + end end @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby # # = Synopsis # @@ -15,7 +15,7 @@ # about a system from within the shell or within Ruby. # # If no facts are specifically asked for, then all facts will be returned. -# +# # = Options # # debug:: @@ -63,34 +63,34 @@ $debug = 0 config = nil result = GetoptLong.new( - [ "--version", "-v", GetoptLong::NO_ARGUMENT ], - [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], - [ "--yaml", "-y", GetoptLong::NO_ARGUMENT ], - [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ], - [ "--puppet", "-p", GetoptLong::NO_ARGUMENT ] + [ "--version", "-v", GetoptLong::NO_ARGUMENT ], + [ "--help", "-h", GetoptLong::NO_ARGUMENT ], + [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "--yaml", "-y", GetoptLong::NO_ARGUMENT ], + [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ], + [ "--puppet", "-p", GetoptLong::NO_ARGUMENT ] ) options = { :yaml => false } -begin - result.each { |opt,arg| - case opt +begin + result.each { |opt,arg| + case opt when "--version" - puts "%s" % Facter.version - exit + puts "%s" % Facter.version + exit when "--puppet" - begin + begin require 'puppet' rescue LoadError => detail $stderr.puts "Could not load Puppet: %s" % detail end when "--yaml" - options[:yaml] = true + options[:yaml] = true when "--debug" - Facter.debugging(1) + Facter.debugging(1) when "--help" if $haveusage RDoc::usage && exit @@ -101,24 +101,24 @@ begin else $stderr.puts "Invalid option '#{opt}'" exit(12) - end - } + end + } rescue - exit(12) + exit(12) end names = [] unless config.nil? - File.open(config) { |file| - names = file.readlines.collect { |line| - line.chomp - } - } + File.open(config) { |file| + names = file.readlines.collect { |line| + line.chomp + } + } end ARGV.each { |item| - names.push item + names.push item } if names.empty? diff --git a/conf/osx/PackageInfo.plist b/conf/osx/PackageInfo.plist index 38b76d8..6668e2e 100644 --- a/conf/osx/PackageInfo.plist +++ b/conf/osx/PackageInfo.plist @@ -2,35 +2,35 @@ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> - <key>CFBundleIdentifier</key> - <string>com.reductivelabs.facter</string> - <key>CFBundleShortVersionString</key> - <string>{SHORTVERSION}</string> - <key>IFMajorVersion</key> - <integer>{MAJORVERSION}</integer> - <key>IFMinorVersion</key> - <integer>{MINORVERSION}</integer> - <key>IFPkgFlagAllowBackRev</key> - <false/> - <key>IFPkgFlagAuthorizationAction</key> - <string>RootAuthorization</string> - <key>IFPkgFlagDefaultLocation</key> - <string>/</string> - <key>IFPkgFlagFollowLinks</key> - <true/> - <key>IFPkgFlagInstallFat</key> - <false/> - <key>IFPkgFlagIsRequired</key> - <false/> - <key>IFPkgFlagOverwritePermissions</key> - <false/> - <key>IFPkgFlagRelocatable</key> - <false/> - <key>IFPkgFlagRestartAction</key> - <string>None</string> - <key>IFPkgFlagRootVolumeOnly</key> - <true/> - <key>IFPkgFlagUpdateInstalledLanguages</key> - <false/> + <key>CFBundleIdentifier</key> + <string>com.reductivelabs.facter</string> + <key>CFBundleShortVersionString</key> + <string>{SHORTVERSION}</string> + <key>IFMajorVersion</key> + <integer>{MAJORVERSION}</integer> + <key>IFMinorVersion</key> + <integer>{MINORVERSION}</integer> + <key>IFPkgFlagAllowBackRev</key> + <false/> + <key>IFPkgFlagAuthorizationAction</key> + <string>RootAuthorization</string> + <key>IFPkgFlagDefaultLocation</key> + <string>/</string> + <key>IFPkgFlagFollowLinks</key> + <true/> + <key>IFPkgFlagInstallFat</key> + <false/> + <key>IFPkgFlagIsRequired</key> + <false/> + <key>IFPkgFlagOverwritePermissions</key> + <false/> + <key>IFPkgFlagRelocatable</key> + <false/> + <key>IFPkgFlagRestartAction</key> + <string>None</string> + <key>IFPkgFlagRootVolumeOnly</key> + <true/> + <key>IFPkgFlagUpdateInstalledLanguages</key> + <false/> </dict> </plist> diff --git a/conf/osx/createpackage.sh b/conf/osx/createpackage.sh index 4e99c91..768380e 100755 --- a/conf/osx/createpackage.sh +++ b/conf/osx/createpackage.sh @@ -7,13 +7,13 @@ # Last Updated: 2008-07-31 # # Copyright 2008 Google Inc. -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,7 +30,7 @@ PREFLIGHT="preflight" function find_installer() { - # we walk up three directories to make this executable from the root, + # we walk up three directories to make this executable from the root, # root/conf or root/conf/osx if [ -f "./${INSTALLRB}" ]; then installer="$(pwd)/${INSTALLRB}" @@ -64,7 +64,7 @@ function prepare_package() { # to look at for package creation and substitue the version strings out. # Major/Minor versions can only be integers, so we have "1" and "50" for # facter version 1.5 - # Note too that for 10.5 compatibility this Info.plist *must* be set to + # Note too that for 10.5 compatibility this Info.plist *must* be set to # follow symlinks. VER1=$(echo ${facter_version} | awk -F "." '{print $1}') VER2=$(echo ${facter_version} | awk -F "." '{print $2}') @@ -75,12 +75,12 @@ function prepare_package() { sed -i '' "s/{SHORTVERSION}/${facter_version}/g" "${pkgtemp}/${PROTO_PLIST}" sed -i '' "s/{MAJORVERSION}/${major_version}/g" "${pkgtemp}/${PROTO_PLIST}" sed -i '' "s/{MINORVERSION}/${minor_version}/g" "${pkgtemp}/${PROTO_PLIST}" - + # We need to create a preflight script to remove traces of previous # facter installs due to limitations in Apple's pkg format. mkdir "${pkgtemp}/scripts" cp "${facter_root}/conf/osx/${PREFLIGHT}" "${pkgtemp}/scripts" - + # substitute in the sitelibdir specified above on the assumption that this # is where any previous facter install exists that should be cleaned out. sed -i '' "s|{SITELIBDIR}|${SITELIBDIR}|g" "${pkgtemp}/scripts/${PREFLIGHT}" @@ -124,44 +124,44 @@ function main() { fi find_installer - + if [ ! "${installer}" ]; then echo "Unable to find ${INSTALLRB}" cleanup_and_exit 1 fi find_facter_root - + if [ ! "${facter_root}" ]; then echo "Unable to find facter repository root." cleanup_and_exit 1 fi - + pkgroot=$(mktemp -d -t facterpkg) - + if [ ! "${pkgroot}" ]; then echo "Unable to create temporary package root." cleanup_and_exit 1 fi - + pkgtemp=$(mktemp -d -t factertmp) - + if [ ! "${pkgtemp}" ]; then echo "Unable to create temporary package root." cleanup_and_exit 1 fi - + install_facter get_facter_version - + if [ ! "${facter_version}" ]; then echo "Unable to retrieve facter version" cleanup_and_exit 1 fi - + prepare_package create_package - + cleanup_and_exit 0 } @@ -81,33 +81,33 @@ libs = glob(%w{lib/**/*.rb lib/**/*.py}) tests = glob(%w{tests/**/*.rb}) def do_bins(bins, target, strip = 's?bin/') - bins.each do |bf| - obf = bf.gsub(/#{strip}/, '') - install_binfile(bf, obf, target) - end + bins.each do |bf| + obf = bf.gsub(/#{strip}/, '') + install_binfile(bf, obf, target) + end end def do_libs(libs, strip = 'lib/') - libs.each do |lf| - olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, '')) - op = File.dirname(olf) - File.makedirs(op, true) - File.chmod(0755, op) - File.install(lf, olf, 0755, true) - end + libs.each do |lf| + olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, '')) + op = File.dirname(olf) + File.makedirs(op, true) + File.chmod(0755, op) + File.install(lf, olf, 0755, true) + end end def do_man(man, strip = 'man/') - man.each do |mf| - omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) - om = File.dirname(omf) - File.makedirs(om, true) - File.chmod(0644, om) - File.install(mf, omf, 0644, true) - gzip = %x{which gzip} - gzip.chomp! - %x{#{gzip} -f #{omf}} - end + man.each do |mf| + omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) + om = File.dirname(omf) + File.makedirs(om, true) + File.chmod(0644, om) + File.install(mf, omf, 0644, true) + gzip = %x{which gzip} + gzip.chomp! + %x{#{gzip} -f #{omf}} + end end # Verify that all of the prereqs are installed @@ -126,158 +126,158 @@ end # Prepare the file installation. # def prepare_installation - # Only try to do docs if we're sure they have rdoc - if $haverdoc - InstallOptions.rdoc = true - if RUBY_PLATFORM == "i386-mswin32" + # Only try to do docs if we're sure they have rdoc + if $haverdoc + InstallOptions.rdoc = true + if RUBY_PLATFORM == "i386-mswin32" + InstallOptions.ri = false + else + InstallOptions.ri = true + end + else + InstallOptions.rdoc = false InstallOptions.ri = false - else - InstallOptions.ri = true - end - else - InstallOptions.rdoc = false - InstallOptions.ri = false - end - - - if $haveman - InstallOptions.man = true - if RUBY_PLATFORM == "i386-mswin32" - InstallOptions.man = false - end - else - InstallOptions.man = false - end - - InstallOptions.tests = true - - ARGV.options do |opts| - opts.banner = "Usage: #{File.basename($0)} [options]" - opts.separator "" - opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc| - InstallOptions.rdoc = onrdoc - end - opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri| - InstallOptions.ri = onri end - opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman| - InstallOptions.man = onman - end - opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest| - InstallOptions.tests = ontest - end - opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir| - InstallOptions.destdir = destdir - end - opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir| - InstallOptions.bindir = bindir + + + if $haveman + InstallOptions.man = true + if RUBY_PLATFORM == "i386-mswin32" + InstallOptions.man = false + end + else + InstallOptions.man = false end - opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir| - InstallOptions.sbindir = sbindir + + InstallOptions.tests = true + + ARGV.options do |opts| + opts.banner = "Usage: #{File.basename($0)} [options]" + opts.separator "" + opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc| + InstallOptions.rdoc = onrdoc + end + opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri| + InstallOptions.ri = onri + end + opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman| + InstallOptions.man = onman + end + opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest| + InstallOptions.tests = ontest + end + opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir| + InstallOptions.destdir = destdir + end + opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir| + InstallOptions.bindir = bindir + end + opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir| + InstallOptions.sbindir = sbindir + end + opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir| + InstallOptions.sitelibdir = sitelibdir + end + opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir| + InstallOptions.mandir = mandir + end + opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick| + InstallOptions.rdoc = false + InstallOptions.ri = false + InstallOptions.tests = false + end + opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full| + InstallOptions.rdoc = true + InstallOptions.ri = true + InstallOptions.tests = true + end + opts.separator("") + opts.on_tail('--help', "Shows this help text.") do + $stderr.puts opts + exit + end + + opts.parse! end - opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir| - InstallOptions.sitelibdir = sitelibdir + + tmpdirs = [".", ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp"] + + version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".") + libdir = File.join(Config::CONFIG["libdir"], "ruby", version) + + # Mac OS X 10.5 declares bindir and sbindir as + # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin + # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin + # which is not generally where people expect executables to be installed + if RUBY_PLATFORM == "universal-darwin9.0" + Config::CONFIG['bindir'] = "/usr/bin" + Config::CONFIG['sbindir'] = "/usr/sbin" end - opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir| - InstallOptions.mandir = mandir + + if not InstallOptions.bindir.nil? + bindir = InstallOptions.bindir + else + bindir = Config::CONFIG['bindir'] end - opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick| - InstallOptions.rdoc = false - InstallOptions.ri = false - InstallOptions.tests = false + + if not InstallOptions.sbindir.nil? + sbindir = InstallOptions.sbindir + else + sbindir = Config::CONFIG['sbindir'] end - opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full| - InstallOptions.rdoc = true - InstallOptions.ri = true - InstallOptions.tests = true + + if not InstallOptions.sitelibdir.nil? + sitelibdir = InstallOptions.sitelibdir + else + sitelibdir = Config::CONFIG["sitelibdir"] + if sitelibdir.nil? + sitelibdir = $:.find { |x| x =~ /site_ruby/ } + if sitelibdir.nil? + sitelibdir = File.join(libdir, "site_ruby") + elsif sitelibdir !~ Regexp.quote(version) + sitelibdir = File.join(sitelibdir, version) + end + end end - opts.separator("") - opts.on_tail('--help', "Shows this help text.") do - $stderr.puts opts - exit + + if not InstallOptions.mandir.nil? + mandir = InstallOptions.mandir + else + mandir = Config::CONFIG['mandir'] end - opts.parse! - end - - tmpdirs = [".", ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp"] - - version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".") - libdir = File.join(Config::CONFIG["libdir"], "ruby", version) - - # Mac OS X 10.5 declares bindir and sbindir as - # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin - # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin - # which is not generally where people expect executables to be installed - if RUBY_PLATFORM == "universal-darwin9.0" - Config::CONFIG['bindir'] = "/usr/bin" - Config::CONFIG['sbindir'] = "/usr/sbin" - end - - if not InstallOptions.bindir.nil? - bindir = InstallOptions.bindir - else - bindir = Config::CONFIG['bindir'] - end - - if not InstallOptions.sbindir.nil? - sbindir = InstallOptions.sbindir - else - sbindir = Config::CONFIG['sbindir'] - end - - if not InstallOptions.sitelibdir.nil? - sitelibdir = InstallOptions.sitelibdir - else - sitelibdir = Config::CONFIG["sitelibdir"] - if sitelibdir.nil? - sitelibdir = $:.find { |x| x =~ /site_ruby/ } - if sitelibdir.nil? - sitelibdir = File.join(libdir, "site_ruby") - elsif sitelibdir !~ Regexp.quote(version) - sitelibdir = File.join(sitelibdir, version) - end + # To be deprecated once people move over to using --destdir option + if (destdir = ENV['DESTDIR']) + bindir = "#{destdir}#{bindir}" + sbindir = "#{destdir}#{sbindir}" + mandir = "#{destdir}#{mandir}" + sitelibdir = "#{destdir}#{sitelibdir}" + + FileUtils.makedirs(bindir) + FileUtils.makedirs(sbindir) + FileUtils.makedirs(mandir) + FileUtils.makedirs(sitelibdir) + # This is the new way forward + elsif (destdir = InstallOptions.destdir) + bindir = "#{destdir}#{bindir}" + sbindir = "#{destdir}#{sbindir}" + mandir = "#{destdir}#{mandir}" + sitelibdir = "#{destdir}#{sitelibdir}" + + FileUtils.makedirs(bindir) + FileUtils.makedirs(sbindir) + FileUtils.makedirs(mandir) + FileUtils.makedirs(sitelibdir) end - end - - if not InstallOptions.mandir.nil? - mandir = InstallOptions.mandir - else - mandir = Config::CONFIG['mandir'] - end - - # To be deprecated once people move over to using --destdir option - if (destdir = ENV['DESTDIR']) - bindir = "#{destdir}#{bindir}" - sbindir = "#{destdir}#{sbindir}" - mandir = "#{destdir}#{mandir}" - sitelibdir = "#{destdir}#{sitelibdir}" - - FileUtils.makedirs(bindir) - FileUtils.makedirs(sbindir) - FileUtils.makedirs(mandir) - FileUtils.makedirs(sitelibdir) - # This is the new way forward - elsif (destdir = InstallOptions.destdir) - bindir = "#{destdir}#{bindir}" - sbindir = "#{destdir}#{sbindir}" - mandir = "#{destdir}#{mandir}" - sitelibdir = "#{destdir}#{sitelibdir}" - - FileUtils.makedirs(bindir) - FileUtils.makedirs(sbindir) - FileUtils.makedirs(mandir) - FileUtils.makedirs(sitelibdir) - end - - tmpdirs << bindir - - InstallOptions.tmp_dirs = tmpdirs.compact - InstallOptions.site_dir = sitelibdir - InstallOptions.bin_dir = bindir - InstallOptions.sbin_dir = sbindir - InstallOptions.lib_dir = libdir - InstallOptions.man_dir = mandir + + tmpdirs << bindir + + InstallOptions.tmp_dirs = tmpdirs.compact + InstallOptions.site_dir = sitelibdir + InstallOptions.bin_dir = bindir + InstallOptions.sbin_dir = sbindir + InstallOptions.lib_dir = libdir + InstallOptions.man_dir = mandir end ## @@ -323,10 +323,10 @@ def build_man(bins) # Create binary man pages bins.each do |bin| - b = bin.gsub( "bin/", "") - %x{#{bin} --help > ./#{b}.rst} - %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8} - File.unlink("./#{b}.rst") + b = bin.gsub( "bin/", "") + %x{#{bin} --help > ./#{b}.rst} + %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8} + File.unlink("./#{b}.rst") end rescue SystemCallError $stderr.puts "Couldn't build man pages: " + $! @@ -335,24 +335,24 @@ def build_man(bins) end def run_tests(test_list) - begin - require 'test/unit/ui/console/testrunner' - $:.unshift "lib" - test_list.each do |test| - next if File.directory?(test) - require test - end - - tests = [] - ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) } - tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) } - tests.delete_if { |o| o == Test::Unit::TestCase } - - tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) } - $:.shift - rescue LoadError - puts "Missing testrunner library; skipping tests" - end + begin + require 'test/unit/ui/console/testrunner' + $:.unshift "lib" + test_list.each do |test| + next if File.directory?(test) + require test + end + + tests = [] + ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) } + tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) } + tests.delete_if { |o| o == Test::Unit::TestCase } + + tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) } + $:.shift + rescue LoadError + puts "Missing testrunner library; skipping tests" + end end ## @@ -361,57 +361,57 @@ end # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under # windows, we add an '.rb' extension and let file associations do their stuff. def install_binfile(from, op_file, target) - tmp_dir = nil - InstallOptions.tmp_dirs.each do |t| - if File.directory?(t) and File.writable?(t) - tmp_dir = t - break + tmp_dir = nil + InstallOptions.tmp_dirs.each do |t| + if File.directory?(t) and File.writable?(t) + tmp_dir = t + break + end end - end - - fail "Cannot find a temporary directory" unless tmp_dir - tmp_file = File.join(tmp_dir, '_tmp') - ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - - File.open(from) do |ip| - File.open(tmp_file, "w") do |op| - ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - op.puts "#!#{ruby}" - contents = ip.readlines - if contents[0] =~ /^#!/ - contents.shift - end - op.write contents.join() + + fail "Cannot find a temporary directory" unless tmp_dir + tmp_file = File.join(tmp_dir, '_tmp') + ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + + File.open(from) do |ip| + File.open(tmp_file, "w") do |op| + ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + op.puts "#!#{ruby}" + contents = ip.readlines + if contents[0] =~ /^#!/ + contents.shift + end + op.write contents.join() + end end - end - if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/io - installed_wrapper = false + if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/io + installed_wrapper = false - if File.exists?("#{from}.bat") - FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) - installed_wrapper = true - end + if File.exists?("#{from}.bat") + FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) + installed_wrapper = true + end - if File.exists?("#{from}.cmd") - FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true) - installed_wrapper = true - end + if File.exists?("#{from}.cmd") + FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true) + installed_wrapper = true + end - if not installed_wrapper - tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') - cwn = File.join(Config::CONFIG['bindir'], op_file) - cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } ) + if not installed_wrapper + tmp_file2 = File.join(tmp_dir, '_tmp_wrapper') + cwn = File.join(Config::CONFIG['bindir'], op_file) + cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } ) - File.open(tmp_file2, "wb") { |cw| cw.puts cwv } - FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) + File.open(tmp_file2, "wb") { |cw| cw.puts cwv } + FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true) - File.unlink(tmp_file2) - installed_wrapper = true + File.unlink(tmp_file2) + installed_wrapper = true + end end - end - FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) - File.unlink(tmp_file) + FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) + File.unlink(tmp_file) end CMD_WRAPPER = <<-EOS diff --git a/lib/facter.rb b/lib/facter.rb index c73f714..b395372 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -28,13 +28,13 @@ module Facter include Enumerable FACTERVERSION = '1.5.4' - # = Facter + # = Facter # Functions as a hash of 'facts' you might care about about your # system, such as mac address, IP address, Video card, etc. # returns them dynamically - # == Synopsis - # + # == Synopsis + # # Generally, treat <tt>Facter</tt> as a hash: # == Example # require 'facter' @@ -49,7 +49,7 @@ module Facter RESET = "[0m" @@debug = 0 - # module methods + # module methods def self.collection unless defined?(@collection) and @collection @@ -147,9 +147,9 @@ module Facter Facter.reset end - # Set debugging on or off. - def self.debugging(bit) - if bit + # Set debugging on or off. + def self.debugging(bit) + if bit case bit when TrueClass; @@debug = 1 when FalseClass; @@debug = 0 @@ -168,10 +168,10 @@ module Facter else @@debug = 0 end - else - @@debug = 0 - end - end + else + @@debug = 0 + end + end # Remove them all. def self.reset diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb index d372607..d68aa3f 100644 --- a/lib/facter/kernel.rb +++ b/lib/facter/kernel.rb @@ -2,8 +2,8 @@ Facter.add(:kernel) do setcode do require 'rbconfig' case Config::CONFIG['host_os'] - when /mswin/i; 'windows' - else Facter::Util::Resolution.exec("uname -s") + when /mswin/i; 'windows' + else Facter::Util::Resolution.exec("uname -s") end end end diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index fc07437..f54d75f 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -13,11 +13,11 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA ## -{ "LSBRelease" => %r{^LSB Version:\t(.*)$}, - "LSBDistId" => %r{^Distributor ID:\t(.*)$}, - "LSBDistRelease" => %r{^Release:\t(.*)$}, - "LSBDistDescription" => %r{^Description:\t(.*)$}, - "LSBDistCodeName" => %r{^Codename:\t(.*)$} +{ "LSBRelease" => %r{^LSB Version:\t(.*)$}, + "LSBDistId" => %r{^Distributor ID:\t(.*)$}, + "LSBDistRelease" => %r{^Release:\t(.*)$}, + "LSBDistDescription" => %r{^Description:\t(.*)$}, + "LSBDistCodeName" => %r{^Codename:\t(.*)$} }.each do |fact, pattern| Facter.add(fact) do confine :kernel => :linux diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index d2b13b9..e1ac7be 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb @@ -6,14 +6,14 @@ require 'facter/util/manufacturer' query = { - '[Ss]ystem [Ii]nformation' => [ - { 'Manufacturer:' => 'manufacturer' }, - { 'Product(?: Name)?:' => 'productname' }, - { 'Serial Number:' => 'serialnumber' } - ], - '(Chassis Information|system enclosure or chassis)' => [ - { '(?:Chassis )?Type:' => 'type' } - ] + '[Ss]ystem [Ii]nformation' => [ + { 'Manufacturer:' => 'manufacturer' }, + { 'Product(?: Name)?:' => 'productname' }, + { 'Serial Number:' => 'serialnumber' } + ], + '(Chassis Information|system enclosure or chassis)' => [ + { '(?:Chassis )?Type:' => 'type' } + ] } Facter::Manufacturer.dmi_find_system_info(query) diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index 01858d8..6880731 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -7,10 +7,11 @@ # require 'facter/util/memory' -{:MemorySize => "MemTotal", - :MemoryFree => "MemFree", - :SwapSize => "SwapTotal", - :SwapFree => "SwapFree"}.each do |fact, name| +{ :MemorySize => "MemTotal", + :MemoryFree => "MemFree", + :SwapSize => "SwapTotal", + :SwapFree => "SwapFree" +}.each do |fact, name| Facter.add(fact) do confine :kernel => :linux setcode do diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb index 309ef63..6ccef23 100644 --- a/lib/facter/netmask.rb +++ b/lib/facter/netmask.rb @@ -9,9 +9,9 @@ require 'facter/util/netmask' Facter.add("netmask") do - confine :kernel => [ :sunos, :linux ] - setcode do - Facter::NetMask.get_netmask - end + confine :kernel => [ :sunos, :linux ] + setcode do + Facter::NetMask.get_netmask + end end diff --git a/lib/facter/network.rb b/lib/facter/network.rb index 513282a..df53ce4 100644 --- a/lib/facter/network.rb +++ b/lib/facter/network.rb @@ -1,10 +1,9 @@ require 'facter/util/ip' Facter::Util::IP.get_interfaces.each do |interface| - - Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do - setcode do - Facter::Util::IP.get_network_value(interface) - end + Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do + setcode do + Facter::Util::IP.get_network_value(interface) end + end end diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index 72f25f5..52f889b 100644 --- a/lib/facter/operatingsystem.rb +++ b/lib/facter/operatingsystem.rb @@ -20,8 +20,8 @@ Facter.add(:operatingsystem) do "Mandriva" elsif FileTest.exists?("/etc/mandrake-release") "Mandrake" - elsif FileTest.exists?("/etc/arch-release") - "Archlinux" + elsif FileTest.exists?("/etc/arch-release") + "Archlinux" elsif FileTest.exists?("/etc/enterprise-release") "OEL" elsif FileTest.exists?("/etc/ovs-release") @@ -37,8 +37,8 @@ Facter.add(:operatingsystem) do txt = File.read("/etc/SuSE-release") if txt =~ /^SUSE LINUX Enterprise Server/i "SLES" - elsif txt =~ /^openSUSE/i - "OpenSuSE" + elsif txt =~ /^openSUSE/i + "OpenSuSE" else "SuSE" end diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb index 1ea2e75..25a226d 100644 --- a/lib/facter/operatingsystemrelease.rb +++ b/lib/facter/operatingsystemrelease.rb @@ -87,8 +87,8 @@ Facter.add(:operatingsystemrelease) do releasemajor = $1 if releasefile =~ /^PATCHLEVEL\s*=\s*(\d+)/ releaseminor = $1 - elsif releasefile =~ /^VERSION\s=.*.(\d+)/ - releaseminor = $1 + elsif releasefile =~ /^VERSION\s=.*.(\d+)/ + releaseminor = $1 else releaseminor = "0" end diff --git a/lib/facter/timezone.rb b/lib/facter/timezone.rb index e01c5e0..744e06a 100644 --- a/lib/facter/timezone.rb +++ b/lib/facter/timezone.rb @@ -1,5 +1,5 @@ Facter.add("timezone") do - setcode do + setcode do Time.new.zone end end diff --git a/lib/facter/uniqueid.rb b/lib/facter/uniqueid.rb index b199865..1af4ae5 100644 --- a/lib/facter/uniqueid.rb +++ b/lib/facter/uniqueid.rb @@ -1,4 +1,4 @@ Facter.add(:uniqueid) do - setcode 'hostid', '/bin/sh' + setcode 'hostid', '/bin/sh' confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX} end diff --git a/lib/facter/uptime.rb b/lib/facter/uptime.rb index 808bcec..3a3bc86 100644 --- a/lib/facter/uptime.rb +++ b/lib/facter/uptime.rb @@ -12,9 +12,9 @@ if FileTest.exists?("/proc/uptime") %w{days hours seconds}.each do |label| Facter.add("uptime_" + label) do - setcode do - Facter::Util::Uptime.get_uptime_period(uptime, label) - end + setcode do + Facter::Util::Uptime.get_uptime_period(uptime, label) + end end end end diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb index 4d4d936..a57bf08 100644 --- a/lib/facter/util/ip.rb +++ b/lib/facter/util/ip.rb @@ -5,20 +5,20 @@ module Facter::Util::IP # a given platform or set of platforms. REGEX_MAP = { :linux => { - :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, - :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, + :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ }, - :bsd => { - :aliases => [:openbsd, :netbsd, :freebsd, :darwin], - :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :macaddress => /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/, - :netmask => /netmask\s+0x(\w{8})/ + :bsd => { + :aliases => [:openbsd, :netbsd, :freebsd, :darwin], + :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :macaddress => /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/, + :netmask => /netmask\s+0x(\w{8})/ }, :sunos => { - :addr => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, - :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, - :netmask => /netmask\s+(\w{8})/ + :addr => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, + :netmask => /netmask\s+(\w{8})/ } } diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb index ff12e7e..954637e 100644 --- a/lib/facter/util/manufacturer.rb +++ b/lib/facter/util/manufacturer.rb @@ -2,45 +2,45 @@ # Support methods for manufacturer specific facts module Facter::Manufacturer - def self.dmi_find_system_info(name) - splitstr="Handle" - case Facter.value(:kernel) - when 'Linux' - return nil unless FileTest.exists?("/usr/sbin/dmidecode") - - output=%x{/usr/sbin/dmidecode 2>/dev/null} - when 'OpenBSD', 'FreeBSD' - return nil unless FileTest.exists?("/usr/local/sbin/dmidecode") - - output=%x{/usr/local/sbin/dmidecode 2>/dev/null} - when 'NetBSD' - return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode") + def self.dmi_find_system_info(name) + splitstr="Handle" + case Facter.value(:kernel) + when 'Linux' + return nil unless FileTest.exists?("/usr/sbin/dmidecode") - output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null} - when 'SunOS' - return nil unless FileTest.exists?("/usr/sbin/smbios") - splitstr="ID SIZE TYPE" - output=%x{/usr/sbin/smbios 2>/dev/null} + output=%x{/usr/sbin/dmidecode 2>/dev/null} + when 'OpenBSD', 'FreeBSD' + return nil unless FileTest.exists?("/usr/local/sbin/dmidecode") - else - return - end - name.each_pair do |key,v| - v.each do |v2| - v2.each_pair do |value,facterkey| - output.split(splitstr).each do |line| - if line =~ /#{key}/ and ( line =~ /#{value} 0x\d+ \(([-\w].*)\)\n*./ or line =~ /#{value} ([-\w].*)\n*./ ) - result = $1 - Facter.add(facterkey) do - confine :kernel => [ :linux, :freebsd, :netbsd, :openbsd, :sunos ] - setcode do - result - end - end - end - end - end - end + output=%x{/usr/local/sbin/dmidecode 2>/dev/null} + when 'NetBSD' + return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode") + + output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null} + when 'SunOS' + return nil unless FileTest.exists?("/usr/sbin/smbios") + splitstr="ID SIZE TYPE" + output=%x{/usr/sbin/smbios 2>/dev/null} + + else + return + end + name.each_pair do |key,v| + v.each do |v2| + v2.each_pair do |value,facterkey| + output.split(splitstr).each do |line| + if line =~ /#{key}/ and ( line =~ /#{value} 0x\d+ \(([-\w].*)\)\n*./ or line =~ /#{value} ([-\w].*)\n*./ ) + result = $1 + Facter.add(facterkey) do + confine :kernel => [ :linux, :freebsd, :netbsd, :openbsd, :sunos ] + setcode do + result + end + end + end + end + end + end end end end diff --git a/lib/facter/util/plist/generator.rb b/lib/facter/util/plist/generator.rb index 9e44b80..6c0796b 100644 --- a/lib/facter/util/plist/generator.rb +++ b/lib/facter/util/plist/generator.rb @@ -7,220 +7,222 @@ #++ # See Plist::Emit. module Plist - # === Create a plist - # You can dump an object to a plist in one of two ways: - # - # * <tt>Plist::Emit.dump(obj)</tt> - # * <tt>obj.to_plist</tt> - # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+. - # - # The following Ruby classes are converted into native plist types: - # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false - # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively). - # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element. - # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element. - # - # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below. - module Emit - # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+. - def to_plist(envelope = true) - return Plist::Emit.dump(self, envelope) - end - - # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+. - def save_plist(filename) - Plist::Emit.save_plist(self, filename) - end - - # The following Ruby classes are converted into native plist types: - # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time + # === Create a plist + # You can dump an object to a plist in one of two ways: # - # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes. + # * <tt>Plist::Emit.dump(obj)</tt> + # * <tt>obj.to_plist</tt> + # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+. # - # +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+. + # The following Ruby classes are converted into native plist types: + # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false + # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively). + # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element. + # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element. # - # The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment. - def self.dump(obj, envelope = true) - output = plist_node(obj) + # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below. + module Emit + # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+. + def to_plist(envelope = true) + return Plist::Emit.dump(self, envelope) + end - output = wrap(output) if envelope + # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+. + def save_plist(filename) + Plist::Emit.save_plist(self, filename) + end - return output - end + # The following Ruby classes are converted into native plist types: + # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time + # + # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes. + # + # +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+. + # + # The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment. + def self.dump(obj, envelope = true) + output = plist_node(obj) - # Writes the serialized object's plist to the specified filename. - def self.save_plist(obj, filename) - File.open(filename, 'wb') do |f| - f.write(obj.to_plist) - end - end + output = wrap(output) if envelope - private - def self.plist_node(element) - output = '' - - if element.respond_to? :to_plist_node - output << element.to_plist_node - else - case element - when Array - if element.empty? - output << "<array/>\n" - else - output << tag('array') { - element.collect {|e| plist_node(e)} - } - end - when Hash - if element.empty? - output << "<dict/>\n" - else - inner_tags = [] - - element.keys.sort.each do |k| - v = element[k] - inner_tags << tag('key', CGI::escapeHTML(k.to_s)) - inner_tags << plist_node(v) + return output + end + + # Writes the serialized object's plist to the specified filename. + def self.save_plist(obj, filename) + File.open(filename, 'wb') do |f| + f.write(obj.to_plist) + end + end + + private + def self.plist_node(element) + output = '' + + if element.respond_to? :to_plist_node + output << element.to_plist_node + else + case element + when Array + if element.empty? + output << "<array/>\n" + else + output << tag('array') { + element.collect {|e| plist_node(e)} + } + end + when Hash + if element.empty? + output << "<dict/>\n" + else + inner_tags = [] + + element.keys.sort.each do |k| + v = element[k] + inner_tags << tag('key', CGI::escapeHTML(k.to_s)) + inner_tags << plist_node(v) + end + + output << tag('dict') { + inner_tags + } + end + when true, false + output << "<#{element}/>\n" + when Time + output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ')) + when Date # also catches DateTime + output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ')) + when String, Symbol, Fixnum, Bignum, Integer, Float + output << tag(element_type(element), CGI::escapeHTML(element.to_s)) + when IO, StringIO + element.rewind + contents = element.read + # note that apple plists are wrapped at a different length then + # what ruby's base64 wraps by default. + # I used #encode64 instead of #b64encode (which allows a length arg) + # because b64encode is b0rked and ignores the length arg. + data = "\n" + Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } + output << tag('data', data) + else + output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' ) + data = "\n" + Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } + output << tag('data', data ) + end end - output << tag('dict') { - inner_tags - } - end - when true, false - output << "<#{element}/>\n" - when Time - output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ')) - when Date # also catches DateTime - output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ')) - when String, Symbol, Fixnum, Bignum, Integer, Float - output << tag(element_type(element), CGI::escapeHTML(element.to_s)) - when IO, StringIO - element.rewind - contents = element.read - # note that apple plists are wrapped at a different length then - # what ruby's base64 wraps by default. - # I used #encode64 instead of #b64encode (which allows a length arg) - # because b64encode is b0rked and ignores the length arg. - data = "\n" - Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } - output << tag('data', data) - else - output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' ) - data = "\n" - Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" } - output << tag('data', data ) + return output end - end - return output - end + def self.comment(content) + return "<!-- #{content} -->\n" + end - def self.comment(content) - return "<!-- #{content} -->\n" - end + def self.tag(type, contents = '', &block) + out = nil + + if block_given? + out = IndentedString.new + out << "<#{type}>" + out.raise_indent - def self.tag(type, contents = '', &block) - out = nil + out << block.call - if block_given? - out = IndentedString.new - out << "<#{type}>" - out.raise_indent + out.lower_indent + out << "</#{type}>" + else + out = "<#{type}>#{contents.to_s}</#{type}>\n" + end - out << block.call + return out.to_s + end - out.lower_indent - out << "</#{type}>" - else - out = "<#{type}>#{contents.to_s}</#{type}>\n" - end + def self.wrap(contents) + output = '' - return out.to_s - end + output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n" + output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n" + output << '<plist version="1.0">' + "\n" + + output << contents + + output << '</plist>' + "\n" - def self.wrap(contents) - output = '' + return output + end - output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n" - output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n" - output << '<plist version="1.0">' + "\n" + def self.element_type(item) + return case item + when String, Symbol; 'string' + when Fixnum, Bignum, Integer; 'integer' + when Float; 'real' + else + raise "Don't know about this data type... something must be wrong!" + end + end - output << contents + private - output << '</plist>' + "\n" + class IndentedString #:nodoc: + attr_accessor :indent_string - return output - end + @@indent_level = 0 - def self.element_type(item) - return case item - when String, Symbol; 'string' - when Fixnum, Bignum, Integer; 'integer' - when Float; 'real' - else - raise "Don't know about this data type... something must be wrong!" - end - end - private - class IndentedString #:nodoc: - attr_accessor :indent_string - - @@indent_level = 0 - - def initialize(str = "\t") - @indent_string = str - @contents = '' - end - - def to_s - return @contents - end - - def raise_indent - @@indent_level += 1 - end - - def lower_indent - @@indent_level -= 1 if @@indent_level > 0 - end - - def <<(val) - if val.is_a? Array - val.each do |f| - self << f - end - else - # if it's already indented, don't bother indenting further - unless val =~ /\A#{@indent_string}/ - indent = @indent_string * @@indent_level - - @contents << val.gsub(/^/, indent) - else - @contents << val - end - - # it already has a newline, don't add another - @contents << "\n" unless val =~ /\n$/ + def initialize(str = "\t") + @indent_string = str + @contents = '' + end + + def to_s + return @contents + end + + def raise_indent + @@indent_level += 1 + end + + def lower_indent + @@indent_level -= 1 if @@indent_level > 0 + end + + def <<(val) + if val.is_a? Array + val.each do |f| + self << f + end + else + # if it's already indented, don't bother indenting further + unless val =~ /\A#{@indent_string}/ + indent = @indent_string * @@indent_level + + @contents << val.gsub(/^/, indent) + else + @contents << val + end + + # it already has a newline, don't add another + @contents << "\n" unless val =~ /\n$/ + end + end end - end end - end end # we need to add this so sorting hash keys works properly class Symbol #:nodoc: - def <=> (other) - self.to_s <=> other.to_s - end + def <=> (other) + self.to_s <=> other.to_s + end end class Array #:nodoc: - include Plist::Emit + include Plist::Emit end class Hash #:nodoc: - include Plist::Emit + include Plist::Emit end # $Id: generator.rb 1781 2006-10-16 01:01:35Z luke $ diff --git a/lib/facter/util/plist/parser.rb b/lib/facter/util/plist/parser.rb index 24f791f..48e1034 100644 --- a/lib/facter/util/plist/parser.rb +++ b/lib/facter/util/plist/parser.rb @@ -21,207 +21,206 @@ module Plist # If you encounter such an error, or if you have a Date element which # can't be parsed into a Time object, please send your plist file to # plist@hexane.org so that I can implement the proper support. - def Plist::parse_xml( filename_or_xml ) - listener = Listener.new - #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener) - parser = StreamParser.new(filename_or_xml, listener) - parser.parse - listener.result - end - - class Listener - #include REXML::StreamListener - - attr_accessor :result, :open - - def initialize - @result = nil - @open = Array.new + def Plist::parse_xml( filename_or_xml ) + listener = Listener.new + #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener) + parser = StreamParser.new(filename_or_xml, listener) + parser.parse + listener.result end + class Listener + #include REXML::StreamListener - def tag_start(name, attributes) - @open.push PTag::mappings[name].new - end + attr_accessor :result, :open - def text( contents ) - @open.last.text = contents if @open.last - end + def initialize + @result = nil + @open = Array.new + end - def tag_end(name) - last = @open.pop - if @open.empty? - @result = last.to_ruby - else - @open.last.children.push last - end - end - end - class StreamParser - def initialize( filename_or_xml, listener ) - @filename_or_xml = filename_or_xml - @listener = listener - end + def tag_start(name, attributes) + @open.push PTag::mappings[name].new + end - TEXT = /([^<]+)/ - XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um - DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um - COMMENT_START = /\A<!--/u - COMMENT_END = /.*?-->/um - - - def parse - plist_tags = PTag::mappings.keys.join('|') - start_tag = /<(#{plist_tags})([^>]*)>/i - end_tag = /<\/(#{plist_tags})[^>]*>/i - - require 'strscan' - - contents = ( - if (File.exists? @filename_or_xml) - File.open(@filename_or_xml) {|f| f.read} - else - @filename_or_xml - end - ) - - @scanner = StringScanner.new( contents ) - until @scanner.eos? - if @scanner.scan(COMMENT_START) - @scanner.scan(COMMENT_END) - elsif @scanner.scan(XMLDECL_PATTERN) - elsif @scanner.scan(DOCTYPE_PATTERN) - elsif @scanner.scan(start_tag) - @listener.tag_start(@scanner[1], nil) - if (@scanner[2] =~ /\/$/) - @listener.tag_end(@scanner[1]) - end - elsif @scanner.scan(TEXT) - @listener.text(@scanner[1]) - elsif @scanner.scan(end_tag) - @listener.tag_end(@scanner[1]) - else - raise "Unimplemented element" - end - end - end - end + def text( contents ) + @open.last.text = contents if @open.last + end - class PTag - @@mappings = { } - def PTag::mappings - @@mappings + def tag_end(name) + last = @open.pop + if @open.empty? + @result = last.to_ruby + else + @open.last.children.push last + end + end end - def PTag::inherited( sub_class ) - key = sub_class.to_s.downcase - key.gsub!(/^plist::/, '' ) - key.gsub!(/^p/, '') unless key == "plist" + class StreamParser + def initialize( filename_or_xml, listener ) + @filename_or_xml = filename_or_xml + @listener = listener + end - @@mappings[key] = sub_class + TEXT = /([^<]+)/ + XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um + DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um + COMMENT_START = /\A<!--/u + COMMENT_END = /.*?-->/um + + def parse + plist_tags = PTag::mappings.keys.join('|') + start_tag = /<(#{plist_tags})([^>]*)>/i + end_tag = /<\/(#{plist_tags})[^>]*>/i + + require 'strscan' + + contents = ( + if (File.exists? @filename_or_xml) + File.open(@filename_or_xml) {|f| f.read} + else + @filename_or_xml + end + ) + + @scanner = StringScanner.new( contents ) + until @scanner.eos? + if @scanner.scan(COMMENT_START) + @scanner.scan(COMMENT_END) + elsif @scanner.scan(XMLDECL_PATTERN) + elsif @scanner.scan(DOCTYPE_PATTERN) + elsif @scanner.scan(start_tag) + @listener.tag_start(@scanner[1], nil) + if (@scanner[2] =~ /\/$/) + @listener.tag_end(@scanner[1]) + end + elsif @scanner.scan(TEXT) + @listener.text(@scanner[1]) + elsif @scanner.scan(end_tag) + @listener.tag_end(@scanner[1]) + else + raise "Unimplemented element" + end + end + end end - attr_accessor :text, :children - def initialize - @children = Array.new - end + class PTag + @@mappings = { } + def PTag::mappings + @@mappings + end - def to_ruby - raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}" + def PTag::inherited( sub_class ) + key = sub_class.to_s.downcase + key.gsub!(/^plist::/, '' ) + key.gsub!(/^p/, '') unless key == "plist" + + @@mappings[key] = sub_class + end + + attr_accessor :text, :children + def initialize + @children = Array.new + end + + def to_ruby + raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}" + end end - end - class PList < PTag - def to_ruby - children.first.to_ruby if children.first + class PList < PTag + def to_ruby + children.first.to_ruby if children.first + end end - end - class PDict < PTag - def to_ruby - dict = Hash.new - key = nil + class PDict < PTag + def to_ruby + dict = Hash.new + key = nil - children.each do |c| - if key.nil? - key = c.to_ruby - else - dict[key] = c.to_ruby - key = nil - end - end + children.each do |c| + if key.nil? + key = c.to_ruby + else + dict[key] = c.to_ruby + key = nil + end + end - dict + dict + end end - end - class PKey < PTag - def to_ruby - CGI::unescapeHTML(text || '') + class PKey < PTag + def to_ruby + CGI::unescapeHTML(text || '') + end end - end - class PString < PTag - def to_ruby - CGI::unescapeHTML(text || '') + class PString < PTag + def to_ruby + CGI::unescapeHTML(text || '') + end end - end - class PArray < PTag - def to_ruby - children.collect do |c| - c.to_ruby - end + class PArray < PTag + def to_ruby + children.collect do |c| + c.to_ruby + end + end end - end - class PInteger < PTag - def to_ruby - text.to_i + class PInteger < PTag + def to_ruby + text.to_i + end end - end - class PTrue < PTag - def to_ruby - true + class PTrue < PTag + def to_ruby + true + end end - end - class PFalse < PTag - def to_ruby - false + class PFalse < PTag + def to_ruby + false + end end - end - class PReal < PTag - def to_ruby - text.to_f + class PReal < PTag + def to_ruby + text.to_f + end end - end - require 'date' - class PDate < PTag - def to_ruby - DateTime.parse(text) + require 'date' + class PDate < PTag + def to_ruby + DateTime.parse(text) + end end - end - - require 'base64' - class PData < PTag - def to_ruby - data = Base64.decode64(text.gsub(/\s+/, '')) - - begin - return Marshal.load(data) - rescue Exception => e - io = StringIO.new - io.write data - io.rewind - return io - end + + require 'base64' + class PData < PTag + def to_ruby + data = Base64.decode64(text.gsub(/\s+/, '')) + + begin + return Marshal.load(data) + rescue Exception => e + io = StringIO.new + io.write data + io.rewind + return io + end + end end - end end # $Id: parser.rb 1781 2006-10-16 01:01:35Z luke $ diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb index 76c4464..c1e339b 100644 --- a/lib/facter/util/uptime.rb +++ b/lib/facter/util/uptime.rb @@ -1,16 +1,15 @@ # A module to gather uptime facts # module Facter::Util::Uptime - def self.get_uptime_simple time = Facter::Util::Resolution.exec('uptime') - if time =~ /up\s*(\d+\s\w+)/ - $1 - elsif time =~ /up\s*(\d+:\d+)/ - $1 + " hours" - else - "unknown" - end + if time =~ /up\s*(\d+\s\w+)/ + $1 + elsif time =~ /up\s*(\d+:\d+)/ + $1 + " hours" + else + "unknown" + end end def self.get_uptime @@ -21,7 +20,6 @@ module Facter::Util::Uptime end def self.get_uptime_period(seconds, label) - case label when 'days' value = seconds / 86400 @@ -30,7 +28,5 @@ module Facter::Util::Uptime when 'seconds' seconds end - end - end diff --git a/tasks/rake/redlabpackage.rb b/tasks/rake/redlabpackage.rb index 2de8005..1df9c41 100644 --- a/tasks/rake/redlabpackage.rb +++ b/tasks/rake/redlabpackage.rb @@ -17,13 +17,13 @@ require 'rake/tasklib' # of date. # # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</b>] -# Create a gzipped tar package (if <em>need_tar</em> is true). +# Create a gzipped tar package (if <em>need_tar</em> is true). # # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</b>] -# Create a gzipped tar package (if <em>need_tar_gz</em> is true). +# Create a gzipped tar package (if <em>need_tar_gz</em> is true). # # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</b>] -# Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true). +# Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true). # # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</b>] # Create a zip package archive (if <em>need_zip</em> is true). @@ -38,8 +38,8 @@ require 'rake/tasklib' class Rake::RedLabPackageTask < Rake::TaskLib # The different directory types we can manage. DIRTYPES = { - :bindir => :bins, - :sbindir => :sbins, + :bindir => :bins, + :sbindir => :sbins, :sitelibdir => :rubylibs } @@ -103,7 +103,7 @@ class Rake::RedLabPackageTask < Rake::TaskLib # The URL for the package. attr_accessor :url - + # The source for the package. attr_accessor :source @@ -139,7 +139,7 @@ class Rake::RedLabPackageTask < Rake::TaskLib end end - # Create a Package Task with the given name and version. + # Create a Package Task with the given name and version. def initialize(name=nil, version=nil) # Theoretically, one could eventually add directory types here. @dirtypes = DIRTYPES.dup @@ -226,7 +226,7 @@ class Rake::RedLabPackageTask < Rake::TaskLib safe_ln(sourcefile, destfile) end end - + # If we've set the destdir, then list it as a prereq. if destdir file destfile => destdir @@ -236,7 +236,7 @@ class Rake::RedLabPackageTask < Rake::TaskLib # And create a task for each one task tname => reqs - + # And then mark our task as a prereq tasks << tname end diff --git a/tasks/rake/reductive.rb b/tasks/rake/reductive.rb index 2fbd2b4..ea7072b 100644 --- a/tasks/rake/reductive.rb +++ b/tasks/rake/reductive.rb @@ -269,13 +269,13 @@ class Rake::RedLabProject < Rake::TaskLib :package, :publish ] do - - announce + + announce announce "**************************************************************" announce "* Release #{@version} Complete." announce "* Packages ready to upload." announce "**************************************************************" - announce + announce end end @@ -283,12 +283,12 @@ class Rake::RedLabProject < Rake::TaskLib def mktaskprerelease # Validate that everything is ready to go for a release. task :prerelease do - announce + announce announce "**************************************************************" announce "* Making Release #{@version}" announce "* (current version #{self.currentversion})" announce "**************************************************************" - announce + announce # Is a release number supplied? unless ENV['REL'] @@ -467,7 +467,7 @@ class Rake::RedLabProject < Rake::TaskLib end desc "List all ruby files" - task :rubyfiles do + task :rubyfiles do puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ } puts Dir['**/bin/*'].reject { |fn| fn =~ /svn|(~$)|(\.rb$)/ } end |