[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5
James Turnbull
james at lovedthanlost.net
Wed Apr 8 21:48:18 UTC 2009
The following commit has been merged in the master branch:
commit fa6494b69ad1b01a9c587c86aa1731f4702f5509
Author: Luke Kanies <luke at madstop.com>
Date: Fri Feb 13 00:29:07 2009 -0600
Using the FileCollection where appropriate.
This commit just replaces the :file and :line accessors
with the use of the new FileCollection Lookup module.
This should mean that we've normalized all file names in
a given process, which *might* have drastic RAM improvements.
For initial simplicity, I've gone with a single global
collection of file names, but it's built so it's easy to use
individual file collections instead.
Signed-off-by: Luke Kanies <luke at madstop.com>
diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb
index 451b496..69f59ff 100644
--- a/lib/puppet/file_collection.rb
+++ b/lib/puppet/file_collection.rb
@@ -1,6 +1,12 @@
# A simple way to turn file names into singletons,
# so we don't have tons of copies of each file path around.
class Puppet::FileCollection
+ require 'puppet/file_collection/lookup'
+
+ def self.collection
+ @collection
+ end
+
def initialize
@paths = []
end
@@ -17,4 +23,6 @@ class Puppet::FileCollection
def path(index)
@paths[index]
end
+
+ @collection = self.new
end
diff --git a/lib/puppet/file_collection/lookup.rb b/lib/puppet/file_collection/lookup.rb
index 8f69c66..ddb0c84 100644
--- a/lib/puppet/file_collection/lookup.rb
+++ b/lib/puppet/file_collection/lookup.rb
@@ -5,6 +5,10 @@ require 'puppet/file_collection'
module Puppet::FileCollection::Lookup
attr_accessor :line, :file_index
+ def file_collection
+ Puppet::FileCollection.collection
+ end
+
def file=(path)
@file_index = file_collection.index(path)
end
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
index 303d75b..ab23dd1 100644
--- a/lib/puppet/parser/ast.rb
+++ b/lib/puppet/parser/ast.rb
@@ -2,6 +2,7 @@
require 'puppet'
require 'puppet/util/autoload'
+require 'puppet/file_collection/lookup'
# The base class for all of the objects that make up the parse trees.
# Handles things like file name, line #, and also does the initialization
@@ -10,11 +11,13 @@ class Puppet::Parser::AST
# Do this so I don't have to type the full path in all of the subclasses
AST = Puppet::Parser::AST
+ include Puppet::FileCollection::Lookup
+
include Puppet::Util::Errors
include Puppet::Util::MethodHelper
include Puppet::Util::Docs
- attr_accessor :line, :file, :parent, :scope
+ attr_accessor :parent, :scope
# don't fetch lexer comment by default
def use_docs
@@ -82,8 +85,6 @@ class Puppet::Parser::AST
# method for them. This is probably pretty inefficient and should
# likely be changed at some point.
def initialize(args)
- @file = nil
- @line = nil
set_options(args)
end
end
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index c545c1e..dba9812 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -36,7 +36,7 @@ class Puppet::Parser::AST
# Interpolate the string looking for variables, and then return
# the result.
def evaluate(scope)
- return scope.strinterp(@value, @file, @line)
+ return scope.strinterp(@value, file, line)
end
end
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index 5c4a241..f8cf3a8 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -40,8 +40,8 @@ class Puppet::Parser::AST
:type => r.type,
:title => r.title,
:params => params,
- :file => @file,
- :line => @line,
+ :file => file,
+ :line => line,
:source => scope.source,
:scope => scope
)
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 2fdd78d..7f0e333 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -4,13 +4,17 @@ class Puppet::Parser::Resource
require 'puppet/parser/resource/param'
require 'puppet/parser/resource/reference'
require 'puppet/util/tagging'
+ require 'puppet/file_collection/lookup'
+
+ include Puppet::FileCollection::Lookup
+
include Puppet::Util
include Puppet::Util::MethodHelper
include Puppet::Util::Errors
include Puppet::Util::Logging
include Puppet::Util::Tagging
- attr_accessor :source, :line, :file, :scope, :rails_id
+ attr_accessor :source, :scope, :rails_id
attr_accessor :virtual, :override, :translated
attr_reader :exported, :evaluated, :params
diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb
index 1a5cfe8..7ce58f4 100644
--- a/lib/puppet/parser/resource/param.rb
+++ b/lib/puppet/parser/resource/param.rb
@@ -1,10 +1,14 @@
+require 'puppet/file_collection/lookup'
+
# The parameters we stick in Resources.
class Puppet::Parser::Resource::Param
- attr_accessor :name, :value, :source, :line, :file, :add
+ attr_accessor :name, :value, :source, :add
include Puppet::Util
include Puppet::Util::Errors
include Puppet::Util::MethodHelper
+ include Puppet::FileCollection::Lookup
+
def initialize(hash)
set_options(hash)
requiredopts(:name, :value, :source)
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb
index cb505d6..bffc037 100644
--- a/lib/puppet/parser/resource/reference.rb
+++ b/lib/puppet/parser/resource/reference.rb
@@ -1,7 +1,9 @@
require 'puppet/resource_reference'
+require 'puppet/file_collection/lookup'
# A reference to a resource. Mostly just the type and title.
class Puppet::Parser::Resource::Reference < Puppet::ResourceReference
+ include Puppet::FileCollection::Lookup
include Puppet::Util::MethodHelper
include Puppet::Util::Errors
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index b57c74b..5cb4ce1 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -10,6 +10,7 @@ require 'puppet/util/errors'
require 'puppet/util/log_paths'
require 'puppet/util/logging'
require 'puppet/resource_reference'
+require 'puppet/file_collection/lookup'
# see the bottom of the file for the rest of the inclusions
@@ -19,6 +20,7 @@ class Type
include Puppet::Util::Errors
include Puppet::Util::LogPaths
include Puppet::Util::Logging
+ include Puppet::FileCollection::Lookup
###############################
# Code related to resource type attributes.
@@ -2135,8 +2137,6 @@ class Type
# In naming methods, I have tried to consistently name the method so
# that it is clear whether it operates on all attributes (thus has 'attr' in
# the method name, or whether it operates on a specific type of attributes.
- attr_accessor :file, :line
-
attr_writer :title
attr_writer :noop
diff --git a/spec/unit/file_collection.rb b/spec/unit/file_collection.rb
index e9acc8d..81bcc2d 100755
--- a/spec/unit/file_collection.rb
+++ b/spec/unit/file_collection.rb
@@ -42,4 +42,12 @@ describe Puppet::FileCollection do
it "should return nil as the file name when an unknown index is provided" do
@collection.path(50).should be_nil
end
+
+ it "should provide a global collection" do
+ Puppet::FileCollection.collection.should be_instance_of(Puppet::FileCollection)
+ end
+
+ it "should reuse the global collection" do
+ Puppet::FileCollection.collection.should equal(Puppet::FileCollection.collection)
+ end
end
diff --git a/spec/unit/file_collection/lookup.rb b/spec/unit/file_collection/lookup.rb
index 9ae7ae5..81cc618 100755
--- a/spec/unit/file_collection/lookup.rb
+++ b/spec/unit/file_collection/lookup.rb
@@ -12,7 +12,7 @@ describe Puppet::FileCollection::Lookup do
@tester = LookupTester.new
@file_collection = mock 'file_collection'
- @tester.stubs(:file_collection).returns @file_collection
+ Puppet::FileCollection.stubs(:collection).returns @file_collection
end
it "should use the file collection to determine the index of the file name" do
@@ -38,4 +38,9 @@ describe Puppet::FileCollection::Lookup do
@tester.line = 50
@tester.line.should == 50
end
+
+ it "should default to the global file collection" do
+ Puppet::FileCollection.expects(:collection).returns "collection"
+ @tester.file_collection.should == "collection"
+ end
end
diff --git a/spec/unit/parser/ast.rb b/spec/unit/parser/ast.rb
index 5139437..35e2b1e 100644
--- a/spec/unit/parser/ast.rb
+++ b/spec/unit/parser/ast.rb
@@ -5,6 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/parser/ast'
describe Puppet::Parser::AST do
+
+ it "should use the file lookup module" do
+ Puppet::Parser::AST.ancestors.should be_include(Puppet::FileCollection::Lookup)
+ end
it "should have a doc accessor" do
ast = Puppet::Parser::AST.new({})
@@ -34,4 +38,4 @@ describe Puppet::Parser::AST do
end
end
-end
\ No newline at end of file
+end
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 63cfbc2..2666f64 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -44,6 +44,10 @@ describe Puppet::Parser::Resource do
end
end
+ it "should use the file lookup module" do
+ Puppet::Parser::Resource.ancestors.should be_include(Puppet::FileCollection::Lookup)
+ end
+
it "should be isomorphic if it is builtin and models an isomorphic type" do
Puppet::Type.type(:file).expects(:isomorphic?).returns(true)
@resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
index bb14526..6284e67 100755
--- a/spec/unit/parser/resource/reference.rb
+++ b/spec/unit/parser/resource/reference.rb
@@ -7,6 +7,10 @@ describe Puppet::Parser::Resource::Reference do
@type = Puppet::Parser::Resource::Reference
end
+ it "should use the file lookup module" do
+ Puppet::Parser::Resource::Reference.ancestors.should be_include(Puppet::FileCollection::Lookup)
+ end
+
it "should require a type" do
proc { @type.new(:title => "yay") }.should raise_error(Puppet::DevError)
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list