Module: Gitchefsync::FS

Defined in:
lib/gitchefsync/io_util.rb

Class Method Summary collapse

Class Method Details

.cmd(x, env = {}) ⇒ Object

executes a command line process raises and exception on stderr returns the sys output



43
44
45
46
47
48
49
50
51
52
53
54
# 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) ⇒ Object

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



61
62
63
# File 'lib/gitchefsync/io_util.rb', line 61

def self.cmdBerks(x)
  self.cmdNoError(x)
end

.cmdNoError(x) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# 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) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# 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) ⇒ Object



90
91
92
93
94
95
96
97
# 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) ⇒ Object

copy the knife file over TODO: do this the ruby way



26
27
28
29
30
31
32
33
34
35
36
37
38
# 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