summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-07-12 02:53:08 +0000
committerLuke Kanies <luke@madstop.com>2005-07-12 02:53:08 +0000
commit1f2c866e7fa08c748d4bf75a6997330182d91cf1 (patch)
tree03334c14b3e0d0a77f5de33ec769fa973d44dc89 /lib
parente19ca977aa201297a3c06eca15e434298321454b (diff)
downloadpuppet-1f2c866e7fa08c748d4bf75a6997330182d91cf1.tar.gz
puppet-1f2c866e7fa08c748d4bf75a6997330182d91cf1.tar.xz
puppet-1f2c866e7fa08c748d4bf75a6997330182d91cf1.zip
doing some refactoring
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@369 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet.rb8
-rw-r--r--lib/puppet/event.rb36
-rw-r--r--lib/puppet/log.rb16
-rw-r--r--lib/puppet/storage.rb10
4 files changed, 35 insertions, 35 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index 00ec0b1c5..6a49338f3 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -5,7 +5,7 @@
require 'singleton'
require 'puppet/log'
-# XXX see the bottom of the file for further inclusions
+# see the bottom of the file for further inclusions
#------------------------------------------------------------
# the top-level module
@@ -18,14 +18,12 @@ module Puppet
# the hash that determines how our system behaves
@@config = Hash.new(false)
- # handle the different message levels
+ # define helper messages for each of the message levels
Puppet::Log.levels.each { |level|
define_method(level,proc { |args|
Puppet::Log.create(level,args)
})
module_function level
- # # default to enabling all notice levels except debug
- # @@config[level] = true unless level == :notice
}
# I keep wanting to use Puppet.error
@@ -96,5 +94,5 @@ module Puppet
self[:statefile] = File.join(self[:puppetroot],"log/state")
end
-require 'puppet/storage'
require 'puppet/type'
+require 'puppet/storage'
diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb
index ad87bb0d3..91046d9af 100644
--- a/lib/puppet/event.rb
+++ b/lib/puppet/event.rb
@@ -11,9 +11,11 @@ module Puppet
# subscriptions getting triggered, and then they get cleared
# eventually, these will be passed on to some central event system
class Event
+ include Puppet
# subscriptions are permanent associations determining how different
# objects react to an event
class Subscription
+ include Puppet
attr_accessor :source, :event, :target, :method
def initialize(hash)
@@ -24,7 +26,7 @@ module Puppet
# this is probably wicked-slow
self.send(method.to_s + "=",value)
}
- Puppet.debug "New Subscription: '%s' => '%s'" %
+ debug "New Subscription: '%s' => '%s'" %
[@source,@event]
end
@@ -38,22 +40,22 @@ module Puppet
# to the "old" object rather than "new"
# but we're pretty far from that being a problem
if transaction.triggercount(self) > 0
- Puppet.debug "%s has already run" % self
+ debug "%s has already run" % self
else
- Puppet.debug "'%s' matched '%s'; triggering '%s' on '%s'" %
+ debug "'%s' matched '%s'; triggering '%s' on '%s'" %
[@source,@event,@method,@target]
begin
if @target.respond_to?(@method)
@target.send(@method)
else
- Puppet.debug "'%s' of type '%s' does not respond to '%s'" %
+ debug "'%s' of type '%s' does not respond to '%s'" %
[@target,@target.class,@method.inspect]
end
rescue => detail
# um, what the heck do i do when an object fails to refresh?
# shouldn't that result in the transaction rolling back?
# XXX yeah, it should
- Puppet.err "'%s' failed to %s: '%s'" %
+ err "'%s' failed to %s: '%s'" %
[@target,@method,detail]
raise
#raise "We need to roll '%s' transaction back" %
@@ -70,17 +72,17 @@ module Puppet
@@subscriptions = []
- def Event.process
- Puppet.debug "Processing events"
+ def self.process
+ debug "Processing events"
@@events.each { |event|
@@subscriptions.find_all { |sub|
- #Puppet.debug "Sub source: '%s'; event object: '%s'" %
+ #debug "Sub source: '%s'; event object: '%s'" %
# [sub.source.inspect,event.object.inspect]
sub.source == event.object and
(sub.event == event.event or
sub.event == :ALL_EVENTS)
}.each { |sub|
- Puppet.debug "Found subscription to %s" % event
+ debug "Found subscription to %s" % event
sub.trigger(event.transaction)
}
}
@@ -88,7 +90,7 @@ module Puppet
@@events.clear
end
- def Event.subscribe(hash)
+ def self.subscribe(hash)
if hash[:event] == '*'
hash[:event] = :ALL_EVENTS
end
@@ -107,7 +109,7 @@ module Puppet
@object = args[:object]
@transaction = args[:transaction]
- Puppet.info "%s: %s" %
+ info "%s: %s" %
[@object,@event]
# initially, just stuff all instances into a central bucket
@@ -134,7 +136,7 @@ class Puppet::NotUsed
# access to the actual hash, which is silly
def action
if not defined? @actions
- Puppet.debug "defining action hash"
+ debug "defining action hash"
@actions = Hash.new
end
@actions
@@ -148,9 +150,9 @@ class Puppet::NotUsed
# event handling should probably be taking place in a central process,
# but....
def event(event,obj)
- Puppet.debug "#{self} got event #{event} from #{obj}"
+ debug "#{self} got event #{event} from #{obj}"
if @actions.key?(event)
- Puppet.debug "calling it"
+ debug "calling it"
@actions[event].call(self,obj,event)
else
p @actions
@@ -174,7 +176,7 @@ class Puppet::NotUsed
@notify[event] = Array.new
end
unless @notify[event].include?(obj)
- Puppet.debug "pushing event '%s' for object '%s'" % [event,obj]
+ debug "pushing event '%s' for object '%s'" % [event,obj]
@notify[event].push(obj)
end
# }
@@ -193,9 +195,9 @@ class Puppet::NotUsed
if (@notify.include?(event) and (! @notify[event].empty?) )
@notify[event].each { |obj| subscribers.push(obj) }
end
- Puppet.debug "triggering #{event}"
+ debug "triggering #{event}"
subscribers.each { |obj|
- Puppet.debug "calling #{event} on #{obj}"
+ debug "calling #{event} on #{obj}"
obj.event(event,self)
}
end
diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb
index 52d30a0e4..1a906452b 100644
--- a/lib/puppet/log.rb
+++ b/lib/puppet/log.rb
@@ -1,13 +1,5 @@
# $Id$
-PINK=""
-GREEN=""
-YELLOW=""
-SLATE=""
-ORANGE=""
-BLUE=""
-RESET=""
-
require 'syslog'
module Puppet
@@ -16,6 +8,14 @@ module Puppet
# modeled after syslog messages
# each level of message prints in a different color
class Log
+ PINK=""
+ GREEN=""
+ YELLOW=""
+ SLATE=""
+ ORANGE=""
+ BLUE=""
+ RESET=""
+
@@messages = Array.new
@@levels = [:debug,:info,:notice,:warning,:err,:alert,:emerg,:crit]
diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb
index eb639e32e..d8f1c3f65 100644
--- a/lib/puppet/storage.rb
+++ b/lib/puppet/storage.rb
@@ -9,12 +9,12 @@ module Puppet
self.class.load
end
- def Storage.clear
+ def self.clear
@@state = nil
Storage.init
end
- def Storage.init
+ def self.init
Puppet.debug "Initializing Storage"
@@state = Hash.new { |hash,key|
hash[key] = Hash.new(nil)
@@ -24,7 +24,7 @@ module Puppet
self.init
- def Storage.load
+ def self.load
if Puppet[:statefile].nil?
raise "Somehow the statefile is nil"
end
@@ -51,7 +51,7 @@ module Puppet
Puppet.debug "Loaded state is %s" % @@state.inspect
end
- def Storage.state(myclass)
+ def self.state(myclass)
unless myclass.is_a? Class
myclass = myclass.class
end
@@ -59,7 +59,7 @@ module Puppet
return result
end
- def Storage.store
+ def self.store
unless FileTest.directory?(File.dirname(Puppet[:statefile]))
begin
Puppet.recmkdir(Puppet[:statefile])