Module: Capsaicin::Files::Remote
- Defined in:
- lib/capsaicin/files/remote.rb
Instance Method Summary collapse
- #cd(dir, options = {}) ⇒ Object
- #chmod(mode, list, options = {}) ⇒ Object
- #chmod_R(mode, list, options = {}) ⇒ Object
- #download(*args) ⇒ Object
- #install(src, dest, options = {}) ⇒ Object
- #put(data, path, options = {}) ⇒ Object
- #pwd ⇒ Object
- #tail_f(file, n = 10) ⇒ Object
- #tar_c(dest, src, options = {}, &filter) ⇒ Object
- #tar_cj(dest, src, options = {}, &filter) ⇒ Object
- #tar_cz(dest, src, options = {}, &filter) ⇒ Object
- #tar_t(src, options = {}, &filter) ⇒ Object
- #tar_tj(src, options = {}, &filter) ⇒ Object
- #tar_tz(src, options = {}, &filter) ⇒ Object
- #tar_x(src, options = {}, &filter) ⇒ Object
- #tar_xj(src, options = {}, &filter) ⇒ Object
- #tar_xz(src, options = {}, &filter) ⇒ Object
- #upload(from, to, options = {}, &block) ⇒ Object
Instance Method Details
#cd(dir, options = {}) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/capsaicin/files/remote.rb', line 109 def cd(dir, ={}) if block_given? dir, dir2 = pwd, dir _r 'cd', dir2 yield end _r 'cd', dir end |
#chmod(mode, list, options = {}) ⇒ Object
28 29 30 |
# File 'lib/capsaicin/files/remote.rb', line 28 def chmod(mode, list, ={}) _r 'chmod', Array(list).unshift(mode.to_s(8)) end |
#chmod_R(mode, list, options = {}) ⇒ Object
32 33 34 |
# File 'lib/capsaicin/files/remote.rb', line 32 def chmod_R(mode, list, ={}) _r 'chmod -R', Array(list).unshift(mode.to_s(8)) end |
#download(*args) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/capsaicin/files/remote.rb', line 100 def download(*args) case _via when :system, :local_run cp(*args) else @config.download(*args) end end |
#install(src, dest, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/capsaicin/files/remote.rb', line 36 def install(src, dest, ={}) src = Array(src) case [:mode] when Fixnum src << '-m' << [:mode].to_s(8) when String src << '-m' << [:mode] end _r 'install', src.push(dest) end |
#put(data, path, options = {}) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/capsaicin/files/remote.rb', line 59 def put(data, path, ={}) case _via when :system, :local_run FileUtils::Verbose.copy_stream StringIO.new(from), to else upload StringIO.new(data), path, end end |
#pwd ⇒ Object
118 119 120 |
# File 'lib/capsaicin/files/remote.rb', line 118 def pwd capture 'pwd', :via => _via end |
#tail_f(file, n = 10) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/capsaicin/files/remote.rb', line 47 def tail_f(file, n=10) cmd = "tail -n #{n} -f #{_q file}" case v = _via when :system, :local_run send v, cmd else stream cmd, :via => v end rescue Interrupt logger.trace "interrupted (Ctrl-C)" if logger end |
#tar_c(dest, src, options = {}, &filter) ⇒ Object
122 123 124 125 |
# File 'lib/capsaicin/files/remote.rb', line 122 def tar_c(dest, src, ={}, &filter) filter and abort "tar_c: remote mode does not support a filtering proc" _r 'tar -cf', Array(src).unshift(dest) end |
#tar_cj(dest, src, options = {}, &filter) ⇒ Object
132 133 134 135 |
# File 'lib/capsaicin/files/remote.rb', line 132 def tar_cj(dest, src, ={}, &filter) filter and abort "tar_cj: remote mode does not support a filtering proc" _r 'tar -cjf', Array(src).unshift(dest) end |
#tar_cz(dest, src, options = {}, &filter) ⇒ Object
127 128 129 130 |
# File 'lib/capsaicin/files/remote.rb', line 127 def tar_cz(dest, src, ={}, &filter) filter and abort "tar_cz: remote mode does not support a filtering proc" _r 'tar -czf', Array(src).unshift(dest) end |
#tar_t(src, options = {}, &filter) ⇒ Object
152 153 154 155 |
# File 'lib/capsaicin/files/remote.rb', line 152 def tar_t(src, ={}, &filter) filter and abort "tar_t: remote mode does not support a filtering proc" _t 'tar -tf', [src] end |
#tar_tj(src, options = {}, &filter) ⇒ Object
162 163 164 165 |
# File 'lib/capsaicin/files/remote.rb', line 162 def tar_tj(src, ={}, &filter) filter and abort "tar_tj: remote mode does not support a filtering proc" _t 'tar -tjf', [src] end |
#tar_tz(src, options = {}, &filter) ⇒ Object
157 158 159 160 |
# File 'lib/capsaicin/files/remote.rb', line 157 def tar_tz(src, ={}, &filter) filter and abort "tar_tz: remote mode does not support a filtering proc" _t 'tar -tzf', [src] end |
#tar_x(src, options = {}, &filter) ⇒ Object
137 138 139 140 |
# File 'lib/capsaicin/files/remote.rb', line 137 def tar_x(src, ={}, &filter) filter and abort "tar_x: remote mode does not support a filtering proc" _r "tar #{'-C '+_q([:chdir]) if [:chdir]} -xf", [src] end |
#tar_xj(src, options = {}, &filter) ⇒ Object
147 148 149 150 |
# File 'lib/capsaicin/files/remote.rb', line 147 def tar_xj(src, ={}, &filter) filter and abort "tar_xj: remote mode does not support a filtering proc" _r "tar #{'-C '+_q([:chdir]) if [:chdir]} -xjf", [src] end |
#tar_xz(src, options = {}, &filter) ⇒ Object
142 143 144 145 |
# File 'lib/capsaicin/files/remote.rb', line 142 def tar_xz(src, ={}, &filter) filter and abort "tar_xz: remote mode does not support a filtering proc" _r "tar #{'-C '+_q([:chdir]) if [:chdir]} -xzf", [src] end |
#upload(from, to, options = {}, &block) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/capsaicin/files/remote.rb', line 68 def upload(from, to, ={}, &block) case _via when :system, :local_run cp from, to else if _via.to_s[0,4] == 'sudo' if to[-1]==?/ || to[-1]==?\\ || directory?(to) tof = File.basename from to2, to = "#{to}/#{tof}", "/tmp/#{tof}-#{Time.now.utc.to_i}" else tof = File.basename to to2, to = to, "/tmp/#{tof}-#{Time.now.utc.to_i}" end end = .dup mode = .delete(:mode) @config.upload(from, to, , &block) if to2 begin run "chmod 0644 #{to}", :via=>:run cp to, to2 if mode mode = mode.is_a?(Numeric) ? '0'+mode.to_s(8) : mode.to_s run "chmod #{mode} #{to2}" end ensure run "rm -f #{to}", :via=>:run end end end end |