diff options
author | Ezra Zygmuntowicz <ez@engineyard.com> | 2008-10-08 14:19:52 -0700 |
---|---|---|
committer | Ezra Zygmuntowicz <ez@engineyard.com> | 2008-10-08 14:19:52 -0700 |
commit | c5d33c1298834ce40b8fbf344f281045771b5371 (patch) | |
tree | 1f0d4c7eab1eb379b544282a7ce48052acf719a5 /lib/chef/cookbook_loader.rb | |
parent | 3d14601aea23dee3899d097324875274da419d84 (diff) | |
download | chef-c5d33c1298834ce40b8fbf344f281045771b5371.tar.gz |
big refactor of the repo layout. move to a chef gem and a chef-server gem all with proper deps
Diffstat (limited to 'lib/chef/cookbook_loader.rb')
-rw-r--r-- | lib/chef/cookbook_loader.rb | 147 |
1 files changed, 0 insertions, 147 deletions
diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb deleted file mode 100644 index 6f6c8d8010..0000000000 --- a/lib/chef/cookbook_loader.rb +++ /dev/null @@ -1,147 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -class Chef - class CookbookLoader - - attr_accessor :cookbook - - include Enumerable - - def initialize() - @cookbook = Hash.new - load_cookbooks - end - - def load_cookbooks - cookbook_settings = Hash.new - Chef::Config.cookbook_path.each do |cb_path| - Dir[File.join(cb_path, "*")].each do |cookbook| - next unless File.directory?(cookbook) - cookbook_name = File.basename(cookbook).to_sym - unless cookbook_settings.has_key?(cookbook_name) - cookbook_settings[cookbook_name] = { - :ignore_regexes => Array.new, - :attribute_files => Array.new, - :definition_files => Array.new, - :recipe_files => Array.new, - :template_files => Array.new, - :remote_files => Array.new, - } - end - ignore_regexes = load_ignore_file(File.join(cookbook, "ignore")) - cookbook_settings[cookbook_name][:ignore_regexes].concat(ignore_regexes) - load_files_unless_basename( - File.join(cookbook, "attributes", "*.rb"), - cookbook_settings[cookbook_name][:attribute_files], - cookbook_settings[cookbook_name][:ignore_regexes] - ) - load_files_unless_basename( - File.join(cookbook, "definitions", "*.rb"), - cookbook_settings[cookbook_name][:definition_files], - cookbook_settings[cookbook_name][:ignore_regexes] - ) - load_files_unless_basename( - File.join(cookbook, "recipes", "*.rb"), - cookbook_settings[cookbook_name][:recipe_files], - cookbook_settings[cookbook_name][:ignore_regexes] - ) - load_cascading_files( - File.join(cookbook, "templates", "**", "*.erb"), - File.join(cookbook, "templates"), - cookbook_settings[cookbook_name][:template_files], - cookbook_settings[cookbook_name][:ignore_regexes] - ) - load_cascading_files( - File.join(cookbook, "files", "**", "*"), - File.join(cookbook, "files"), - cookbook_settings[cookbook_name][:remote_files], - cookbook_settings[cookbook_name][:ignore_regexes] - ) - end - end - cookbook_settings.each_key do |cookbook| - @cookbook[cookbook] = Chef::Cookbook.new(cookbook) - @cookbook[cookbook].attribute_files = cookbook_settings[cookbook][:attribute_files] - @cookbook[cookbook].definition_files = cookbook_settings[cookbook][:definition_files] - @cookbook[cookbook].recipe_files = cookbook_settings[cookbook][:recipe_files] - @cookbook[cookbook].template_files = cookbook_settings[cookbook][:template_files] - @cookbook[cookbook].remote_files = cookbook_settings[cookbook][:remote_files] - end - end - - def [](cookbook) - if @cookbook.has_key?(cookbook.to_sym) - @cookbook[cookbook.to_sym] - else - raise ArgumentError, "Cannot find a cookbook named #{cookbook.to_s}" - end - end - - def each - @cookbook.each_value do |cobject| - yield cobject - end - end - - private - - def load_ignore_file(ignore_file) - results = Array.new - if File.exists?(ignore_file) && File.readable?(ignore_file) - IO.foreach(ignore_file) do |line| - next if line =~ /^#/ - next if line =~ /^\w*$/ - line.chomp! - results << Regexp.new(line) - end - end - results - end - - def load_cascading_files(file_glob, base_path, result_array, ignore_regexes) - Dir[file_glob].each do |file| - next if skip_file(file, ignore_regexes) - file =~ /^#{base_path}\/(.+)$/ - singlecopy = $1 - unless result_array.detect { |f| f =~ /#{singlecopy}$/ } - result_array << file - end - end - end - - def load_files_unless_basename(file_glob, result_array, ignore_regexes) - Dir[file_glob].each do |file| - next if skip_file(file, ignore_regexes) - file_basename = File.basename(file) - # If we've seen a file with this basename before, skip it. - unless result_array.detect { |f| File.basename(f) == file_basename } - result_array << file - end - end - end - - def skip_file(file, ignore_regexes) - skip = false - ignore_regexes.each do |exp| - skip = true if exp.match(file) - end - skip - end - - end -end
\ No newline at end of file |