diff options
Diffstat (limited to 'lib/blink.rb')
-rw-r--r-- | lib/blink.rb | 174 |
1 files changed, 11 insertions, 163 deletions
diff --git a/lib/blink.rb b/lib/blink.rb index 274e37550..17d3a8d6c 100644 --- a/lib/blink.rb +++ b/lib/blink.rb @@ -3,12 +3,6 @@ # $Id$ require 'singleton' -#require 'blink/component' -#require 'blink/interface' -#require 'blink/selector' -#require 'blink/type/service' -#require 'blink/type/file' -#require 'blink/type/symlink' # XXX see the bottom of the file for further inclusions @@ -31,11 +25,18 @@ module Blink # the hash that determines how our system behaves @@config = Hash.new(false) + @@config[:blinkroot] = "/var/blink" + @@config[:logdir] = "/var/blink/log" + @@config[:logfile] = "/var/blink/log/blink.log" + @@config[:statefile] = "/var/blink/log/state" - msglevels = [:debug,:verbose,:notice,:warning,:error] + + loglevels = [:debug,:verbose,:notice,:warning,:error] # handle the different message levels - msglevels.each { |level| + # XXX this should be redone to treat log-levels like radio buttons + # pick one, and it and all above it will be logged + loglevels.each { |level| define_method(level,proc { |args| Blink.message(level,args) }) @@ -69,47 +70,6 @@ module Blink puts msg end - # DISABLED - - # we've collected all data; now operate on it -# def Blink.run -# ops = Blink::Objects.genops() -# ops.find_all { |op| -# op.auto?() -# }.each { |op| -# Blink::Message.new( -# :level => :debug, -# :source => "Blink", -# :message => "Running op %s" % op -# ) -# op.check -# }.find_all { |op| -# puts "dirty? #{op}" -# op.dirty? -# }.collect { |op| -# puts "%s is dirty; %s instead of %s" % [op, op.state, op.should] -# op.fix -# }.each { |event| # this might need to support lists someday... -# #list.each { |event| -# puts event -# event.trigger -# #} -# } -# end -# -# def Blink.walk -# root = Blink::Objects.root -# root.check -# if root.dirty? -# Blink::Message.new( -# :message => "someone's dirty", -# :level => :notice, -# :source => root -# ) -# root.fix -# end -# end - # configuration parameter access and stuff def Blink.[](param) return @@config[param] @@ -120,120 +80,8 @@ module Blink @@config[param] = value end - # a class for storing state - # not currently used - class Storage - include Singleton - @@config = "/var/tmp/blinkstate" - @@state = Hash.new - @@splitchar = " " - - def initialize - self.load - end - - def Storage.load - puts "loading state" - return unless File.exists?(@@config) - File.open(@@config) { |file| - file.gets { |line| - myclass, key, value = line.split(@@splitchar) - - unless defined? @@state[myclass] - @@state[myclass] = Hash.new - end - - @@state[myclass][key] = value - } - } - end - - def Storage.state(myclass) - unless defined? @@state[myclass] - @@state[myclass] = Hash.new - end - return @@state[myclass] - end - - def Storage.store - File.open(@@config, File::CREAT|File::WRONLY, 0644) { |file| - @@state.each { |key, value| - file.puts([self.class,key,value].join(@@splitchar)) - } - } - end - end - - #------------------------------------------------------------ - # provide feedback of various types to the user - # modeled after syslog messages - # each level of message prints in a different color - class Message - @@messages = Array.new - @@levels = [ :debug, :verbose, :notice, :warning, :error ] - @@colors = { - :debug => SLATE, - :verbose => ORANGE, - :notice => PINK, - :warning => GREEN, - :error => YELLOW - } - - attr_reader :level, :message - attr_writer :level, :message - - def initialize(args) - unless args.include?(:level) && args.include?(:message) && - args.include?(:source) - raise "Blink::Message called incorrectly" - end - - if args[:level].class == String - @level = args[:level].intern - elsif args[:level].class == Symbol - @level = args[:level] - else - raise "Level is not a string or symbol: #{args[:level].class}" - end - @message = args[:message] - @source = args[:source] - @time = Time.now - # this should include the host name, and probly lots of other - # stuff, at some point - unless @@levels.include?(level) - raise "Invalid message level #{level}" - end - - @@messages.push(self) - Blink.newmessage(self) - end - - def to_s - # this probably won't stay, but until this leaves the console, - # i'm going to use coloring... - #return "#{@time} #{@source} (#{@level}): #{@message}" - #return @@colors[@level] + "%s %s (%s): %s" % [ - # @time, @source, @level, @message - #] + RESET - return @@colors[@level] + "%s (%s): %s" % [ - @source, @level, @message - ] + RESET - end - end - #------------------------------------------------------------ - - #------------------------------------------------------------ - class Modification - attr_accessor :object, :type, :from, :to - - def initialize(object) - @object = object - @type = object.class - @from = object.is? - @to = object.should? - end - end - #------------------------------------------------------------ end +require 'blink/storage' +require 'blink/message' require 'blink/type' |