Module: Capsaicin::Files::Remote

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

Instance Method Summary collapse

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, options={})
  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, options={})
  _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, options={})
  _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, 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



59
60
61
62
63
64
65
66
# File 'lib/capsaicin/files/remote.rb', line 59

def put(data, path, options={})
  case _via
  when :system, :local_run
    FileUtils::Verbose.copy_stream StringIO.new(from), to
  else
    upload StringIO.new(data), path, options
  end
end

#pwdObject



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, 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



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

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



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

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



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

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



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

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



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

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(src, options = {}, &filter) ⇒ Object



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

def tar_x(src, options={}, &filter)
  filter and abort "tar_x: remote mode does not support a filtering proc"
  _r "tar #{'-C '+_q(options[:chdir]) if options[: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, options={}, &filter)
  filter and abort "tar_xj: remote mode does not support a filtering proc"
  _r "tar #{'-C '+_q(options[:chdir]) if options[: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, options={}, &filter)
  filter and abort "tar_xz: remote mode does not support a filtering proc"
  _r "tar #{'-C '+_q(options[:chdir]) if options[: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, 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
   options = options.dup
   mode = options.delete(:mode)
    @config.upload(from, to, options, &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