Module: Capsaicin::Files::Remote

Defined in:
lib/capsaicin/files/remote.rb

Instance Method Summary collapse

Instance Method Details

#cd(dir, options = {}) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/capsaicin/files/remote.rb', line 114

def cd(dir, options={})
  if block_given?
    dir, dir2 = pwd, dir
    _r 'cd', dir2
    yield
  end  
  _r 'cd', dir
end

#chmod(mode, list, options = {}) ⇒ Object



20
21
22
# File 'lib/capsaicin/files/remote.rb', line 20

def chmod(mode, list, options={})
  _r 'chmod', Array(list).unshift(mode.to_s(8))
end

#chmod_R(mode, list, options = {}) ⇒ Object



24
25
26
# File 'lib/capsaicin/files/remote.rb', line 24

def chmod_R(mode, list, options={})
  _r 'chmod -R', Array(list).unshift(mode.to_s(8))
end

#download(*args) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/capsaicin/files/remote.rb', line 82

def download(*args)
  case _via
  when :system, :local_run
    cp(*args)
  else
    @config.download(*args)
  end
end

#install(src, dest, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/capsaicin/files/remote.rb', line 28

def install(src, dest, options={})
  src = Array(src)
  case options[:mode]
  when Fixnum
    src << '-m' << options[:mode].to_s(8)
  when String
    src << '-m' << options[:mode]
  end
  _r 'install', src.push(dest)
end

#put(data, path, options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/capsaicin/files/remote.rb', line 91

def put(data, path, options={})
  case _via
  when :system, :local_run
    FileUtils::Verbose.copy_stream StringIO.new(from), to
  else
    if _via.to_s[0,4] == 'sudo'
      if path[-1]==?/ || path[-1]==?\ || directory?(path)
        pathf = File.basename from
        path2, path = "#{path}/#{pathf}", "/tmp/#{pathf}-#{Time.now.utc.to_i}"
      else
        pathf = File.basename path
        path2, path = path, "/tmp/#{pathf}-#{Time.now.utc.to_i}"
      end
    end
    @config.put(data, path, options)
    if path2
      run "chmod 0644 #{path}"
      cp path, path2
      run "rm -f #{path}"
    end
  end
end

#pwdObject



123
124
125
# File 'lib/capsaicin/files/remote.rb', line 123

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



127
128
129
130
# File 'lib/capsaicin/files/remote.rb', line 127

def tar_c(dest, src, options={}, &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



137
138
139
140
# File 'lib/capsaicin/files/remote.rb', line 137

def tar_cj(dest, src, options={}, &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



132
133
134
135
# File 'lib/capsaicin/files/remote.rb', line 132

def tar_cz(dest, src, options={}, &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



157
158
159
160
# File 'lib/capsaicin/files/remote.rb', line 157

def tar_t(src, options={}, &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



167
168
169
170
# File 'lib/capsaicin/files/remote.rb', line 167

def tar_tj(src, options={}, &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



162
163
164
165
# File 'lib/capsaicin/files/remote.rb', line 162

def tar_tz(src, options={}, &filter)
  filter and abort "tar_tz: remote mode does not support a filtering proc"
  _t 'tar -tzf', [src]
end

#tar_x(dest, options = {}, &filter) ⇒ Object



142
143
144
145
# File 'lib/capsaicin/files/remote.rb', line 142

def tar_x(dest, options={}, &filter)
  filter and abort "tar_x: remote mode does not support a filtering proc"
  _r 'tar -xf', [dest]
end

#tar_xj(dest, src, options = {}, &filter) ⇒ Object



152
153
154
155
# File 'lib/capsaicin/files/remote.rb', line 152

def tar_xj(dest, src, options={}, &filter)
  filter and abort "tar_xj: remote mode does not support a filtering proc"
  _r 'tar -xjf', Array(src).unshift(dest)
end

#tar_xz(dest, options = {}, &filter) ⇒ Object



147
148
149
150
# File 'lib/capsaicin/files/remote.rb', line 147

def tar_xz(dest, options={}, &filter)
  filter and abort "tar_xz: remote mode does not support a filtering proc"
  _r 'tar -xzf', [dest]
end

#upload(from, to, options = {}, &block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/capsaicin/files/remote.rb', line 59

def upload(from, to, options={}, &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
    @config.upload(from, to, options, &block)
    if to2
      run "chmod 0644 #{to}"
      cp to, to2
      run "rm -f #{to}"
    end
  end
end