lib/cuken/api/chef.rb in cuken-0.1.4 vs lib/cuken/api/chef.rb in cuken-0.1.7

- old
+ new

@@ -1,8 +1,11 @@ require 'aruba/api' unless defined? Aruba::Api require 'chef' unless defined? Chef +require 'grit' unless defined? Grit +require 'cuken/api/common' require 'cuken/api/chef/common' +require 'cuken/api/chef/knife' module ::Cuken module Api module Chef @@ -37,26 +40,28 @@ end end def chef_clone_repo(ckbk_path, cookbook = false, repo = chef.remote_chef_repo, brnch = 'master') in_current_dir do + pth = Pathname(ckbk_path).expand_path gritty = ::Grit::Git.new(current_dir) + $stdout.puts gritty.inspect clone_opts = {:quiet => false, :verbose => true, :progress => true, :branch => brnch} - if Dir.exists?(ckbk_path) - $stdout.puts "Pulling: #{repo} into #{ckbk_path}" - gritty.pull(clone_opts, repo, ckbk_path) + if pth.directory? + $stdout.puts "Pulling: #{repo} into #{pth}" + gritty.pull(clone_opts, repo, pth.to_s) else - $stdout.puts "Cloning: #{repo} into #{ckbk_path}" - gritty.clone(clone_opts, repo, ckbk_path) + $stdout.puts "Cloning: #{repo} into #{pth}" + res = gritty.clone(clone_opts, repo, pth.to_s) end - update_cookbook_paths(ckbk_path, cookbook) - Pathname(ckbk_path) + update_cookbook_paths(pth, cookbook) + pth end end def run_knife_command(cmd, interactive=false) - no_ckbk_pth_opt = ['cookbook delete'].each{|str| break true if cmd[/#{str}/]} + no_ckbk_pth_opt = ['cookbook delete', 'role from file'].each{|str| break true if cmd[/#{str}/]} no_ckbk_pth = chef.cookbooks_paths.empty? if no_ckbk_pth ckbk_pth_opt = false else ckbk_pth = (chef.cookbooks_paths.collect { |pn| pn.expand_path.to_s }).join(':') @@ -66,16 +71,19 @@ in_current_dir do unless chef.client_knife_path chef.client_knife_path = Pathname(chef.local_chef_repo).ascend { |d| h=d+'.chef'+'knife.rb'; break h if h.file? } end raise(RuntimeError, "chef.client_knife_path is required", caller) unless chef.client_knife_path - cmd += " -c #{chef.client_knife_path.expand_path.to_s}" if chef.client_knife_path.expand_path.exist? - cmd += " -o #{ckbk_pth}" if ckbk_pth_opt - cmd += " --log_level debug" if chef.knife_debug + end + cmd += " -c #{chef.client_knife_path.expand_path.to_s}" if chef.client_knife_path.expand_path.exist? + cmd += " -o #{ckbk_pth}" if ckbk_pth_opt + cmd += " --log_level debug" if chef.knife_debug + chef.root_dir ||= current_dir + in_chef_root do if interactive - run_interactive(unescape("#{chef.knife}" + cmd)) + run_interactive(unescape("#{chef.knife_command}" + cmd)) else - run_simple(unescape("#{chef.knife}" + cmd)) + run_simple(unescape("#{chef.knife_command}" + cmd)) end end end def rest