module Gitchefsync::FS
Public Class Methods
cmd(x, env={})
click to toggle source
executes a command line process raises and exception on stderr returns the sys output
# File lib/gitchefsync/io_util.rb, line 43 def self.cmd(x, env={}) ret = nil err = nil Open3.popen3(env, x) do |stdin, stdout, stderr, wait_thr| ret = stdout.read err = stderr.read end if err.to_s != '' raise CmdError, "stdout=#{err}:cmd=#{x}" end ret end
cmdBerks(x)
click to toggle source
there is a host of errors associated with berks “DEPRECATED: Your Berksfile contains a site location …” this method is to allow filtering on the message to determine what is a real error versus what is just a warning - at this time will just have no checking
# File lib/gitchefsync/io_util.rb, line 61 def self.cmdBerks(x) self.cmdNoError(x) end
cmdNoError(x)
click to toggle source
# File lib/gitchefsync/io_util.rb, line 65 def self.cmdNoError(x) ret = nil err = nil Open3.popen3(x) do |stdin, stdout, stderr, wait_thr| ret = stdout.read err = stderr.read end ret << err ret end
flatten(path, find)
click to toggle source
# File lib/gitchefsync/io_util.rb, line 77 def self.flatten(path, find) arr_path = Array.new arr_path.unshift(File.basename(path, ".*")) fp = path while true do fp = File.expand_path("..", fp) return nil if fp == "/" break if File.basename(fp) == find arr_path.unshift(File.basename(fp)) end arr_path.join("_") end
getBasePath(path, find)
click to toggle source
# File lib/gitchefsync/io_util.rb, line 90 def self.getBasePath(path, find) fp = path while true do fp = File.expand_path("..", fp) return nil if fp == "/" return fp if File.basename(fp) == find end end
knifeReady(working_dir,knife_file)
click to toggle source
copy the knife file over TODO: do this the ruby way
# File lib/gitchefsync/io_util.rb, line 26 def self.knifeReady (working_dir,knife_file) chef_dir = working_dir + "/" + ".chef" if !File.exists?(chef_dir) self.cmd "mkdir -p #{chef_dir}" end if !File.exists?(knife_file) raise(KnifeError, "knife file must be defined") end self.cmd "cp -f #{knife_file} #{chef_dir}/knife.rb" #check for knife readiness self.cmd "cd #{working_dir} && knife client list" end