summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-04-21 19:26:03 +0000
committerLuke Kanies <luke@madstop.com>2005-04-21 19:26:03 +0000
commit565554f47dccca357560ba96336b8bd4e3d2afe1 (patch)
treeaf2e1ae6273d106b279544e44747b329eeb12af6
parent9843da69eb90ba5029e3726e7c886bbcfe410cc9 (diff)
downloadpuppet-565554f47dccca357560ba96336b8bd4e3d2afe1.tar.gz
puppet-565554f47dccca357560ba96336b8bd4e3d2afe1.tar.xz
puppet-565554f47dccca357560ba96336b8bd4e3d2afe1.zip
finishing reorganization of base classes and such; there is now a clear tree heirarchy, with parents and children -- all tests pass on the types, but there are still some issues with client/server stuff
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@207 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/blink/client.rb7
-rw-r--r--lib/blink/element.rb38
-rw-r--r--lib/blink/transaction.rb2
-rw-r--r--lib/blink/type.rb48
-rw-r--r--lib/blink/type/file.rb41
-rw-r--r--lib/blink/type/package.rb8
-rw-r--r--lib/blink/type/process.rb8
-rw-r--r--lib/blink/type/service.rb18
-rw-r--r--lib/blink/type/state.rb13
-rw-r--r--lib/blink/type/symlink.rb43
-rw-r--r--lib/blink/type/typegen/filetype.rb4
11 files changed, 128 insertions, 102 deletions
diff --git a/lib/blink/client.rb b/lib/blink/client.rb
index 207cd734b..e2539481f 100644
--- a/lib/blink/client.rb
+++ b/lib/blink/client.rb
@@ -7,6 +7,7 @@
require 'blink'
require 'blink/function'
require 'blink/type'
+require 'blink/transaction'
module Blink
class ClientError < RuntimeError; end
@@ -48,9 +49,9 @@ module Blink
# that means that we need, at the least:
# - a standard mechanism for specifying that an object is no-op
# - a standard object that is considered a rollback object
- objects.each { |obj|
- obj.evaluate
- }
+ #objects.each { |obj|
+ # obj.evaluate
+ #}
transaction = Blink::Transaction.new(objects)
transaction.run
diff --git a/lib/blink/element.rb b/lib/blink/element.rb
new file mode 100644
index 000000000..492eb3905
--- /dev/null
+++ b/lib/blink/element.rb
@@ -0,0 +1,38 @@
+#!/usr/local/bin/ruby -w
+
+# $Id$
+
+# included so we can test object types
+require 'blink'
+
+
+#---------------------------------------------------------------
+# the base class for both types and states
+# very little functionality; basically just defines the interface
+# and provides a few simple across-the-board functions like 'noop'
+class Blink::Element
+ attr_writer :noop
+
+ #---------------------------------------------------------------
+ # all of our subclasses must respond to each of these methods...
+ @@interface_methods = [
+ :retrieve, :insync?, :sync, :fqpath, :evaluate, :refresh
+ ]
+
+ # so raise an error if a method that isn't overridden gets called
+ @@interface_methods.each { |method|
+ self.send(:define_method,method) {
+ raise "%s has not overridden %s" % [self.class,method]
+ }
+ }
+ #---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ # for testing whether we should actually do anything
+ def noop
+ return @noop || Blink[:noop] || false
+ end
+ #---------------------------------------------------------------
+
+end
+#---------------------------------------------------------------
diff --git a/lib/blink/transaction.rb b/lib/blink/transaction.rb
index 44733b187..7c1258614 100644
--- a/lib/blink/transaction.rb
+++ b/lib/blink/transaction.rb
@@ -45,7 +45,7 @@ class Blink::Transaction
#---------------------------------------------------------------
def run
- tree.evaluate(self)
+ @tree.evaluate(self)
self.evaluate
end
#---------------------------------------------------------------
diff --git a/lib/blink/type.rb b/lib/blink/type.rb
index c0ac2d0d4..ec36f7099 100644
--- a/lib/blink/type.rb
+++ b/lib/blink/type.rb
@@ -4,43 +4,13 @@
# included so we can test object types
require 'blink'
+require 'blink/element'
require 'blink/type/state'
# XXX see the bottom of the file for the rest of the inclusions
#---------------------------------------------------------------
-# the base class for both types and states
-# very little functionality; basically just defines the interface
-# and provides a few simple across-the-board functions like 'noop'
-class Blink::Element
- attr_writer :noop
-
- #---------------------------------------------------------------
- # all of our subclasses must respond to each of these methods...
- @@interface_methods = [
- :retrieve, :insync?, :sync, :fqpath, :evaluate, :refresh
- ]
-
- # so raise an error if a method that isn't overridden gets called
- @@interface_methods.each { |method|
- self.send(:define_method,method) {
- raise "%s has not overridden %s" % [self.class,method]
- }
- }
- #---------------------------------------------------------------
-
- #---------------------------------------------------------------
- # for testing whether we should actually do anything
- def noop
- return @noop || Blink[:noop] || false
- end
- #---------------------------------------------------------------
-
-end
-#---------------------------------------------------------------
-
-#---------------------------------------------------------------
# This class is the abstract base class for the mechanism for organizing
# work. No work is actually done by this class or its subclasses; rather,
# the subclasses include states which do the actual work.
@@ -60,6 +30,7 @@ end
# to use this interface, just define an 'each' method and 'include Blink::Type'
+module Blink
class Blink::Type < Blink::Element
attr_accessor :children, :parameters, :parent, :states
include Enumerable
@@ -149,6 +120,8 @@ class Blink::Type < Blink::Element
def Type.initvars
@objects = Hash.new
@actions = Hash.new
+ @validstates = {}
+ @validparameters = {}
end
#---------------------------------------------------------------
@@ -250,7 +223,7 @@ class Blink::Type < Blink::Element
#---------------------------------------------------------------
#---------------------------------------------------------------
- def Branch.buildstatehash
+ def Type.buildstatehash
unless defined? @validstates
@validstates = Hash.new(false)
end
@@ -270,7 +243,7 @@ class Blink::Type < Blink::Element
#---------------------------------------------------------------
#---------------------------------------------------------------
- def Branch.validstate(name)
+ def Type.validstate(name)
unless @validstates.length == @states.length
self.buildstatehash
end
@@ -283,8 +256,8 @@ class Blink::Type < Blink::Element
#---------------------------------------------------------------
#---------------------------------------------------------------
- def Branch.validparameter(name)
- return @validparameter.include?(name)
+ def Type.validparameter(name)
+ return @parameters.include?(name)
end
#---------------------------------------------------------------
@@ -369,8 +342,8 @@ class Blink::Type < Blink::Element
#---------------------------------------------------------------
def initialize(hash)
- @childary = []
- @childhash = {}
+ @children = []
+
@parent = nil
@noop = false
@@ -526,6 +499,7 @@ class Blink::Type < Blink::Element
}
#---------------------------------------------------------------
end # Blink::Type
+end
require 'blink/type/service'
require 'blink/type/file'
diff --git a/lib/blink/type/file.rb b/lib/blink/type/file.rb
index 24a465c88..82b4f574c 100644
--- a/lib/blink/type/file.rb
+++ b/lib/blink/type/file.rb
@@ -20,10 +20,10 @@ module Blink
stat = nil
begin
- stat = File.stat(self.object[:path].is)
+ stat = File.stat(self.parent[:path])
rescue
# this isn't correct, but what the hell
- raise "File '%s' does not exist: #{$!}" % self.object[:path].is
+ raise "File '%s' does not exist: #{$!}" % self.parent[:path]
end
self.is = stat.uid
@@ -31,7 +31,7 @@ module Blink
begin
user = Etc.getpwnam(self.should)
if user.gid == ""
- raise "Could not retrieve uid for %s" % self.object
+ raise "Could not retrieve uid for %s" % self.parent
end
Blink.debug "converting %s to integer %d" %
[self.should,user.uid]
@@ -57,12 +57,12 @@ module Blink
def sync
begin
- File.chown(self.should,-1,self.object[:path].is)
+ File.chown(self.should,-1,self.parent[:path])
rescue
- raise "failed to sync #{self.object[:path].is}: #{$!}"
+ raise "failed to sync #{self.parent[:path]}: #{$!}"
end
- self.object.newevent(:event => :inode_changed)
+ #self.parent.newevent(:event => :inode_changed)
end
end
@@ -78,9 +78,9 @@ module Blink
stat = nil
begin
- stat = File.stat(self.object[:path].is)
+ stat = File.stat(self.parent[:path])
rescue => error
- raise "File %s could not be stat'ed: %s" % [self.object[:path].is,error]
+ raise "File %s could not be stat'ed: %s" % [self.parent[:path],error]
end
self.is = stat.mode & 007777
@@ -89,11 +89,11 @@ module Blink
def sync
begin
- File.chmod(self.should,self.object[:path].is)
+ File.chmod(self.should,self.parent[:path])
rescue
- raise "failed to chmod #{self.object[:path].is}: #{$!}"
+ raise "failed to chmod #{self.parent[:path]}: #{$!}"
end
- self.object.newevent(:event => :inode_changed)
+ #self.parent.newevent(:event => :inode_changed)
end
end
@@ -129,10 +129,10 @@ module Blink
stat = nil
begin
- stat = File.stat(self.object[:path].is)
+ stat = File.stat(self.parent[:path])
rescue
# this isn't correct, but what the hell
- raise "File #{self.object[:path].is} does not exist: #{$!}"
+ raise "File #{self.parent[:path]} does not exist: #{$!}"
end
self.is = stat.gid
@@ -147,7 +147,7 @@ module Blink
# this is retarded
#p group
if group.gid == ""
- raise "Could not retrieve gid for %s" % self.object
+ raise "Could not retrieve gid for %s" % self.parent
end
Blink.debug "converting %s to integer %d" %
[self.should,group.gid]
@@ -184,12 +184,12 @@ module Blink
Blink.debug "setting chgrp state to %d" % self.should
begin
# set owner to nil so it's ignored
- File.chown(nil,self.should,self.object[:path].is)
+ File.chown(nil,self.should,self.parent[:path])
rescue
raise "failed to chgrp %s to %s: %s" %
- [self.object[:path].is, self.should, $!]
+ [self.parent[:path], self.should, $!]
end
- self.object.newevent(:event => :inode_changed)
+ #self.parent.newevent(:event => :inode_changed)
end
end
end
@@ -197,11 +197,14 @@ module Blink
class File < Type
attr_reader :stat, :path, :params
# class instance variable
- @params = [
+ @states = [
Blink::State::FileUID,
Blink::State::FileGroup,
Blink::State::FileMode,
- Blink::State::FileSetUID,
+ Blink::State::FileSetUID
+ ]
+
+ @parameters = [
:path
]
diff --git a/lib/blink/type/package.rb b/lib/blink/type/package.rb
index 6b09abc17..c4df3ddd2 100644
--- a/lib/blink/type/package.rb
+++ b/lib/blink/type/package.rb
@@ -19,7 +19,7 @@ module Blink
# raise "failed to sync #{@params[:file]}: #{$!}"
#end
- #self.object.newevent(:event => :inode_changed)
+ #self.parent.newevent(:event => :inode_changed)
end
end
end
@@ -30,8 +30,10 @@ module Blink
# into the general package object...
class Package < Type
attr_reader :version, :format
- @params = [
- Blink::State::PackageInstalled,
+ @states = [
+ Blink::State::PackageInstalled
+ ]
+ @parameters = [
:format,
:name,
:status,
diff --git a/lib/blink/type/process.rb b/lib/blink/type/process.rb
index 7cc7169b4..b42f75f26 100644
--- a/lib/blink/type/process.rb
+++ b/lib/blink/type/process.rb
@@ -21,13 +21,13 @@ module Blink
# this isn't correct, but what the hell
Blink::Message.new(
:level => :error,
- :source => self.object,
+ :source => self.parent,
:message => "Failed to run ps"
)
end
self.state = running
- Blink.debug "there are #{running} #{self.object} processes for start"
+ Blink.debug "there are #{running} #{self.parent} processes for start"
end
def <=>(other)
@@ -49,7 +49,7 @@ module Blink
string = @params[:binary] + (@params[:arguments] || "")
Blink::Message.new(
:level => :notice,
- :source => self.object,
+ :source => self.parent,
:message => "starting"
)
Kernel.exec(string)
@@ -60,7 +60,7 @@ module Blink
class Type
class BProcess < Type
attr_reader :stat, :path
- @params = [:start, :stop, :user, :pattern, :binary, :arguments]
+ @parameters = [:start, :stop, :user, :pattern, :binary, :arguments]
@name = :process
@namevar = :pattern
diff --git a/lib/blink/type/service.rb b/lib/blink/type/service.rb
index 280bc7fc7..d65464b25 100644
--- a/lib/blink/type/service.rb
+++ b/lib/blink/type/service.rb
@@ -16,15 +16,15 @@ module Blink
def retrieve
self.is = self.running()
Blink.debug "Running value for '%s' is '%s'" %
- [self.object.name,self.is]
+ [self.parent.name,self.is]
end
# should i cache this info?
def running
begin
- status = self.object.initcmd("status")
+ status = self.parent.initcmd("status")
Blink.debug "initcmd status for '%s' is '%s'" %
- [self.object.name,status]
+ [self.parent.name,status]
if status # the command succeeded
return 1
@@ -48,19 +48,19 @@ module Blink
if self.should > 0
if status < 1
Blink.debug "Starting '%s'" % self
- unless self.object.initcmd("start")
+ unless self.parent.initcmd("start")
raise "Failed to start %s" % self.name
end
else
Blink.debug "'%s' is already running, yo" % self
#Blink.debug "Starting '%s'" % self
- #unless self.object.initcmd("start")
+ #unless self.parent.initcmd("start")
# raise "Failed to start %s" % self.name
#end
end
elsif status > 0
Blink.debug "Stopping '%s'" % self
- unless self.object.initcmd("stop")
+ unless self.parent.initcmd("stop")
raise "Failed to stop %s" % self.name
end
else
@@ -72,8 +72,10 @@ module Blink
class Type
class Service < Type
attr_reader :stat
- @params = [
- Blink::State::ServiceRunning,
+ @states = [
+ Blink::State::ServiceRunning
+ ]
+ @parameters = [
:name,
:pattern
]
diff --git a/lib/blink/type/state.rb b/lib/blink/type/state.rb
index 240c472a5..25583842f 100644
--- a/lib/blink/type/state.rb
+++ b/lib/blink/type/state.rb
@@ -3,7 +3,8 @@
# $Id$
require 'blink'
-require 'blink/type'
+require 'blink/element'
+require 'blink/statechange'
#---------------------------------------------------------------
# this is a virtual base class for states
@@ -13,15 +14,14 @@ require 'blink/type'
# against the real state of the system. For instance, you could verify that
# a file's owner is what you want, but you could not create two file objects
# and use these methods to verify that they have the same owner
+module Blink
class Blink::State < Blink::Element
- include Comparable
-
attr_accessor :is, :should, :parent
@virtual = true
#---------------------------------------------------------------
- # every state class must tell us what it's name will be (as a symbol)
+ # every state class must tell us what its name will be (as a symbol)
# this determines how we will refer to the state during usage
# e.g., the Owner state for Files might say its name is :owner;
# this means that we can say "file[:owner] = 'yayness'"
@@ -45,7 +45,7 @@ class Blink::State < Blink::Element
#---------------------------------------------------------------
# return the full path to us, for logging and rollback
def fqpath
- return @object.fqpath, self.name
+ return @parent.fqpath, self.name
end
#---------------------------------------------------------------
@@ -96,7 +96,8 @@ class Blink::State < Blink::Element
#---------------------------------------------------------------
def to_s
- return @object.name.to_s + " -> " + self.name.to_s
+ return @parent.name.to_s + " -> " + self.name.to_s
end
#---------------------------------------------------------------
end
+end
diff --git a/lib/blink/type/symlink.rb b/lib/blink/type/symlink.rb
index a5f626d82..772b5a831 100644
--- a/lib/blink/type/symlink.rb
+++ b/lib/blink/type/symlink.rb
@@ -19,40 +19,40 @@ module Blink
def create
begin
Blink.debug("Creating symlink '%s' to '%s'" %
- [self.object[:path].is,self.should])
- unless File.symlink(self.should,self.object[:path].is)
+ [self.parent[:path],self.should])
+ unless File.symlink(self.should,self.parent[:path])
raise TypeError.new("Could not create symlink '%s'" %
- self.object[:path].is)
+ self.parent[:path])
end
rescue => detail
raise TypeError.new("Cannot create symlink '%s': %s" %
- [self.object[:path].is,detail])
+ [self.parent[:path],detail])
end
end
def remove
- if FileTest.symlink?(self.object[:path].is)
- Blink.debug("Removing symlink '%s'" % self.object[:path].is)
+ if FileTest.symlink?(self.parent[:path])
+ Blink.debug("Removing symlink '%s'" % self.parent[:path])
begin
- File.unlink(self.object[:path].is)
+ File.unlink(self.parent[:path])
rescue
raise TypeError.new("Failed to remove symlink '%s'" %
- self.object[:path].is)
+ self.parent[:path])
end
- elsif FileTest.exists?(self.object[:path].is)
+ elsif FileTest.exists?(self.parent[:path])
raise TypeError.new("Cannot remove normal file '%s'" %
- self.object[:path].is)
+ self.parent[:path])
else
Blink.debug("Symlink '%s' does not exist" %
- self.object[:path].is)
+ self.parent[:path])
end
end
def retrieve
stat = nil
- if FileTest.symlink?(self.object[:path].is)
- self.is = File.readlink(self.object[:path].is)
+ if FileTest.symlink?(self.parent[:path])
+ self.is = File.readlink(self.parent[:path])
Blink.debug("link value is '%s'" % self.is)
return
else
@@ -67,21 +67,21 @@ module Blink
if self.should.nil?
self.remove()
else # it should exist and be a symlink
- if FileTest.symlink?(self.object[:path].is)
- path = File.readlink(self.object[:path].is)
+ if FileTest.symlink?(self.parent[:path])
+ path = File.readlink(self.parent[:path])
if path != self.should
self.remove()
self.create()
end
- elsif FileTest.exists?(self.object[:path].is)
+ elsif FileTest.exists?(self.parent[:path])
raise TypeError.new("Cannot replace normal file '%s'" %
- self.object[:path].is)
+ self.parent[:path])
else
self.create()
end
end
- self.object.newevent(:event => :inode_changed)
+ #self.parent.newevent(:event => :inode_changed)
end
end
end
@@ -90,11 +90,14 @@ module Blink
class Symlink < Type
attr_reader :stat, :path, :params
# class instance variable
- @params = [
+ @states = [
Blink::State::FileUID,
Blink::State::FileGroup,
Blink::State::FileMode,
- Blink::State::SymlinkTarget,
+ Blink::State::SymlinkTarget
+ ]
+
+ @parameters = [
:path
]
diff --git a/lib/blink/type/typegen/filetype.rb b/lib/blink/type/typegen/filetype.rb
index 3140c2e79..23854ade9 100644
--- a/lib/blink/type/typegen/filetype.rb
+++ b/lib/blink/type/typegen/filetype.rb
@@ -22,6 +22,8 @@ class Blink::Type::FileType < Blink::Type::TypeGenerator
end
klass = super(hash)
+ klass.escapednewlines = true
+
#klass.childtype = Blink::Type::FileRecord.newtype(
# :name => hash[:name] + "_record",
# :splitchar => hash[:recordsplit],
@@ -71,7 +73,7 @@ class Blink::Type::FileType < Blink::Type::TypeGenerator
#---------------------------------------------------------------
def FileType.escapednewlines
- if @escnlines.nil?
+ if ! defined? @escnlines or @escnlines.nil?
return false
else
return @escnlines