Module: Gitchefsync::FS
- Defined in:
- lib/gitchefsync/io_util.rb
Class Method Summary collapse
-
.cmd(x, env = {}) ⇒ Object
executes a command line process raises and exception on stderr returns the sys output.
-
.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.
- .cmdNoError(x) ⇒ Object
- .flatten(path, find) ⇒ Object
- .getBasePath(path, find) ⇒ Object
-
.knifeReady(working_dir, knife_file) ⇒ Object
copy the knife file over TODO: do this the ruby way.
Class Method Details
.cmd(x, env = {}) ⇒ Object
executes a command line process raises and exception on stderr returns the sys output
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitchefsync/io_util.rb', line 27 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
45 46 47 |
# File 'lib/gitchefsync/io_util.rb', line 45 def self.cmdBerks(x) self.cmdNoError(x) end |
.cmdNoError(x) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gitchefsync/io_util.rb', line 49 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
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gitchefsync/io_util.rb', line 61 def self.flatten(path, find) arr_path = Array.new arr_path.unshift(File.basename(path, ".*")) fp = path while true do fp = File.("..", 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
74 75 76 77 78 79 80 81 |
# File 'lib/gitchefsync/io_util.rb', line 74 def self.getBasePath(path, find) fp = path while true do fp = File.("..", 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
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gitchefsync/io_util.rb', line 10 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 |