diff options
author | Daniel DeLeo <dan@opscode.com> | 2011-04-11 16:43:59 -0700 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2011-04-11 16:43:59 -0700 |
commit | 9823fee7d5579dc4775964e7b6cb6cc6c189aa79 (patch) | |
tree | 18933ce3fa5f0c41ed2f23ac873746bb181c2199 | |
parent | 5e98c9ee4c2c4b0715a6a3d15b3b94e95c65cff5 (diff) | |
download | chef-9823fee7d5579dc4775964e7b6cb6cc6c189aa79.tar.gz |
polish cookbook uploader output
-rw-r--r-- | chef/lib/chef/cookbook_uploader.rb | 15 | ||||
-rw-r--r-- | chef/lib/chef/knife/cookbook_upload.rb | 15 | ||||
-rw-r--r-- | chef/lib/chef/knife/recipe_list.rb | 1 |
3 files changed, 18 insertions, 13 deletions
diff --git a/chef/lib/chef/cookbook_uploader.rb b/chef/lib/chef/cookbook_uploader.rb index 6b7c6e72ad..dec3dd194f 100644 --- a/chef/lib/chef/cookbook_uploader.rb +++ b/chef/lib/chef/cookbook_uploader.rb @@ -1,4 +1,5 @@ +require 'set' require 'rest_client' require 'chef/exceptions' require 'chef/knife/cookbook_metadata' @@ -67,17 +68,22 @@ class Chef self.class.setup_worker_threads + checksums_to_upload = Set.new + # upload the new checksums and commit the sandbox new_sandbox['checksums'].each do |checksum, info| if info['needs_upload'] == true + checksums_to_upload << checksum Chef::Log.info("Uploading #{checksum_files[checksum]} (checksum hex = #{checksum}) to #{info['url']}") - self.class.work_queue << uploader_function_for(checksum_files[checksum], checksum, info['url']) + self.class.work_queue << uploader_function_for(checksum_files[checksum], checksum, info['url'], checksums_to_upload) else Chef::Log.debug("#{checksum_files[checksum]} has not changed") end end - sleep 0.1 until self.class.work_queue.empty? + until checksums_to_upload.empty? + sleep 0.1 + end sandbox_url = new_sandbox['uri'] Chef::Log.debug("Committing sandbox") @@ -102,7 +108,7 @@ class Chef def worker_thread(work_queue) end - def uploader_function_for(file, checksum, url) + def uploader_function_for(file, checksum, url, checksums_to_upload) lambda do # Checksum is the hexadecimal representation of the md5, # but we need the base64 encoding for the content-md5 @@ -123,8 +129,9 @@ class Chef begin RestClient::Resource.new(url, :headers=>headers, :timeout=>1800, :open_timeout=>1800).put(file_contents) + checksums_to_upload.delete(checksum) rescue RestClient::Exception => e - Chef::Log.error("Upload failed: #{e.message}\n#{e.response.body}") + ui.error("Failed to upload #@cookbook : #{e.message}\n#{e.response.body}") raise end end diff --git a/chef/lib/chef/knife/cookbook_upload.rb b/chef/lib/chef/knife/cookbook_upload.rb index bafe3cc2c8..471def07d4 100644 --- a/chef/lib/chef/knife/cookbook_upload.rb +++ b/chef/lib/chef/knife/cookbook_upload.rb @@ -68,9 +68,10 @@ class Chef version_constraints_to_update = {} if config[:all] + justify_width = cookbook_repo.cookbook_names.map {|name| name.size}.max.to_i + 2 cookbook_repo.each do |cookbook_name, cookbook| cookbook.freeze_version if config[:freeze] - upload(cookbook) + upload(cookbook, justify_width) version_constraints_to_update[cookbook_name] = cookbook.version end else @@ -79,11 +80,12 @@ class Chef ui.error("You must specify the --all flag or at least one cookbook name") exit 1 end + justify_width = @name_args.map {|name| name.size }.max.to_i + 2 @name_args.each do |cookbook_name| begin cookbook = cookbook_repo[cookbook_name] cookbook.freeze_version if config[:freeze] - upload(cookbook) + upload(cookbook, justify_width) version_constraints_to_update[cookbook_name] = cookbook.version rescue Exceptions::CookbookNotFoundInRepo => e ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it") @@ -129,12 +131,9 @@ class Chef end end - def upload(cookbook) - if config[:all] - ui.info("** #{cookbook.name} **") - else - ui.info "Uploading #{cookbook.name}..." - end + def upload(cookbook, justify_width) + ui.info("Uploading #{cookbook.name.to_s.ljust(justify_width + 10)} [#{cookbook.version}]") + check_for_broken_links(cookbook) Chef::CookbookUploader.new(cookbook, config[:cookbook_path], :force => config[:force]).upload_cookbook rescue Net::HTTPServerException => e diff --git a/chef/lib/chef/knife/recipe_list.rb b/chef/lib/chef/knife/recipe_list.rb index 25c181bc08..ed7d2a9509 100644 --- a/chef/lib/chef/knife/recipe_list.rb +++ b/chef/lib/chef/knife/recipe_list.rb @@ -23,7 +23,6 @@ class Chef::Knife::RecipeList < Chef::Knife def run recipes = rest.get_rest('cookbooks/_recipes') - recipes = recipes.keys.map { |cb| recipes[cb].map {|ver, rec| rec.map{ |rn| "#{cb}::#{rn} (#{ver})" }}}.flatten.uniq if pattern = @name_args.first recipes = recipes.grep(Regexp.new(pattern)) end |