summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:08 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:08 -0700
commiteefccf252527dc5b69af5959b0b0e2ddb5c91b74 (patch)
treea37e13c9cd4aab7e8671004cf4f83000b52c96a8 /lib/puppet
parent184132e07fc1461555cb4da842df15f32842a843 (diff)
downloadpuppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.gz
puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.xz
puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.zip
Code smell: English names for special globals rather than line-noise
* Replaced 36 occurances of [$][?] with $CHILD_STATUS 3 Examples: The code: print "%s finished with exit code %s\n" % [host, $?.exitstatus] becomes: print "%s finished with exit code %s\n" % [host, $CHILD_STATUS.exitstatus] The code: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] becomes: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $CHILD_STATUS.exitstatus] The code: unless $? == 0 becomes: unless $CHILD_STATUS == 0 * Replaced 3 occurances of [$][$] with $PID 3 Examples: The code: Process.kill(:HUP, $$) if restart_requested? becomes: Process.kill(:HUP, $PID) if restart_requested? The code: if pid == $$ becomes: if pid == $PID The code: host[:name] = "!invalid.hostname.$$$" becomes: host[:name] = "!invalid.hostname.$PID$" * Replaced 7 occurances of [$]& with $MATCH 3 Examples: The code: work.slice!(0, $&.length) becomes: work.slice!(0, $MATCH.length) The code: if $& becomes: if $MATCH The code: if $& becomes: if $MATCH * Replaced 28 occurances of [$]:(?!:) with $LOAD_PATH 3 Examples: The code: sitelibdir = $:.find { |x| x =~ /site_ruby/ } becomes: sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ } The code: $:.unshift "lib" becomes: $LOAD_PATH.unshift "lib" The code: $:.shift becomes: $LOAD_PATH.shift * Replaced 3 occurances of [$]! with $ERROR_INFO 3 Examples: The code: $LOG.fatal("Problem reading #{filepath}: #{$!}") becomes: $LOG.fatal("Problem reading #{filepath}: #{$ERROR_INFO}") The code: $stderr.puts "Couldn't build man pages: " + $! becomes: $stderr.puts "Couldn't build man pages: " + $ERROR_INFO The code: $stderr.puts $!.message becomes: $stderr.puts $ERROR_INFO.message * Replaced 3 occurances of ^(.*)[$]" with \1$LOADED_FEATURES 3 Examples: The code: unless $".index 'racc/parser.rb' becomes: unless $LOADED_FEATURES.index 'racc/parser.rb' The code: $".push 'racc/parser.rb' becomes: $LOADED_FEATURES.push 'racc/parser.rb' The code: $".should be_include("tmp/myfile.rb") becomes: $LOADED_FEATURES.should be_include("tmp/myfile.rb")
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/application.rb2
-rw-r--r--lib/puppet/application/describe.rb2
-rw-r--r--lib/puppet/application/kick.rb8
-rw-r--r--lib/puppet/defaults.rb6
-rw-r--r--lib/puppet/external/nagios/parser.rb10
-rw-r--r--lib/puppet/external/pson/pure/generator.rb4
-rw-r--r--lib/puppet/external/pson/pure/parser.rb2
-rw-r--r--lib/puppet/feature/rails.rb4
-rwxr-xr-xlib/puppet/provider/package/darwinport.rb2
-rwxr-xr-xlib/puppet/provider/service/base.rb2
-rwxr-xr-xlib/puppet/provider/service/debian.rb2
-rwxr-xr-xlib/puppet/provider/service/smf.rb2
-rw-r--r--lib/puppet/provider/zone/solaris.rb2
-rw-r--r--lib/puppet/rails.rb2
-rw-r--r--lib/puppet/util.rb4
-rw-r--r--lib/puppet/util/autoload.rb2
-rw-r--r--lib/puppet/util/command_line.rb2
-rw-r--r--lib/puppet/util/rdoc/generators/puppet_generator.rb2
-rw-r--r--lib/puppet/util/reference.rb14
-rw-r--r--lib/puppet/util/suidmanager.rb4
20 files changed, 39 insertions, 39 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 3409d3615..7e7a2a962 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -169,7 +169,7 @@ class Application
def controlled_run(&block)
return unless clear?
result = block.call
- Process.kill(:HUP, $$) if restart_requested?
+ Process.kill(:HUP, $PID) if restart_requested?
result
end
diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb
index f9c5260ec..b9c05c0e5 100644
--- a/lib/puppet/application/describe.rb
+++ b/lib/puppet/application/describe.rb
@@ -19,7 +19,7 @@ class Formatter
while work.length > textLen
if work =~ patt
res << $1
- work.slice!(0, $&.length)
+ work.slice!(0, $MATCH.length)
else
res << work.slice!(0, textLen)
end
diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb
index 8c168b3ba..e6cbed6c8 100644
--- a/lib/puppet/application/kick.rb
+++ b/lib/puppet/application/kick.rb
@@ -77,12 +77,12 @@ class Puppet::Application::Kick < Puppet::Application
# Remove our host from the list of children, so the parallelization
# continues working.
@children.delete(pid)
- if $?.exitstatus != 0
+ if $CHILD_STATUS.exitstatus != 0
failures << host
end
- print "%s finished with exit code %s\n" % [host, $?.exitstatus]
+ print "%s finished with exit code %s\n" % [host, $CHILD_STATUS.exitstatus]
else
- $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus]
+ $stderr.puts "Could not find host for PID %s with status %s" % [pid, $CHILD_STATUS.exitstatus]
end
rescue Errno::ECHILD
# There are no children left, so just exit unless there are still
@@ -104,7 +104,7 @@ class Puppet::Application::Kick < Puppet::Application
def run_for_host(host)
if options[:ping]
out = %x{ping -c 1 #{host}}
- unless $? == 0
+ unless $CHILD_STATUS == 0
$stderr.print "Could not contact %s\n" % host
next
end
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 9637a63e0..64badedb0 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -82,11 +82,11 @@ module Puppet
is in Ruby's search path",
:call_on_define => true, # Call our hook with the default value, so we always get the libdir set.
:hook => proc do |value|
- if defined?(@oldlibdir) and $:.include?(@oldlibdir)
- $:.delete(@oldlibdir)
+ if defined?(@oldlibdir) and $LOAD_PATH.include?(@oldlibdir)
+ $LOAD_PATH.delete(@oldlibdir)
end
@oldlibdir = value
- $: << value
+ $LOAD_PATH << value
end
},
:ignoreimport => [false, "A parameter that can be used in commit
diff --git a/lib/puppet/external/nagios/parser.rb b/lib/puppet/external/nagios/parser.rb
index deea9f3bc..4a1f4c98d 100644
--- a/lib/puppet/external/nagios/parser.rb
+++ b/lib/puppet/external/nagios/parser.rb
@@ -7,8 +7,8 @@
# parser.rb: generated by racc (runtime embedded)
#
###### racc/parser.rb begin
-unless $".index 'racc/parser.rb'
-$".push 'racc/parser.rb'
+unless $LOADED_FEATURES.index 'racc/parser.rb'
+$LOADED_FEATURES.push 'racc/parser.rb'
self.class.module_eval <<'..end racc/parser.rb modeval..id5256434e8a', 'racc/parser.rb', 1
#
@@ -482,7 +482,7 @@ end
# The lexer. Very simple.
def token
@src.sub!(/\A\n/,'')
- if $&
+ if $MATCH
@line += 1
return [ :RETURN, "\n" ]
end
@@ -495,12 +495,12 @@ def token
# remove comments from this line
@src.sub!(/\A[ \t]*;.*\n/,"\n")
- if $&
+ if $MATCH
return [:INLINECOMMENT, ""]
end
@src.sub!(/\A#.*\n/,"\n")
- if $&
+ if $MATCH
return [:COMMENT, ""]
end
diff --git a/lib/puppet/external/pson/pure/generator.rb b/lib/puppet/external/pson/pure/generator.rb
index 6656ed1b2..42981b9dc 100644
--- a/lib/puppet/external/pson/pure/generator.rb
+++ b/lib/puppet/external/pson/pure/generator.rb
@@ -43,7 +43,7 @@ module PSON
string = string.dup
string << '' # XXX workaround: avoid buffer sharing
string.force_encoding(Encoding::ASCII_8BIT)
- string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
+ string.gsub!(/["\\\x0-\x1f]/) { MAP[$MATCH] }
string.gsub!(/(
(?:
[\xc2-\xdf][\x80-\xbf] |
@@ -63,7 +63,7 @@ module PSON
end
else
def utf8_to_pson(string) # :nodoc:
- string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
+ string = string.gsub(/["\\\x0-\x1f]/) { MAP[$MATCH] }
string.gsub!(/(
(?:
[\xc2-\xdf][\x80-\xbf] |
diff --git a/lib/puppet/external/pson/pure/parser.rb b/lib/puppet/external/pson/pure/parser.rb
index ef14d4009..ef05637e4 100644
--- a/lib/puppet/external/pson/pure/parser.rb
+++ b/lib/puppet/external/pson/pure/parser.rb
@@ -132,7 +132,7 @@ module PSON
if scan(STRING)
return '' if self[1].empty?
string = self[1].gsub(%r{(?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff])}n) do |c|
- if u = UNESCAPE_MAP[$&[1]]
+ if u = UNESCAPE_MAP[$MATCH[1]]
u
else # \uXXXX
bytes = ''
diff --git a/lib/puppet/feature/rails.rb b/lib/puppet/feature/rails.rb
index a29007273..f1997bd6b 100644
--- a/lib/puppet/feature/rails.rb
+++ b/lib/puppet/feature/rails.rb
@@ -14,9 +14,9 @@ Puppet.features.add(:rails) do
count = 0
Dir.entries("/usr/share/rails").each do |dir|
libdir = File.join("/usr/share/rails", dir, "lib")
- if FileTest.exists?(libdir) and ! $:.include?(libdir)
+ if FileTest.exists?(libdir) and ! $LOAD_PATH.include?(libdir)
count += 1
- $: << libdir
+ $LOAD_PATH << libdir
end
end
diff --git a/lib/puppet/provider/package/darwinport.rb b/lib/puppet/provider/package/darwinport.rb
index 7829438c5..5cced62d5 100755
--- a/lib/puppet/provider/package/darwinport.rb
+++ b/lib/puppet/provider/package/darwinport.rb
@@ -67,7 +67,7 @@ Puppet::Type.type(:package).provide :darwinport, :parent => Puppet::Provider::Pa
def latest
info = port :search, "^#{@resource[:name]}$"
- if $? != 0 or info =~ /^Error/
+ if $CHILD_STATUS != 0 or info =~ /^Error/
return nil
end
diff --git a/lib/puppet/provider/service/base.rb b/lib/puppet/provider/service/base.rb
index aa11f26fc..2e9ac778a 100755
--- a/lib/puppet/provider/service/base.rb
+++ b/lib/puppet/provider/service/base.rb
@@ -64,7 +64,7 @@ Puppet::Type.type(:service).provide :base do
ucommand(:status, false)
# Expicitly calling exitstatus to facilitate testing
- if $?.exitstatus == 0
+ if $CHILD_STATUS.exitstatus == 0
return :running
else
return :stopped
diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb
index 34e2cf8b1..1f95d66f7 100755
--- a/lib/puppet/provider/service/debian.rb
+++ b/lib/puppet/provider/service/debian.rb
@@ -34,7 +34,7 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do
# 104 is the exit status when you query start an enabled service.
# 106 is the exit status when the policy layer supplies a fallback action
# See x-man-page://invoke-rc.d
- if [104, 106].include?($?.exitstatus)
+ if [104, 106].include?($CHILD_STATUS.exitstatus)
return :true
else
return :false
diff --git a/lib/puppet/provider/service/smf.rb b/lib/puppet/provider/service/smf.rb
index 685889386..72f34ef37 100755
--- a/lib/puppet/provider/service/smf.rb
+++ b/lib/puppet/provider/service/smf.rb
@@ -22,7 +22,7 @@ Puppet::Type.type(:service).provide :smf, :parent => :base do
begin
if resource[:manifest]
[command(:svcs), "-l", @resource[:name]]
- if $?.exitstatus == 1
+ if $CHILD_STATUS.exitstatus == 1
Puppet.notice "Importing %s for %s" % [ @resource[:manifest], @resource[:name] ]
svccfg :import, resource[:manifest]
end
diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb
index 1aaa70d47..4d7e7473d 100644
--- a/lib/puppet/provider/zone/solaris.rb
+++ b/lib/puppet/provider/zone/solaris.rb
@@ -150,7 +150,7 @@ Puppet::Type.type(:zone).provide(:solaris) do
pipe.puts str
end
- unless $? == 0
+ unless $CHILD_STATUS == 0
raise ArgumentError, "Failed to apply configuration"
end
end
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 714dda80c..be252e444 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -97,7 +97,7 @@ module Puppet::Rails
# Migrate to the latest db schema.
def self.migrate
dbdir = nil
- $:.each { |d|
+ $LOAD_PATH.each { |d|
tmp = File.join(d, "puppet/rails/database")
if FileTest.directory?(tmp)
dbdir = tmp
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 386100270..1f974921e 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -215,7 +215,7 @@ module Util
end
if failonfail
- unless $? == 0
+ unless $CHILD_STATUS == 0
raise ExecutionFailure, output
end
end
@@ -380,7 +380,7 @@ module Util
def memory
unless defined?(@pmap)
pmap = %x{which pmap 2>/dev/null}.chomp
- if $? != 0 or pmap =~ /^no/
+ if $CHILD_STATUS != 0 or pmap =~ /^no/
@pmap = nil
else
@pmap = pmap
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index 27a361396..f0be0ece2 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -143,6 +143,6 @@ class Puppet::Util::Autoload
end
def search_directories(env=nil)
- [module_directories(env), Puppet[:libdir].split(File::PATH_SEPARATOR), $:].flatten
+ [module_directories(env), Puppet[:libdir].split(File::PATH_SEPARATOR), $LOAD_PATH].flatten
end
end
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 9ccc94a23..fa1b08b70 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -33,7 +33,7 @@ module Puppet
end
def available_subcommands
- absolute_appdir = $:.collect { |x| File.join(x,'puppet','application') }.detect{ |x| File.directory?(x) }
+ absolute_appdir = $LOAD_PATH.collect { |x| File.join(x,'puppet','application') }.detect{ |x| File.directory?(x) }
Dir[File.join(absolute_appdir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
end
diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb
index c2c27c8eb..c32a401bd 100644
--- a/lib/puppet/util/rdoc/generators/puppet_generator.rb
+++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb
@@ -177,7 +177,7 @@ module Generators
File.makedirs(NODE_DIR)
File.makedirs(PLUGIN_DIR)
rescue
- $stderr.puts $!.message
+ $stderr.puts $ERROR_INFO.message
exit 1
end
end
diff --git a/lib/puppet/util/reference.rb b/lib/puppet/util/reference.rb
index f34e54b8c..74d75bb3f 100644
--- a/lib/puppet/util/reference.rb
+++ b/lib/puppet/util/reference.rb
@@ -41,10 +41,10 @@ class Puppet::Util::Reference
f.puts text
end
rst2latex = %x{which rst2latex}
- if $? != 0 or rst2latex =~ /no /
+ if $CHILD_STATUS != 0 or rst2latex =~ /no /
rst2latex = %x{which rst2latex.py}
end
- if $? != 0 or rst2latex =~ /no /
+ if $CHILD_STATUS != 0 or rst2latex =~ /no /
raise "Could not find rst2latex"
end
rst2latex.chomp!
@@ -53,7 +53,7 @@ class Puppet::Util::Reference
# If we get here without an error, /tmp/puppetdoc.tex isn't a tricky cracker's symlink
end
output = %x{#{cmd}}
- unless $? == 0
+ unless $CHILD_STATUS == 0
$stderr.puts "rst2latex failed"
$stderr.puts output
exit(1)
@@ -75,16 +75,16 @@ class Puppet::Util::Reference
f.puts text
end
pandoc = %x{which pandoc}
- if $? != 0 or pandoc =~ /no /
+ if $CHILD_STATUS != 0 or pandoc =~ /no /
pandoc = %x{which pandoc}
end
- if $? != 0 or pandoc =~ /no /
+ if $CHILD_STATUS != 0 or pandoc =~ /no /
raise "Could not find pandoc"
end
pandoc.chomp!
cmd = %{#{pandoc} -s -r rst -w markdown #{dir}/#{name}.rst -o #{dir}/#{name}.mdwn}
output = %x{#{cmd}}
- unless $? == 0
+ unless $CHILD_STATUS == 0
$stderr.puts "Pandoc failed to create #{name} reference."
$stderr.puts output
exit(1)
@@ -201,7 +201,7 @@ class Puppet::Util::Reference
puts "Writing %s reference to trac as %s" % [@name, @page]
cmd = %{sudo trac-admin /opt/rl/trac/puppet wiki import %s /tmp/puppetdoc.txt} % self.page
output = %x{#{cmd}}
- unless $? == 0
+ unless $CHILD_STATUS == 0
$stderr.puts "trac-admin failed"
$stderr.puts output
exit(1)
diff --git a/lib/puppet/util/suidmanager.rb b/lib/puppet/util/suidmanager.rb
index b8e7d534c..404f78890 100644
--- a/lib/puppet/util/suidmanager.rb
+++ b/lib/puppet/util/suidmanager.rb
@@ -90,7 +90,7 @@ module Puppet::Util::SUIDManager
def run_and_capture(command, new_uid=nil, new_gid=nil)
output = Puppet::Util.execute(command, :failonfail => false, :uid => new_uid, :gid => new_gid)
- [output, $?.dup]
+ [output, $CHILD_STATUS.dup]
end
module_function :run_and_capture
@@ -98,7 +98,7 @@ module Puppet::Util::SUIDManager
status = nil
asuser(new_uid, new_gid) do
Kernel.system(command)
- status = $?.dup
+ status = $CHILD_STATUS.dup
end
status
end