joewilliams (owner)

Revisions

gist: 127554 Download_button fork
public
Public Clone URL: git://gist.github.com/127554.git
Embed All Files: show embed
rake_cookbook_metadata.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Author:: Joshua Timberman (<joshua@opscode.com>)
# Author:: Adam Jacob (<adam@opscode.com>)
#
# Copyright:: 2009, Opscode, Inc
#
# 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.
 
 
desc "Create metadata.rb for each cookbook"
task :cookbook_metadata do
  Chef::Config[:cookbook_path] = [ File.join(File.dirname(__FILE__), "cookbooks") ]
  cl = Chef::CookbookLoader.new
  cl.each do |cookbook|
    if ENV['COOKBOOK']
      next unless cookbook.name.to_s == ENV['COOKBOOK']
    end
 
    Chef::Config.cookbook_path.each do |cdir|
      metadata_rb_file = File.open(File.join(cdir, cookbook.name.to_s, 'metadata.rb'), "w")
      puts "* Creating the metadata.rb for #{cookbook.name}"
 
      # If the cookbook has a README.rdoc, then it should be the long_description
      if File.exists?(File.join(cdir, cookbook.name.to_s, 'README.rdoc'))
        long_description = "IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))"
        puts "** #{cookbook.name} has README.rdoc"
      else
        long_description = %w{"Configures #{cookbook.name}"}
      end
      metadata = <<-EOH
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Configures #{cookbook.name}"
long_description #{long_description}
version "0.7"
EOH
      # Load up the recipes
      if cookbook.recipe_files.nitems > 1
        cookbook.recipe_files.each do |rfile|
          unless rfile =~ /default/
            recipe_name = "#{cookbook.name}::#{File.basename(rfile, ".rb")}"
            metadata << "recipe \"#{recipe_name}\"\n"
            puts "** #{cookbook.name} has recipe, #{recipe_name}"
          end
        end
      end
 
      # Load up attributes
      if cookbook.attribute_files.nitems > 0
        cookbook.attribute_files.each do |afile|
          attribute_name = File.basename(afile, ".rb")
          metadata << %Q{
attribute "#{attribute_name}",
:display_name => "",
:description => "",
:recipes => [ "#{cookbook.name}" ],
:default => ""
}
          puts "** #{cookbook.name} has attributes, #{attribute_name}"
        end
      end
 
      metadata_rb_file.puts metadata
    end
  end
end