Skip to content
Browse files

Fix CHEF-2225: handle deprecated cookbooks in knife cookbook site dow…

…nload
  • Loading branch information...
1 parent a4b0523 commit b5324dd7a58e1f6fddddd288d690bde31f2d1946 Nuo Yan committed Apr 14, 2011
View
5 chef/distro/common/html/knife-cookbook-site.1.html
@@ -134,6 +134,7 @@ <h2 id="DOWNLOAD">DOWNLOAD</h2>
<dl>
<dt><code>-f</code>, <code>--file FILE</code></dt><dd>The filename to write to</dd>
+<dt class="flush"><code>--force</code></dt><dd>Force download deprecated cookbook</dd>
</dl>
@@ -215,11 +216,11 @@ <h2 id="SEE-ALSO">SEE ALSO</h2>
<h2 id="AUTHOR">AUTHOR</h2>
-<p> Chef was written by Adam Jacob <a href="&#x6d;&#x61;&#105;&#108;&#x74;&#111;&#58;&#x61;&#100;&#97;&#109;&#x40;&#111;&#x70;&#x73;&#x63;&#x6f;&#100;&#101;&#x2e;&#99;&#111;&#x6d;" data-bare-link="true">&#97;&#100;&#97;&#x6d;&#x40;&#111;&#112;&#x73;&#x63;&#x6f;&#x64;&#101;&#46;&#x63;&#111;&#109;</a> with many contributions from the community.</p>
+<p> Chef was written by Adam Jacob <a href="&#109;&#x61;&#x69;&#108;&#116;&#x6f;&#x3a;&#x61;&#x64;&#97;&#x6d;&#x40;&#111;&#x70;&#x73;&#99;&#111;&#100;&#x65;&#46;&#99;&#111;&#109;" data-bare-link="true">&#x61;&#100;&#97;&#x6d;&#64;&#x6f;&#x70;&#x73;&#x63;&#x6f;&#100;&#x65;&#x2e;&#x63;&#x6f;&#109;</a> with many contributions from the community.</p>
<h2 id="DOCUMENTATION">DOCUMENTATION</h2>
-<p> This manual page was written by Joshua Timberman <a href="&#x6d;&#97;&#105;&#108;&#116;&#x6f;&#58;&#106;&#111;&#115;&#104;&#x75;&#97;&#64;&#x6f;&#x70;&#x73;&#x63;&#111;&#100;&#x65;&#46;&#x63;&#111;&#x6d;" data-bare-link="true">&#106;&#111;&#x73;&#x68;&#x75;&#x61;&#64;&#x6f;&#112;&#115;&#99;&#x6f;&#100;&#101;&#46;&#x63;&#111;&#x6d;</a>.
+<p> This manual page was written by Joshua Timberman <a href="&#109;&#x61;&#x69;&#x6c;&#x74;&#111;&#x3a;&#x6a;&#111;&#x73;&#104;&#117;&#97;&#64;&#x6f;&#x70;&#x73;&#x63;&#111;&#x64;&#101;&#46;&#99;&#111;&#x6d;" data-bare-link="true">&#106;&#x6f;&#115;&#104;&#117;&#x61;&#64;&#111;&#112;&#115;&#x63;&#x6f;&#x64;&#x65;&#x2e;&#99;&#x6f;&#109;</a>.
Permission is granted to copy, distribute and / or modify this document under the terms of the Apache 2.0 License.</p>
<h2 id="CHEF">CHEF</h2>
View
4 chef/distro/common/man/man1/knife-cookbook-site.1
@@ -52,6 +52,10 @@ If \fI\-d\fR is specified, the process is applied recursively to all the cookboo
\fB\-f\fR, \fB\-\-file FILE\fR
The filename to write to
.
+.TP
+\fB\-\-force\fR
+Force download deprecated cookbook
+.
.P
Downloads a specific cookbook from the Community site, optionally specifying a certain version\.
.
View
2 chef/distro/common/markdown/man1/knife-cookbook-site.mkd
@@ -39,6 +39,8 @@ __knife cookbook site download COOKBOOK [VERSION]__ _(options)_
* `-f`, `--file FILE`:
The filename to write to
+ * `--force`:
+ Force download deprecated cookbook
Downloads a specific cookbook from the Community site, optionally
specifying a certain version.
View
40 chef/lib/chef/knife/cookbook_site_download.rb
@@ -5,9 +5,9 @@
# 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.
@@ -27,26 +27,38 @@ class CookbookSiteDownload < Knife
category "cookbook site"
option :file,
- :short => "-f FILE",
- :long => "--file FILE",
- :description => "The filename to write to"
+ :short => "-f FILE",
+ :long => "--file FILE",
+ :description => "The filename to write to"
+
+ option :force,
+ :long => "--force",
+ :description => "Force download deprecated version"
def run
- if @name_args.length == 1
- current = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}")
- cookbook_data = noauth_rest.get_rest(current["latest_version"])
- else
- cookbook_data = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
+ current = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}")
+ if current["deprecated"] == true
+ replacement = File.basename(current["replacement"])
+ ui.warn("DEPRECATION: This cookbook has been deprecated. It has been replaced by #{replacement}.")
+ unless config[:force]
+ ui.warn("Use --force to force download deprecated cookbook.")
+ return
+ end
end
+ cookbook_data = if @name_args.length == 1
+ noauth_rest.get_rest(current["latest_version"])
+ else
+ noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
+ end
@version = cookbook_data['version']
-
- ui.info("Downloading #{@name_args[0]} from the cookbooks site at version #{cookbook_data['version']} to #{config[:file]}")
- noauth_rest.sign_on_redirect = false
- tf = noauth_rest.get_rest(cookbook_data["file"], true)
unless config[:file]
config[:file] = File.join(Dir.pwd, "#{@name_args[0]}-#{cookbook_data['version']}.tar.gz")
end
+ ui.info("Downloading #{@name_args[0]} from the cookbooks site at version #{cookbook_data['version']} to #{config[:file]}")
+ noauth_rest.sign_on_redirect = false
+ tf = noauth_rest.get_rest(cookbook_data["file"], true)
+
FileUtils.cp(tf.path, config[:file])
ui.info("Cookbook saved: #{config[:file]}")
end

0 comments on commit b5324dd

Please sign in to comment.
Something went wrong with that request. Please try again.